diff --git a/Dockerfile b/Dockerfile index 441f2be..841b3a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,6 +40,12 @@ RUN --mount=type=bind,source=package.json,target=package.json \ # Copy the rest of the source files into the image. COPY . . + +ARG VUE_APP_SOLO_URL +ENV VUE_APP_SOLO_URL=$VUE_APP_SOLO_URL + +ENV NODE_ENV=production + # Run the build script. RUN yarn run build @@ -50,4 +56,6 @@ FROM nginx:stable-alpine AS final COPY --from=build /usr/src/app/dist /usr/share/nginx/html # COPY --from=build /usr/src/app/nginx.prod.conf /etc/nginx/conf.d/default.conf EXPOSE 80 + CMD ["nginx", "-g", "daemon off;"] + diff --git a/compose.yaml b/compose.yaml index 64aead1..b1a3e66 100644 --- a/compose.yaml +++ b/compose.yaml @@ -11,40 +11,9 @@ services: server: build: context: . + args: + - VUE_APP_SOLO_URL=http://localhost:8669 environment: NODE_ENV: production ports: - 8080:80 -# The commented out section below is an example of how to define a PostgreSQL -# database that your application can use. `depends_on` tells Docker Compose to -# start the database before your application. The `db-data` volume persists the -# database data between container restarts. The `db-password` secret is used -# to set the database password. You must create `db/password.txt` and add -# a password of your choosing to it before running `docker-compose up`. -# depends_on: -# db: -# condition: service_healthy -# db: -# image: postgres -# restart: always -# user: postgres -# secrets: -# - db-password -# volumes: -# - db-data:/var/lib/postgresql/data -# environment: -# - POSTGRES_DB=example -# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password -# expose: -# - 5432 -# healthcheck: -# test: [ "CMD", "pg_isready" ] -# interval: 10s -# timeout: 5s -# retries: 5 -# volumes: -# db-data: -# secrets: -# db-password: -# file: db/password.txt - diff --git a/src/App.vue b/src/App.vue index 540ccaf..6bbd406 100644 --- a/src/App.vue +++ b/src/App.vue @@ -62,18 +62,19 @@ export default Vue.extend({ } }, created() { - let net = this.$route.params.net as "main" | "test" | undefined - if (!["main", "test"].includes(net!)) { + let net = this.$route.params.net as "main" | "test" | "solo" | undefined + if (!["main", "test", "solo"].includes(net!)) { net = undefined } const connex = createConnex(net) Vue.prototype.$connex = connex Vue.prototype.$net = genesisIdToNetwork(connex.thor.genesis.id) - if (!["main", "test"].includes(Vue.prototype.$net)) { + if (!["main", "test", "solo"].includes(Vue.prototype.$net)) { Vue.prototype.$net = undefined } + this.routed() this.$state.chainStatus = this.$connex.thor.status diff --git a/src/create-connex.ts b/src/create-connex.ts index c779d26..c14ecd1 100644 --- a/src/create-connex.ts +++ b/src/create-connex.ts @@ -1,22 +1,57 @@ -import Connex from '@vechain/connex/esm' +import Connex from "@vechain/connex/esm"; -const nodeUrls = { - main: 'https://explore-mainnet.veblocks.net', - test: 'https://explore-testnet.veblocks.net' -} +export const soloUrlNode = process.env.VUE_APP_SOLO_URL; + +//Needed to support runtime env variables +export const isSoloNode = !!soloUrlNode; +export const nodeUrls = { + main: "https://explore-mainnet.veblocks.net", + test: "https://explore-testnet.veblocks.net", + solo: soloUrlNode ?? "http://localhost:8669", + custom: "", +}; -export function createConnex(net?: 'main' | 'test') { - if (net) { // net specified - const url = nodeUrls[net] - return new Connex({ node: url, network: net }) +const soloGenesis = { + number: 0, + id: "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6", + size: 170, + parentID: + "0xffffffff53616c757465202620526573706563742c20457468657265756d2100", + timestamp: 1530316800, + gasLimit: 10000000, + beneficiary: "0x0000000000000000000000000000000000000000", + gasUsed: 0, + totalScore: 0, + txsRoot: "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + txsFeatures: 0, + stateRoot: + "0x93de0ffb1f33bc0af053abc2a87c4af44594f5dcb1cb879dd823686a15d68550", + receiptsRoot: + "0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0", + signer: "0x0000000000000000000000000000000000000000", + isTrunk: true, + transactions: [], +}; + +export function createConnex(net?: "main" | "test" | "solo") { + if (net) { + // net specified + const url = nodeUrls[net]; + if (net == "solo") { + return new Connex({ node: url, network: soloGenesis }); + } + return new Connex({ node: url, network: net }); + } else { + const injected = (window as any).connex; + // net unspecified + if (injected) { + return new Connex({ node: "", network: injected.thor.genesis }); } else { - const injected = (window as any).connex - // net unspecified - if (injected) { - return new Connex({ node: '', network: injected.thor.genesis }) - } else { - // defaults to main net - return new Connex({ node: nodeUrls.main }) - } + // defaults to main net, or soloUrl if solo is provided + if (isSoloNode) { + return new Connex({ node: nodeUrls.solo, network: soloGenesis }); + } + return new Connex({ node: nodeUrls.main }); } + } } diff --git a/src/router.ts b/src/router.ts index 992f402..ec5f603 100644 --- a/src/router.ts +++ b/src/router.ts @@ -17,7 +17,7 @@ export default new Router({ mode: 'hash', routes: [ { - path: '/:net(main|test)?', + path: '/:net(main|test|solo)?', children: [ { path: '', diff --git a/src/utils.ts b/src/utils.ts index 163bdac..5fbf27d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,8 +1,25 @@ export function genesisIdToNetwork(id: string) { - switch (id) { - case '0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a': return 'main' - case '0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127': return 'test' - case '0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6': return 'solo' - default: return 'custom' - } + switch (id) { + case "0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a": + return "main"; + case "0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127": + return "test"; + case "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6": + return "solo"; + default: + return "custom"; + } +} + +export function networkToGenesisId(net: string) { + switch (net) { + case "main": + return "0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a"; + case "test": + return "0x000000000b2bce3c70bc649a02749e8687721b09ed2e15997f466536b20bb127"; + case "solo": + return "0x00000000c05a20fbca2bf6ae3affba6af4a74b800b585bf7a4988aba7aea69f6"; + default: + return ""; + } } diff --git a/src/views/Frame.vue b/src/views/Frame.vue index 8e97d10..50dbce2 100644 --- a/src/views/Frame.vue +++ b/src/views/Frame.vue @@ -7,27 +7,39 @@ >