Skip to content

Commit

Permalink
Merge 47a446e into 5deaffa
Browse files Browse the repository at this point in the history
  • Loading branch information
vbaranov committed Feb 6, 2019
2 parents 5deaffa + 47a446e commit 646952d
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 58 deletions.
16 changes: 16 additions & 0 deletions helpers/enum.js
@@ -0,0 +1,16 @@
const networkIDs = {
MAINNET_CODE: 1,
ROPSTEN_CODE: 3,
RINKEBY_CODE: 4,
GOERLI_CODE: 5,
KOVAN_CODE: 42,
SOKOL_CODE: 77,
POA_CORE_CODE: 99,
XDAI_CODE: 100,
RSK_CODE: 30,
RSK_TESTNET_CODE: 31,
}

module.exports = {
networkIDs
}
75 changes: 51 additions & 24 deletions helpers/get-explorer-links.js
@@ -1,64 +1,91 @@
const POAIDs = [77, 99, 100]
const RSKIDs = [30]
const { networkIDs } = require('./enum')
const {
MAINNET_CODE,
ROPSTEN_CODE,
RINKEBY_CODE,
GOERLI_CODE,
KOVAN_CODE,
SOKOL_CODE,
POA_CORE_CODE,
XDAI_CODE,
RSK_CODE,
} = networkIDs

const POA_IDs = [SOKOL_CODE, POA_CORE_CODE, XDAI_CODE]
const RSK_IDs = [RSK_CODE]
const ETH_IDs = [GOERLI_CODE]

const blockScoutLink = (net, prefix) => `https://blockscout.com/${net}/${prefix}`
const etherscanLink = (prefix) => `https://${prefix}etherscan.io`
const rskExplorerLink = 'https://explorer.rsk.co'

