-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from vechain/feat-support-solo
feat: add support for solo network
- Loading branch information
Showing
7 changed files
with
129 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters