From 6de0b55390b48fd8e61d6aeef7bcc29760f36355 Mon Sep 17 00:00:00 2001 From: octo-gone Date: Thu, 11 Apr 2024 20:22:14 +0300 Subject: [PATCH 1/6] feat: display chain id and chain name instead of identifier --- src/api/gateways.ts | 3 +++ src/commands/gateways/ls.ts | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/gateways.ts b/src/api/gateways.ts index 590068b..37e9995 100644 --- a/src/api/gateways.ts +++ b/src/api/gateways.ts @@ -8,6 +8,9 @@ export type Provider = { export type Gateway = { network: string; + chainName: string; + chainId?: number; + chainSS58Prefix?: number; providers: Provider[]; }; diff --git a/src/commands/gateways/ls.ts b/src/commands/gateways/ls.ts index 58b3fde..3e02898 100644 --- a/src/commands/gateways/ls.ts +++ b/src/commands/gateways/ls.ts @@ -34,7 +34,7 @@ export default class Ls extends CliCommand { !type || type === 'substrate' ? getSubstrateGateways() : [], ]); - const maxNameLength = maxBy([...evm, ...substrate], (g) => g.network.length)?.network.length; + const maxNameLength = maxBy([...evm, ...substrate], (g) => g.chainName.length)?.chainName.length; switch (type) { case 'evm': @@ -59,7 +59,7 @@ export default class Ls extends CliCommand { } gateways = search - ? gateways.filter((g) => g.network.toLocaleLowerCase().includes(search.toLocaleLowerCase())) + ? gateways.filter((g) => g.chainName.toLocaleLowerCase().includes(search.toLocaleLowerCase())) : gateways; if (!gateways.length) { @@ -69,7 +69,7 @@ export default class Ls extends CliCommand { const table = new Table({ wordWrap: true, colWidths: [maxNameLength ? maxNameLength + 2 : null], - head: ['Name', 'Release', 'Gateway URL'], + head: ['Name', summary === 'EVM' ? 'Chain ID' : 'SS58 Prefix', 'Release', 'Gateway URL'], wrapOnWordBoundary: false, style: { @@ -79,8 +79,8 @@ export default class Ls extends CliCommand { }, }); - gateways.map(({ network, providers }) => { - table.push([network, chalk.dim(providers[0].release), providers[0].dataSourceUrl]); + gateways.map(({ chainName, chainId, chainSS58Prefix, providers }) => { + table.push([chainName, summary === 'EVM' ? chalk.dim(chainId || '') : chalk.dim(chainSS58Prefix || ''), chalk.dim(providers[0].release), providers[0].dataSourceUrl]); }); this.log(table.toString()); From a77d147a5d06765d2db804776f0d1ec4d9e4862c Mon Sep 17 00:00:00 2001 From: octo-gone Date: Mon, 22 Apr 2024 14:30:43 +0300 Subject: [PATCH 2/6] fix: remove ss58 prefix --- src/commands/gateways/ls.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/commands/gateways/ls.ts b/src/commands/gateways/ls.ts index 3e02898..0cc6d4c 100644 --- a/src/commands/gateways/ls.ts +++ b/src/commands/gateways/ls.ts @@ -66,10 +66,13 @@ export default class Ls extends CliCommand { return this.log('No gateways found'); } + const headRow = ['Name', 'Release', 'Gateway URL']; + if (summary === 'EVM') + headRow.splice(1, 0, 'Chain ID'); const table = new Table({ wordWrap: true, colWidths: [maxNameLength ? maxNameLength + 2 : null], - head: ['Name', summary === 'EVM' ? 'Chain ID' : 'SS58 Prefix', 'Release', 'Gateway URL'], + head: headRow, wrapOnWordBoundary: false, style: { @@ -79,8 +82,11 @@ export default class Ls extends CliCommand { }, }); - gateways.map(({ chainName, chainId, chainSS58Prefix, providers }) => { - table.push([chainName, summary === 'EVM' ? chalk.dim(chainId || '') : chalk.dim(chainSS58Prefix || ''), chalk.dim(providers[0].release), providers[0].dataSourceUrl]); + gateways.map(({ chainName, chainId, providers }) => { + const row = [chainName, chalk.dim(providers[0].release), providers[0].dataSourceUrl]; + if (summary === 'EVM') + row.splice(1, 0, chalk.dim(chainId || '')); + table.push(row); }); this.log(table.toString()); From fc6f39371938cf4f1e621f9e27adea582e5af6b4 Mon Sep 17 00:00:00 2001 From: Igor Mahov Date: Wed, 24 Apr 2024 17:50:00 +0300 Subject: [PATCH 3/6] feat: chain id search --- .gitignore | 5 +++++ src/commands/gateways/ls.ts | 30 ++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 896263d..35fb3e7 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,8 @@ dist/ # Oclif oclif.manifest.json +# Yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz diff --git a/src/commands/gateways/ls.ts b/src/commands/gateways/ls.ts index 0cc6d4c..5a6858d 100644 --- a/src/commands/gateways/ls.ts +++ b/src/commands/gateways/ls.ts @@ -22,29 +22,34 @@ export default class Ls extends CliCommand { description: 'Search gateways', required: false, }), + id: Flags.string({ + char: 'i', + description: 'Search by id', + required: false, + }), }; async run(): Promise { const { - flags: { type, search }, + flags: { type, search, id: chainId }, } = await this.parse(Ls); const [evm, substrate] = await Promise.all([ - !type || type === 'evm' ? getEvmGateways() : [], - !type || type === 'substrate' ? getSubstrateGateways() : [], + !type || type === 'evm' || chainId ? getEvmGateways() : [], + !chainId && (!type || type === 'substrate') ? getSubstrateGateways() : [], ]); const maxNameLength = maxBy([...evm, ...substrate], (g) => g.chainName.length)?.chainName.length; switch (type) { case 'evm': - this.processGateways(evm, { search, summary: 'EVM', maxNameLength }); + this.processGateways(evm, { search, summary: 'EVM', chainId, maxNameLength }); break; case 'substrate': this.processGateways(substrate, { search, summary: 'Substrate', maxNameLength }); break; default: - this.processGateways(evm, { search, summary: 'EVM', maxNameLength }); + this.processGateways(evm, { search, summary: 'EVM', chainId, maxNameLength }); this.log(); this.processGateways(substrate, { search, summary: 'Substrate', maxNameLength }); } @@ -52,7 +57,12 @@ export default class Ls extends CliCommand { processGateways( gateways: Gateway[], - { summary, search, maxNameLength }: { search?: string; summary?: string; maxNameLength?: number }, + { + search, + summary, + chainId, + maxNameLength, + }: { search?: string; summary?: string; chainId?: string; maxNameLength?: number }, ) { if (summary) { this.log(chalk.bold(summary)); @@ -62,13 +72,14 @@ export default class Ls extends CliCommand { ? gateways.filter((g) => g.chainName.toLocaleLowerCase().includes(search.toLocaleLowerCase())) : gateways; + if (summary === 'EVM' && chainId) gateways = gateways.filter((g) => String(g.chainId) === chainId); + if (!gateways.length) { return this.log('No gateways found'); } const headRow = ['Name', 'Release', 'Gateway URL']; - if (summary === 'EVM') - headRow.splice(1, 0, 'Chain ID'); + if (summary === 'EVM') headRow.splice(1, 0, 'Chain ID'); const table = new Table({ wordWrap: true, colWidths: [maxNameLength ? maxNameLength + 2 : null], @@ -84,8 +95,7 @@ export default class Ls extends CliCommand { gateways.map(({ chainName, chainId, providers }) => { const row = [chainName, chalk.dim(providers[0].release), providers[0].dataSourceUrl]; - if (summary === 'EVM') - row.splice(1, 0, chalk.dim(chainId || '')); + if (summary === 'EVM') row.splice(1, 0, chalk.dim(chainId || '')); table.push(row); }); From e1b7d77920967999216994bd28b66297794ee823 Mon Sep 17 00:00:00 2001 From: Igor Mahov Date: Thu, 25 Apr 2024 15:19:21 +0300 Subject: [PATCH 4/6] refactor: filrter by name, chain id and ss58 --- src/commands/gateways/ls.ts | 53 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/commands/gateways/ls.ts b/src/commands/gateways/ls.ts index 5a6858d..33c8dfb 100644 --- a/src/commands/gateways/ls.ts +++ b/src/commands/gateways/ls.ts @@ -12,74 +12,78 @@ export default class Ls extends CliCommand { static flags = { type: Flags.string({ char: 't', - description: 'Filter gateways by network type', + description: 'Filter by network type', options: ['evm', 'substrate'], helpValue: '', required: false, }), - search: Flags.string({ - char: 's', - description: 'Search gateways', + name: Flags.string({ + char: 'n', + description: 'Filter by network name', + helpValue: '', required: false, }), - id: Flags.string({ - char: 'i', - description: 'Search by id', + chain: Flags.string({ + char: 'c', + description: 'Filter by chain ID or SS58 prefix', + helpValue: '', required: false, }), }; async run(): Promise { const { - flags: { type, search, id: chainId }, + flags: { type, name, chain: chainId }, } = await this.parse(Ls); const [evm, substrate] = await Promise.all([ - !type || type === 'evm' || chainId ? getEvmGateways() : [], - !chainId && (!type || type === 'substrate') ? getSubstrateGateways() : [], + !type || type === 'evm' ? getEvmGateways() : [], + !type || type === 'substrate' ? getSubstrateGateways() : [], ]); const maxNameLength = maxBy([...evm, ...substrate], (g) => g.chainName.length)?.chainName.length; switch (type) { case 'evm': - this.processGateways(evm, { search, summary: 'EVM', chainId, maxNameLength }); + this.processGateways(evm, { type, name, chainId, summary: 'EVM', maxNameLength }); break; case 'substrate': - this.processGateways(substrate, { search, summary: 'Substrate', maxNameLength }); + this.processGateways(substrate, { type, name, chainId, summary: 'Substrate', maxNameLength }); break; default: - this.processGateways(evm, { search, summary: 'EVM', chainId, maxNameLength }); + this.processGateways(evm, { type: 'evm', name, chainId, summary: 'EVM', maxNameLength }); this.log(); - this.processGateways(substrate, { search, summary: 'Substrate', maxNameLength }); + this.processGateways(substrate, { type: 'substrate', name, chainId, summary: 'Substrate', maxNameLength }); } } processGateways( gateways: Gateway[], { - search, - summary, + type, + name, chainId, + summary, maxNameLength, - }: { search?: string; summary?: string; chainId?: string; maxNameLength?: number }, + }: { type: 'evm' | 'substrate'; name?: string; chainId?: string; summary?: string; maxNameLength?: number }, ) { if (summary) { this.log(chalk.bold(summary)); } - gateways = search - ? gateways.filter((g) => g.chainName.toLocaleLowerCase().includes(search.toLocaleLowerCase())) + gateways = name + ? gateways.filter((g) => g.network.toLocaleLowerCase().match(new RegExp(name.toLocaleLowerCase()))) : gateways; - if (summary === 'EVM' && chainId) gateways = gateways.filter((g) => String(g.chainId) === chainId); + gateways = chainId + ? gateways.filter((g) => (type === 'evm' ? String(g.chainId) === chainId : String(g.chainSS58Prefix) === chainId)) + : gateways; if (!gateways.length) { return this.log('No gateways found'); } - const headRow = ['Name', 'Release', 'Gateway URL']; - if (summary === 'EVM') headRow.splice(1, 0, 'Chain ID'); + const headRow = ['Name', ...(type === 'evm' ? ['Chain ID'] : ['SS58 prefix']), 'Gateway URL']; const table = new Table({ wordWrap: true, colWidths: [maxNameLength ? maxNameLength + 2 : null], @@ -93,9 +97,8 @@ export default class Ls extends CliCommand { }, }); - gateways.map(({ chainName, chainId, providers }) => { - const row = [chainName, chalk.dim(providers[0].release), providers[0].dataSourceUrl]; - if (summary === 'EVM') row.splice(1, 0, chalk.dim(chainId || '')); + gateways.map(({ chainName, chainId, chainSS58Prefix, providers }) => { + const row = [chainName, chalk.dim(chainId || chainSS58Prefix), providers[0].dataSourceUrl]; table.push(row); }); From 03ac7d1018d94ad0d7986db285e2313af1136b49 Mon Sep 17 00:00:00 2001 From: Igor Mahov Date: Thu, 25 Apr 2024 16:13:52 +0300 Subject: [PATCH 5/6] fixes --- src/commands/gateways/ls.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/commands/gateways/ls.ts b/src/commands/gateways/ls.ts index 33c8dfb..f1cd978 100644 --- a/src/commands/gateways/ls.ts +++ b/src/commands/gateways/ls.ts @@ -71,9 +71,7 @@ export default class Ls extends CliCommand { this.log(chalk.bold(summary)); } - gateways = name - ? gateways.filter((g) => g.network.toLocaleLowerCase().match(new RegExp(name.toLocaleLowerCase()))) - : gateways; + gateways = name ? gateways.filter((g) => g.network.match(new RegExp(name, 'i'))) : gateways; gateways = chainId ? gateways.filter((g) => (type === 'evm' ? String(g.chainId) === chainId : String(g.chainSS58Prefix) === chainId)) @@ -83,7 +81,7 @@ export default class Ls extends CliCommand { return this.log('No gateways found'); } - const headRow = ['Name', ...(type === 'evm' ? ['Chain ID'] : ['SS58 prefix']), 'Gateway URL']; + const headRow = ['Network', type === 'evm' ? 'Chain ID' : 'SS58 prefix', 'Gateway URL']; const table = new Table({ wordWrap: true, colWidths: [maxNameLength ? maxNameLength + 2 : null], @@ -98,7 +96,7 @@ export default class Ls extends CliCommand { }); gateways.map(({ chainName, chainId, chainSS58Prefix, providers }) => { - const row = [chainName, chalk.dim(chainId || chainSS58Prefix), providers[0].dataSourceUrl]; + const row = [chainName, chalk.dim(chainId || chainSS58Prefix || '-'), providers[0].dataSourceUrl]; table.push(row); }); From 411fa70ee1935efb22e8091d925eb2587c04b4b8 Mon Sep 17 00:00:00 2001 From: Eugene Formanenko Date: Fri, 26 Apr 2024 10:02:11 +0400 Subject: [PATCH 6/6] fix: tests --- .github/workflows/{test.yml => test.yaml} | 25 ++++++++++++----------- package.json | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) rename .github/workflows/{test.yml => test.yaml} (57%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yaml similarity index 57% rename from .github/workflows/test.yml rename to .github/workflows/test.yaml index 41c1421..1d96a67 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yaml @@ -24,19 +24,20 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - uses: actions/cache@v3 - id: yarn-cache - env: - cache-name: rest-api + - name: Install node + uses: actions/setup-node@v4 with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-${{ env.cache-name }}-yarn-${{ hashFiles('yarn.lock') }} - restore-keys: | - ${{ runner.os }}-${{ env.cache-name }}-yarn- + node-version: 18 + + - name: Install Yarn + run: corepack enable + + # Yarn dependencies cannot be cached until yarn is installed + # WORKAROUND: https://github.com/actions/setup-node/issues/531 + - name: Extract cached dependencies + uses: actions/setup-node@v4 + with: + cache: yarn - name: Install run: yarn install diff --git a/package.json b/package.json index 36b6249..91e1fc0 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "sqd": "./bin/run.js", "bl": "node ./lib/blessed.js", "lint": "eslint --fix src/**/*", - "test:unit": "NODE_ENV=test jest --bail --testRegex=.unit.spec.ts$", + "test:unit": "NODE_ENV=test jest --bail --testRegex=.unit.spec.ts\\$", "tsc": "tsc --noEmit", "pkg:build": "./bin/pkg-build.sh", "pkg:compress": "./bin/pkg-compress.sh",