mirror of
https://github.com/wharfkit/common.git
synced 2026-07-21 17:43:31 +00:00
Reworked exported Chains
This commit is contained in:
+98
-13
@@ -39,8 +39,11 @@ export class ChainDefinition extends Struct {
|
||||
}
|
||||
|
||||
get name() {
|
||||
const id = String(this.id)
|
||||
return chainNames.has(id) ? chainNames.get(id) : 'Unknown blockchain'
|
||||
const indice = chainIdsToIndices.get(String(this.id))
|
||||
if (!indice) {
|
||||
return 'Unknown blockchain'
|
||||
}
|
||||
return ChainNames[indice]
|
||||
}
|
||||
|
||||
public getLogo(): Logo | undefined {
|
||||
@@ -58,10 +61,49 @@ export class ChainDefinition extends Struct {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of string-based chain names to assist autocompletion
|
||||
*/
|
||||
export type ChainIndices =
|
||||
| 'EOS'
|
||||
| 'FIO'
|
||||
| 'FIOTestnet'
|
||||
| 'Jungle4'
|
||||
| 'KylinTestnet'
|
||||
| 'Libre'
|
||||
| 'LibreTestnet'
|
||||
| 'Proton'
|
||||
| 'ProtonTestnet'
|
||||
| 'Telos'
|
||||
| 'TelosTestnet'
|
||||
| 'WAX'
|
||||
| 'WAXTestnet'
|
||||
| 'UX'
|
||||
|
||||
/**
|
||||
* List of human readable chain names based on the ChainIndices type.
|
||||
*/
|
||||
export const ChainNames: Record<ChainIndices, string> = {
|
||||
EOS: 'EOS',
|
||||
FIO: 'FIO',
|
||||
FIOTestnet: 'FIO (Testnet)',
|
||||
Jungle4: 'Jungle 4 (Testnet)',
|
||||
KylinTestnet: 'Kylin (Testnet)',
|
||||
Libre: 'Libre',
|
||||
LibreTestnet: 'Libre (Testnet)',
|
||||
Proton: 'Proton',
|
||||
ProtonTestnet: 'Proton (Testnet)',
|
||||
Telos: 'Telos',
|
||||
TelosTestnet: 'Telos (Testnet)',
|
||||
WAX: 'WAX',
|
||||
WAXTestnet: 'WAX (Testnet)',
|
||||
UX: 'UX Network',
|
||||
}
|
||||
|
||||
/**
|
||||
* An exported list of ChainDefinition entries for select chains.
|
||||
*/
|
||||
export const Chains: Record<string, ChainDefinition> = {
|
||||
export const Chains: Record<ChainIndices, ChainDefinition> = {
|
||||
EOS: ChainDefinition.from({
|
||||
id: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
|
||||
url: 'https://eos.greymass.com',
|
||||
@@ -70,10 +112,54 @@ export const Chains: Record<string, ChainDefinition> = {
|
||||
suffix: '',
|
||||
},
|
||||
}),
|
||||
FIO: ChainDefinition.from({
|
||||
id: '21dcae42c0182200e93f954a074011f9048a7624c6fe81d3c9541a614a88bd1c',
|
||||
url: 'https://fio.greymass.com',
|
||||
explorer: {
|
||||
prefix: 'https://fio.bloks.io/transaction/',
|
||||
suffix: '',
|
||||
},
|
||||
}),
|
||||
FIOTestnet: ChainDefinition.from({
|
||||
id: 'b20901380af44ef59c5918439a1f9a41d83669020319a80574b804a5f95cbd7e',
|
||||
url: 'https://fiotestnet.greymass.com',
|
||||
explorer: {
|
||||
prefix: 'https://fio-test.bloks.io/transaction/',
|
||||
suffix: '',
|
||||
},
|
||||
}),
|
||||
Jungle4: ChainDefinition.from({
|
||||
id: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d',
|
||||
url: 'https://jungle4.greymass.com',
|
||||
}),
|
||||
KylinTestnet: ChainDefinition.from({
|
||||
id: '5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191',
|
||||
url: 'https://api.kylin.alohaeos.com',
|
||||
}),
|
||||
Libre: ChainDefinition.from({
|
||||
id: '38b1d7815474d0c60683ecbea321d723e83f5da6ae5f1c1f9fecc69d9ba96465',
|
||||
url: 'https://libre.greymass.com',
|
||||
explorer: {
|
||||
prefix: 'https://www.libreblocks.io/tx/',
|
||||
suffix: '',
|
||||
},
|
||||
}),
|
||||
LibreTestnet: ChainDefinition.from({
|
||||
id: 'b64646740308df2ee06c6b72f34c0f7fa066d940e831f752db2006fcc2b78dee',
|
||||
url: 'https://libretestnet.greymass.com',
|
||||
}),
|
||||
Proton: ChainDefinition.from({
|
||||
id: '384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0',
|
||||
url: 'https://proton.greymass.com',
|
||||
explorer: {
|
||||
prefix: 'https://www.protonscan.io/transaction/',
|
||||
suffix: '',
|
||||
},
|
||||
}),
|
||||
ProtonTestnet: ChainDefinition.from({
|
||||
id: '71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd',
|
||||
url: 'https://proton-testnet.greymass.com',
|
||||
}),
|
||||
Telos: ChainDefinition.from({
|
||||
id: '4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11',
|
||||
url: 'https://telos.greymass.com',
|
||||
@@ -109,24 +195,23 @@ export const Chains: Record<string, ChainDefinition> = {
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of chain IDs and their formatted names for display purposes.
|
||||
* A list of chain IDs and their ChainIndices for reference lookups
|
||||
*/
|
||||
export const chainNames: Map<Checksum256Type, string> = new Map([
|
||||
export const chainIdsToIndices: Map<Checksum256Type, ChainIndices> = new Map([
|
||||
['aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', 'EOS'],
|
||||
['21dcae42c0182200e93f954a074011f9048a7624c6fe81d3c9541a614a88bd1c', 'FIO'],
|
||||
['b20901380af44ef59c5918439a1f9a41d83669020319a80574b804a5f95cbd7e', 'FIO (Testnet)'],
|
||||
['2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840', 'Jungle 3 (Testnet)'],
|
||||
['73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d', 'Jungle 4 (Testnet)'],
|
||||
['5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191', 'Kylin (Testnet)'],
|
||||
['b20901380af44ef59c5918439a1f9a41d83669020319a80574b804a5f95cbd7e', 'FIOTestnet'],
|
||||
['73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d', 'Jungle4'],
|
||||
['5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191', 'KylinTestnet'],
|
||||
['38b1d7815474d0c60683ecbea321d723e83f5da6ae5f1c1f9fecc69d9ba96465', 'Libre'],
|
||||
['b64646740308df2ee06c6b72f34c0f7fa066d940e831f752db2006fcc2b78dee', 'Libre (Testnet)'],
|
||||
['b64646740308df2ee06c6b72f34c0f7fa066d940e831f752db2006fcc2b78dee', 'LibreTestnet'],
|
||||
['384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0', 'Proton'],
|
||||
['71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd', 'Proton (Testnet)'],
|
||||
['71ee83bcf52142d61019d95f9cc5427ba6a0d7ff8accd9e2088ae2abeaf3d3dd', 'ProtonTestnet'],
|
||||
['4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11', 'Telos'],
|
||||
['1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f', 'Telos (Testnet)'],
|
||||
['1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f', 'TelosTestnet'],
|
||||
['8fc6dce7942189f842170de953932b1f66693ad3788f766e777b6f9d22335c02', 'UX'],
|
||||
['1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4', 'WAX'],
|
||||
['f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12', 'WAX (Testnet)'],
|
||||
['f16b1833c747c43682f4386fca9cbb327929334a762755ebec17f6f23c9b8a12', 'WAXTestnet'],
|
||||
])
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import {assert} from 'chai'
|
||||
|
||||
import {ChainDefinition, chainIdsToIndices, ChainNames, Chains} from '$lib'
|
||||
|
||||
suite('chains', function () {
|
||||
suite('chainIdsToIndices', function () {
|
||||
test('chainIdsToIndices -> ChainDefinitions ', function () {
|
||||
for (const [chainId, indice] of chainIdsToIndices) {
|
||||
const def = Chains[indice]
|
||||
assert.isTrue(def.id.equals(chainId), `${indice}: ${def.id} !== ${chainId}`)
|
||||
}
|
||||
})
|
||||
test('chainIdToIndices -> ChainNames', function () {
|
||||
for (const [, indice] of chainIdsToIndices) {
|
||||
const name = ChainNames[indice]
|
||||
assert.isDefined(name, `Not defined - ${indice}: ${name}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
suite('Chains', function () {
|
||||
test('valid data', function () {
|
||||
for (const [, indice] of chainIdsToIndices) {
|
||||
const def = Chains[indice]
|
||||
assert.instanceOf(def, ChainDefinition)
|
||||
assert.equal(def.name, ChainNames[indice])
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
+1
-2
@@ -8,8 +8,7 @@
|
||||
"types": ["mocha", "node"],
|
||||
"baseUrl": "..",
|
||||
"paths": {
|
||||
"@wharfkit/session": ["src"],
|
||||
"@wharfkit/session": ["src"],
|
||||
"$lib": ["src"],
|
||||
"$test": ["test"],
|
||||
"$test/*": ["test/*"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user