Skip to content

Commit

Permalink
Add alias for chain (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
fewensa authored Oct 10, 2024
1 parent e54bcf6 commit 837e08a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions conf/mainnets/crab.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
id: '44'
code: crab-dvm
alias:
- crab
name: Crab
rpcs:
- https://crab-rpc.dcdao.box
Expand Down
2 changes: 2 additions & 0 deletions conf/mainnets/darwinia.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
id: '46'
code: darwinia-dvm
alias:
- darwinia
name: Darwinia
rpcs:
- https://rpc.darwinia.network
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.

13 changes: 13 additions & 0 deletions scripts/generate/stdconf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as helper from './_helper.mjs'

export function standardization(global, ccf) {
_stdGeneric(global, ccf);
_stdAlias(global, ccf);
_stdRpcs(global, ccf);
_stdMessagers(global, ccf);
_stdIndexers(global, ccf);
Expand All @@ -17,6 +18,18 @@ function _stdGeneric(global, ccf) {
if (!ccf.rpcs) ccf.rpcs = [];
if (!ccf.protocol) ccf.protocol = {};
if (!ccf.indexers) ccf.indexers = [];
if (!ccf.alias) ccf.alias = [];
}

function _stdAlias(global, ccf) {
if (!ccf.alias.length) {
ccf.alias.push(ccf.code);
return;
}
if (ccf.alias.find(item => item.toUpperCase() === ccf.code.toUpperCase())) {
return ccf.alias;
}
ccf.alias.push(ccf.code);
}

function _stdMessagers(global, ccf) {
Expand Down
2 changes: 1 addition & 1 deletion template/ts/files/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@helixbridge/helixconf",
"version": "1.1.15",
"version": "1.1.16",
"description": "Helix conf",
"main": "dist/src/index.js",
"publishConfig": {
Expand Down
7 changes: 7 additions & 0 deletions template/ts/files/src/helixconf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface HelixChainConfType {
id: bigint
lzid?: bigint
code: string
alias: string[]
name: string
rpcs: ChainRpc[]
protocol: Record<HelixProtocolName, string>
Expand Down Expand Up @@ -213,6 +214,10 @@ export class HelixChainConf {
return this._data.code;
}

get alias(): string[] {
return this._data.alias;
}

get name(): string {
return this._data.name;
}
Expand Down Expand Up @@ -430,6 +435,7 @@ export class HelixChainConf {
contract: this.contract,
additional: this.additional,
code: this.code,
alias: this.alias,
name: this.name,
rpcs: this.rpcs,
indexers: this.indexers,
Expand All @@ -449,6 +455,7 @@ export class HelixChainConf {
contract: json.contract,
additional: json.additional,
code: json.code,
alias: json.alias,
name: json.name,
rpcs: ChainRpc.fromOptions(json.rpcs),
indexers: json.indexers,
Expand Down
6 changes: 5 additions & 1 deletion template/ts/templates/helpers.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ export class HelixChain {

static get(chain: string | number | bigint): HelixChainConf | undefined {
const upperCaseChainName = chain.toString().toUpperCase();
return HelixChain.chains().find(
const pickedChain = HelixChain.chains().find(
item => item.code.toUpperCase() === upperCaseChainName || item.id.toString() === upperCaseChainName
);
if (pickedChain) return pickedChain;
return HelixChain.chains().find(
item => item.alias.find(alias => alias.toUpperCase() === upperCaseChainName)
);
}
}

Expand Down

0 comments on commit 837e08a

Please sign in to comment.