Merge pull request #15 from poanetwork/classic

Add Ethereum classic properties
This commit is contained in:
Victor Baranov 2019-03-26 16:46:25 +03:00 committed by GitHub
commit b00ad23429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 12 deletions

View File

@ -1,5 +1,6 @@
const networkIDs = {
MAINNET_CODE: 1,
CLASSIC_CODE: '1\'',
ROPSTEN_CODE: 3,
RINKEBY_CODE: 4,
GOERLI_CODE: 5,

View File

@ -1,4 +1,5 @@
const { networkIDs } = require('./enum')
const { isClassic } = require('./helper')
const {
MAINNET_CODE,
ROPSTEN_CODE,
@ -9,6 +10,7 @@ const {
POA_CORE_CODE,
XDAI_CODE,
RSK_CODE,
CLASSIC_CODE,
} = networkIDs
const POA_IDs = [SOKOL_CODE, POA_CORE_CODE, XDAI_CODE]
@ -23,6 +25,8 @@ const getExplorerAccountLinkFor = (account, network) => {
const prefix = getExplorerPrefix(network)
if (POA_IDs.includes(parseInt(network))) {
return `${blockScoutLink('poa', prefix)}/address/${account}`
} else if (network === CLASSIC_CODE) {
return `${blockScoutLink('etc', prefix)}/address/${account}`
} else if (ETH_IDs.includes(parseInt(network))) {
return `${blockScoutLink('eth', prefix)}/address/${account}`
} else if (RSK_IDs.includes(parseInt(network))) {
@ -36,6 +40,8 @@ const getExplorerTxLinkFor = (hash, network) => {
const prefix = getExplorerPrefix(network)
if (POA_IDs.includes(parseInt(network))) {
return `${blockScoutLink('poa', prefix)}/tx/${hash}`
} else if (network === CLASSIC_CODE) {
return `${blockScoutLink('etc', prefix)}/tx/${hash}`
} else if (ETH_IDs.includes(parseInt(network))) {
return `${blockScoutLink('eth', prefix)}/tx/${hash}`
} else if (RSK_IDs.includes(parseInt(network))) {
@ -48,9 +54,11 @@ const getExplorerTxLinkFor = (hash, network) => {
const getExplorerTokenLinkFor = (tokenAddress, account, network) => {
const prefix = getExplorerPrefix(network)
if (POA_IDs.includes(parseInt(network))) {
return `${blockScoutLink('poa', prefix)}/address/${tokenAddress}`
return `${blockScoutLink('poa', prefix)}/tokens/${tokenAddress}`
} else if (network === CLASSIC_CODE) {
return `${blockScoutLink('etc', prefix)}/tokens/${tokenAddress}`
} else if (ETH_IDs.includes(parseInt(network))) {
return `${blockScoutLink('eth', prefix)}/address/${tokenAddress}`
return `${blockScoutLink('eth', prefix)}/tokens/${tokenAddress}`
} else if (RSK_IDs.includes(parseInt(network))) {
return `${rskExplorerLink}/token/${tokenAddress}/account/${account}`
} else {
@ -59,7 +67,7 @@ const getExplorerTokenLinkFor = (tokenAddress, account, network) => {
}
function getExplorerPrefix (network) {
const net = parseInt(network)
const net = isClassic ? network : parseInt(network)
let prefix
switch (net) {
case MAINNET_CODE: // main net
@ -86,6 +94,9 @@ function getExplorerPrefix (network) {
case GOERLI_CODE: // Goerli testnet
prefix = 'goerli'
break
case CLASSIC_CODE: // Goerli testnet
prefix = 'mainnet'
break
default:
prefix = ''
}

View File

@ -1,4 +1,5 @@
const { networkIDs } = require('./enum')
const { isClassic } = require('./helper')
const {
MAINNET_CODE,
ROPSTEN_CODE,
@ -10,10 +11,11 @@ const {
XDAI_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
CLASSIC_CODE,
} = networkIDs
function getNetworkDisplayName(network) {
const netID = parseInt(network)
const netID = isClassic ? network : parseInt(network)
switch (netID) {
case MAINNET_CODE:
return 'Main Ethereum Network'
@ -35,13 +37,15 @@ function getNetworkDisplayName(network) {
return 'RSK Mainnet'
case RSK_TESTNET_CODE:
return 'RSK Testnet'
case CLASSIC_CODE:
return 'Ethereum Classic'
default:
return 'Unknown Private Network'
}
}
function getNetworkCoinName(network) {
const netID = parseInt(network)
const netID = isClassic ? network : parseInt(network)
switch (netID) {
case SOKOL_CODE:
case POA_CORE_CODE:
@ -53,6 +57,8 @@ function getNetworkCoinName(network) {
return 'xDAI'
case GOERLI_CODE:
return 'GöETH'
case CLASSIC_CODE:
return 'ETC'
default:
return 'ETH'
}
@ -65,6 +71,7 @@ function isTestnet(network) {
case POA_CORE_CODE:
case XDAI_CODE:
case RSK_CODE:
case CLASSIC_CODE:
return false
default:
return true

View File

@ -1,4 +1,5 @@
const { networkIDs } = require('./enum')
const { isClassic } = require('./helper')
const {
MAINNET_CODE,
ROPSTEN_CODE,
@ -10,10 +11,11 @@ const {
XDAI_CODE,
RSK_CODE,
RSK_TESTNET_CODE,
CLASSIC_CODE,
} = networkIDs
function getRPCEndpoints(network) {
const netID = parseInt(network)
const netID = isClassic ? network : parseInt(network)
switch (netID) {
case MAINNET_CODE:
return ['https://mainnet.infura.io/']
@ -35,6 +37,8 @@ function getRPCEndpoints(network) {
return ['https://public-node.rsk.co']
case RSK_TESTNET_CODE:
return ['https://public-node.testnet.rsk.co']
case CLASSIC_CODE:
return ['https://ethereumclassic.network/']
default:
return []
}

7
helpers/helper.js Normal file
View File

@ -0,0 +1,7 @@
const isClassic = (networkID) => {
return networkID === '1\'' ? true : false
}
module.exports = {
isClassic
}

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "eth-net-props",
"version": "1.0.14",
"version": "1.0.15",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "eth-net-props",
"version": "1.0.14",
"version": "1.0.15",
"description": "Get properties of EMV-based network",
"main": "index.js",
"directories": {

View File

@ -38,6 +38,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Goerli Testnet`, () => {
assert.equal(explorerLinks.getExplorerAccountLinkFor('0xd8fe15886d2dcbc5d7c06394beb417aadaf1eee0', 5), 'https://blockscout.com/eth/goerli/address/0xd8fe15886d2dcbc5d7c06394beb417aadaf1eee0')
})
it(`${claimPrefix} Ethereum Classic`, () => {
assert.equal(explorerLinks.getExplorerAccountLinkFor('0xd8fe15886d2dcbc5d7c06394beb417aadaf1eee0', '1\''), 'https://blockscout.com/etc/mainnet/address/0xd8fe15886d2dcbc5d7c06394beb417aadaf1eee0')
})
})
describe ('getExplorerTxLinkFor()', () => {
@ -68,17 +71,20 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Goerli Testnet`, () => {
assert.equal(explorerLinks.getExplorerTxLinkFor('0xb9599801c83e6aa20769e7dcdce0989c7380ba78cb587d3d7db11e1b30b17b54', 5), 'https://blockscout.com/eth/goerli/tx/0xb9599801c83e6aa20769e7dcdce0989c7380ba78cb587d3d7db11e1b30b17b54')
})
it(`${claimPrefix} Ethereum Classic`, () => {
assert.equal(explorerLinks.getExplorerTxLinkFor('0x430c90335b32fdcd92e54991668023d58b72bce836e204a81c6d97506c7137e5', '1\''), 'https://blockscout.com/etc/mainnet/tx/0x430c90335b32fdcd92e54991668023d58b72bce836e204a81c6d97506c7137e5')
})
})
describe ('getExplorerTokenLinkFor()', () => {
it(`${claimPrefix} Sokol POA Network`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 77), 'https://blockscout.com/poa/sokol/address/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE')
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 77), 'https://blockscout.com/poa/sokol/tokens/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE')
})
it(`${claimPrefix} Core POA Network`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 99), 'https://blockscout.com/poa/core/address/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE')
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 99), 'https://blockscout.com/poa/core/tokens/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE')
})
it(`${claimPrefix} Dai Chain`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 100), 'https://blockscout.com/poa/dai/address/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE')
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xabe71e6a260c2eea3c30864dc50639100aa315f6', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 100), 'https://blockscout.com/poa/dai/tokens/0xabe71e6a260c2eea3c30864dc50639100aa315f6')
})
it(`${claimPrefix} Mainnet`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE', '0x70FDd102DDB03Dc55B1719E76DfeA784916621fd', 1), 'https://etherscan.io/token/0xcf2AEDCfb4ff2c9020fb61c41226A4DfD77D12dE?a=0x70FDd102DDB03Dc55B1719E76DfeA784916621fd')
@ -96,7 +102,10 @@ describe('eth-net-props', () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0x16cb2604ce5951c8506fbf690d816be6d0aa00fb', '0x604056c0f88aed17ef975269aab1ae9d02840bb2', 30), 'https://explorer.rsk.co/token/0x16cb2604ce5951c8506fbf690d816be6d0aa00fb/account/0x604056c0f88aed17ef975269aab1ae9d02840bb2')
})
it(`${claimPrefix} Goerli testnet`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0xd8fe15886d2dcbc5d7c06394beb417aadaf1eee0', '0x604056c0f88aed17ef975269aab1ae9d02840bb2', 5), 'https://blockscout.com/eth/goerli/address/0xd8fe15886d2dcbc5d7c06394beb417aadaf1eee0')
assert.equal(explorerLinks.getExplorerTokenLinkFor('0x7af963cf6d228e564e2a0aa0ddbf06210b38615d', '0x604056c0f88aed17ef975269aab1ae9d02840bb2', 5), 'https://blockscout.com/eth/goerli/tokens/0x7af963cf6d228e564e2a0aa0ddbf06210b38615d')
})
it(`${claimPrefix} Ethereum Classic`, () => {
assert.equal(explorerLinks.getExplorerTokenLinkFor('0x1ac1c8b874c7b889113a036ba443b082554be5d0', '0x604056c0f88aed17ef975269aab1ae9d02840bb2', '1\''), 'https://blockscout.com/etc/mainnet/tokens/0x1ac1c8b874c7b889113a036ba443b082554be5d0')
})
})
})
@ -226,6 +235,13 @@ describe('eth-net-props', () => {
assert.equal(GoerliRPCEndpoints[0], 'https://goerli.blockscout.com/')
}
})
it(`${claimPrefix} Ethereum Classic`, () => {
const ETCRPCEndpoints = RPCEndpoints.getRPCEndpoints('1\'')
assert.equal(ETCRPCEndpoints.length, 1)
if (ETCRPCEndpoints.length > 0) {
assert.equal(ETCRPCEndpoints[0], 'https://ethereumclassic.network/')
}
})
})
claimPrefix = 'should return correct display name for'
@ -260,6 +276,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Goerli Testnet`, () => {
assert.equal(netProps.getNetworkDisplayName(5), 'Görli Test Network')
})
it(`${claimPrefix} Ethereum Classic`, () => {
assert.equal(netProps.getNetworkDisplayName('1\''), 'Ethereum Classic')
})
claimPrefix = 'should return correct coin name for'
it(`${claimPrefix} Sokol POA Network`, () => {
@ -292,6 +311,9 @@ describe('eth-net-props', () => {
it(`${claimPrefix} Goerli Testnet`, () => {
assert.equal(netProps.getNetworkCoinName(5), 'GöETH')
})
it(`${claimPrefix} Ethereum Classic`, () => {
assert.equal(netProps.getNetworkCoinName('1\''), 'ETC')
})
it('Sokol POA Network is a testnet', () => {
assert.equal(netProps.isTestnet(77), true)
@ -323,5 +345,8 @@ describe('eth-net-props', () => {
it('Goerli Testnet is a testnet', () => {
assert.equal(netProps.isTestnet(5), true)
})
it('Ethereum Classic is not a testnet', () => {
assert.equal(netProps.isTestnet('1\''), false)
})
})
})