const getExplorerAccountLinkFor = (account, network) => {
const prefix = getExplorerPrefix(network)
if (POAIDs.includes(parseInt(network))) {
return `https://blockscout.com/poa/${prefix}/address/${account}`
} else if (RSKIDs.includes(parseInt(network))) {
return `https://explorer.rsk.co/address/${account}`
if (POA_IDs.includes(parseInt(network))) {
return `${blockScoutLink('poa', prefix)}/address/${account}`
} else if (ETH_IDs.includes(parseInt(network))) {
return `${blockScoutLink('eth', prefix)}/address/${account}`
} else if (RSK_IDs.includes(parseInt(network))) {
return `${rskExplorerLink}/address/${account}`
} else {
return `https://${prefix}etherscan.io/address/${account}`
return `${etherscanLink(prefix)}/address/${account}`
}
}

const getExplorerTxLinkFor = (hash, network) => {
const prefix = getExplorerPrefix(network)
if (POAIDs.includes(parseInt(network))) {
return `https://blockscout.com/poa/${prefix}/tx/${hash}`
} else if (RSKIDs.includes(parseInt(network))) {
return `https://explorer.rsk.co/tx/${hash}`
if (POA_IDs.includes(parseInt(network))) {
return `${blockScoutLink('poa', prefix)}/tx/${hash}`
} else if (ETH_IDs.includes(parseInt(network))) {
return `${blockScoutLink('eth', prefix)}/tx/${hash}`
} else if (RSK_IDs.includes(parseInt(network))) {
return `${rskExplorerLink}/tx/${hash}`
} else {
return `https://${prefix}etherscan.io/tx/${hash}`
return `${etherscanLink(prefix)}/tx/${hash}`
}
}

const getExplorerTokenLinkFor = (tokenAddress, account, network) => {
const prefix = getExplorerPrefix(network)
if (POAIDs.includes(parseInt(network))) {
return `https://blockscout.com/poa/${prefix}/address/${tokenAddress}`
} else if (RSKIDs.includes(parseInt(network))) {
return `https://explorer.rsk.co/token/${tokenAddress}/account/${account}`
if (POA_IDs.includes(parseInt(network))) {
return `${blockScoutLink('poa', prefix)}/address/${tokenAddress}`
} else if (ETH_IDs.includes(parseInt(network))) {
return `${blockScoutLink('eth', prefix)}/address/${tokenAddress}`
} else if (RSK_IDs.includes(parseInt(network))) {
return `${rskExplorerLink}/token/${tokenAddress}/account/${account}`
} else {
return `https://${prefix}etherscan.io/token/${tokenAddress}?a=${account}`
return `${etherscanLink(prefix)}/token/${tokenAddress}?a=${account}`
}
}

function getExplorerPrefix (network) {
const net = parseInt(network)
let prefix
switch (net) {
case 1: // main net
case MAINNET_CODE: // main net
prefix = ''
break
case 3: // ropsten test net
case ROPSTEN_CODE: // ropsten test net
prefix = 'ropsten.'
break
case 4: // rinkeby test net
case RINKEBY_CODE: // rinkeby test net
prefix = 'rinkeby.'
break
case 42: // kovan test net
case KOVAN_CODE: // kovan test net
prefix = 'kovan.'
break
case 77: // POA Sokol test net
case SOKOL_CODE: // POA Sokol test net
prefix = 'sokol'
break
case 99: // POA Core net
case POA_CORE_CODE: // POA Core net
prefix = 'core'
break
case 100: // Dai chain
case XDAI_CODE: // Dai chain
prefix = 'dai'
break
case GOERLI_CODE: // Goerli testnet
prefix = 'goerli'
break
default:
prefix = ''
}
Expand Down
22 changes: 17 additions & 5 deletions helpers/get-faucet-links.js
@@ -1,15 +1,27 @@
const { networkIDs } = require('./enum')
const {
ROPSTEN_CODE,
RINKEBY_CODE,
GOERLI_CODE,
KOVAN_CODE,
SOKOL_CODE,
RSK_TESTNET_CODE,
} = networkIDs

function getFaucetLinks(network) {
const netID = parseInt(network)
switch (netID) {
case 3:
case ROPSTEN_CODE:
return ['https://faucet.metamask.io/']
case 4:
case RINKEBY_CODE:
return ['https://faucet.rinkeby.io/']
case 42:
case GOERLI_CODE:
return ['https://goerli-faucet.slock.it/']
case KOVAN_CODE:
return ['https://faucet.kovan.network/', 'https://gitter.im/kovan-testnet/faucet/']
case 77:
case SOKOL_CODE:
return ['https://faucet.poa.network/']
case 31:
case RSK_TESTNET_CODE:
return ['https://faucet.testnet.rsk.co/']
default:
return []
Expand Down
54 changes: 36 additions & 18 deletions helpers/get-net-properties.js
@@ -1,23 +1,39 @@
const { networkIDs } = require('./enum')
const {
MAINNET_CODE,
ROPSTEN_CODE,
RINKEBY_CODE,
GOERLI_CODE,
KOVAN_CODE,
SOKOL_CODE,
POA_CORE_CODE,
XDAI_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
} = networkIDs

function getNetworkDisplayName(network) {
const netID = parseInt(network)
switch (netID) {
case 1:
case MAINNET_CODE:
return 'Main Ethereum Network'
case 3:
case ROPSTEN_CODE:
return 'Ropsten Test Network'
case 4:
case RINKEBY_CODE:
return 'Rinkeby Test Network'
case 42:
case GOERLI_CODE:
return 'Goerli Test Network'
case KOVAN_CODE:
return 'Kovan Test Network'
case 77:
case SOKOL_CODE:
return 'POA Sokol Test Network'
case 99:
case POA_CORE_CODE:
return 'POA Network'
case 100:
case XDAI_CODE:
return 'xDai Chain'
case 30:
case RSK_CODE:
return 'RSK Mainnet'
case 31:
case RSK_TESTNET_CODE:
return 'RSK Testnet'
default:
return 'Unknown Private Network'
Expand All @@ -27,14 +43,16 @@ function getNetworkDisplayName(network) {
function getNetworkCoinName(network) {
const netID = parseInt(network)
switch (netID) {
case 77:
case 99:
case SOKOL_CODE:
case POA_CORE_CODE:
return 'POA'
case 30:
case 31:
case RSK_CODE:
case RSK_TESTNET_CODE:
return 'RBTC'
case 100:
case XDAI_CODE:
return 'xDAI'
case GOERLI_CODE:
return 'GöETH'
default:
return 'ETH'
}
Expand All @@ -43,10 +61,10 @@ function getNetworkCoinName(network) {
function isTestnet(network) {
const netID = parseInt(network)
switch (netID) {
case 1:
case 99:
case 100:
case 30:
case MAINNET_CODE:
case POA_CORE_CODE:
case XDAI_CODE:
case RSK_CODE:
return false
default:
return true
Expand Down
34 changes: 25 additions & 9 deletions helpers/get-rpc-endpoints.js
@@ -1,23 +1,39 @@
const { networkIDs } = require('./enum')
const {
MAINNET_CODE,
ROPSTEN_CODE,
RINKEBY_CODE,
GOERLI_CODE,
KOVAN_CODE,
SOKOL_CODE,
POA_CORE_CODE,
XDAI_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
} = networkIDs

function getRPCEndpoints(network) {
const netID = parseInt(network)
switch (netID) {
case 1:
case MAINNET_CODE:
return ['https://mainnet.infura.io/']
case 3:
case ROPSTEN_CODE:
return ['https://ropsten.infura.io/']
case 4:
case RINKEBY_CODE:
return ['https://rinkeby.infura.io/']
case 42:
case GOERLI_CODE:
return ['https://goerli.blockscout.com/']
case KOVAN_CODE:
return ['https://kovan.infura.io/']
case 77:
case SOKOL_CODE:
return ['https://sokol.poa.network/']
case 99:
case POA_CORE_CODE:
return ['https://core.poa.network/']
case 100:
case XDAI_CODE:
return ['https://dai.poa.network/']
case 30:
case RSK_CODE:
return ['https://public-node.rsk.co']
case 31:
case RSK_TESTNET_CODE:
return ['https://public-node.testnet.rsk.co']
default:
return []
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eth-net-props",
"version": "1.0.11",
"version": "1.0.12",
"description": "Get properties of EMV-based network",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 646952d

Please sign in to comment.