From bfb703385ba49be58aa56753a4b677134f8add86 Mon Sep 17 00:00:00 2001 From: tomasklim Date: Tue, 6 Aug 2024 14:11:10 +0200 Subject: [PATCH] feat(connect): use network shortcut not just symbol for identification --- packages/blockchain-link-types/src/blockbook-api.ts | 1 + packages/blockchain-link-types/src/common.ts | 1 + packages/blockchain-link-utils/src/blockbook.ts | 1 + packages/blockchain-link-utils/src/ripple.ts | 1 + packages/blockchain-link/src/workers/blockfrost/index.ts | 1 + .../src/workers/electrum/methods/getInfo.ts | 1 + packages/blockchain-link/src/workers/solana/index.ts | 1 + packages/connect/e2e/__wscache__/blockbook.js | 1 + packages/connect/src/backend/Blockchain.ts | 7 ++++++- packages/suite-web/e2e/fixtures/eth-account.ts | 1 + packages/suite-web/e2e/fixtures/send-form-doge.ts | 1 + .../suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts | 1 + 12 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/blockchain-link-types/src/blockbook-api.ts b/packages/blockchain-link-types/src/blockbook-api.ts index 06835e78a8a6..04c9c87b5eae 100644 --- a/packages/blockchain-link-types/src/blockbook-api.ts +++ b/packages/blockchain-link-types/src/blockbook-api.ts @@ -357,6 +357,7 @@ export interface WsInfoRes { bestHeight: number; bestHash: string; block0Hash: string; + network: string; testnet: boolean; backend: WsBackendInfo; } diff --git a/packages/blockchain-link-types/src/common.ts b/packages/blockchain-link-types/src/common.ts index 0d9fbeed2140..c9d268408290 100644 --- a/packages/blockchain-link-types/src/common.ts +++ b/packages/blockchain-link-types/src/common.ts @@ -32,6 +32,7 @@ export interface ServerInfo { blockHeight: number; blockHash: string; consensusBranchId?: number; // zcash current branch id + network: string; } export type TokenStandard = 'ERC20' | 'ERC1155' | 'ERC721' | 'SPL'; diff --git a/packages/blockchain-link-utils/src/blockbook.ts b/packages/blockchain-link-utils/src/blockbook.ts index 470ffbd9cea4..afec4c9f9dee 100644 --- a/packages/blockchain-link-utils/src/blockbook.ts +++ b/packages/blockchain-link-utils/src/blockbook.ts @@ -22,6 +22,7 @@ import { Addresses, filterTargets, enhanceVinVout, sumVinVout, transformTarget } export const transformServerInfo = (payload: ServerInfo) => ({ name: payload.name, shortcut: payload.shortcut, + network: payload.network || payload.shortcut, // for backwards Blockbook compatibility testnet: payload.testnet, version: payload.version, decimals: payload.decimals, diff --git a/packages/blockchain-link-utils/src/ripple.ts b/packages/blockchain-link-utils/src/ripple.ts index 4de17fbb07ec..2129f3cbb081 100644 --- a/packages/blockchain-link-utils/src/ripple.ts +++ b/packages/blockchain-link-utils/src/ripple.ts @@ -4,6 +4,7 @@ import type { Transaction } from '@trezor/blockchain-link-types'; export const transformServerInfo = (payload: any) => ({ name: 'Ripple', shortcut: 'xrp', + network: 'xrp', testnet: false, version: payload.buildVersion, decimals: 6, diff --git a/packages/blockchain-link/src/workers/blockfrost/index.ts b/packages/blockchain-link/src/workers/blockfrost/index.ts index 7fa640e7c7ec..615a8ac3fa1f 100644 --- a/packages/blockchain-link/src/workers/blockfrost/index.ts +++ b/packages/blockchain-link/src/workers/blockfrost/index.ts @@ -26,6 +26,7 @@ const getInfo = async (request: Request) => { type: RESPONSES.GET_INFO, payload: { url: api.options.url, + network: info.shortcut, ...info, }, } as const; diff --git a/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts b/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts index 88da9bb1a916..3ba69428f613 100644 --- a/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts +++ b/packages/blockchain-link/src/workers/electrum/methods/getInfo.ts @@ -18,6 +18,7 @@ const getInfo: Api = client => { blockHash: blockheaderToBlockhash(hex), name: 'Bitcoin', shortcut: coin, + network: coin, testnet: coin === 'REGTEST', decimals: 8, }); diff --git a/packages/blockchain-link/src/workers/solana/index.ts b/packages/blockchain-link/src/workers/solana/index.ts index cfad7f14534e..4c86e340fc6c 100644 --- a/packages/blockchain-link/src/workers/solana/index.ts +++ b/packages/blockchain-link/src/workers/solana/index.ts @@ -244,6 +244,7 @@ const getInfo = async (request: Request) => { blockHeight, blockHash, shortcut: isTestnet ? 'dsol' : 'sol', + network: isTestnet ? 'dsol' : 'sol', url: api.rpcEndpoint, name: 'Solana', version: (await api.getVersion())['solana-core'], diff --git a/packages/connect/e2e/__wscache__/blockbook.js b/packages/connect/e2e/__wscache__/blockbook.js index de6ace0ec33b..b1892307106d 100644 --- a/packages/connect/e2e/__wscache__/blockbook.js +++ b/packages/connect/e2e/__wscache__/blockbook.js @@ -10,6 +10,7 @@ const blockbookFixtures = { bestHeight: 7000000, // high block to make sure that utxos have enough confirmations (composeTransaction test) bestHash: '', block0Hash: '', + network: params.shortcut, testnet: true, version: '0.0.0-mocked', }, diff --git a/packages/connect/src/backend/Blockchain.ts b/packages/connect/src/backend/Blockchain.ts index 7cc5e54c0e27..f56317903da9 100644 --- a/packages/connect/src/backend/Blockchain.ts +++ b/packages/connect/src/backend/Blockchain.ts @@ -130,7 +130,12 @@ export class Blockchain { const shortcut = getNormalizedShortcut(this.coinInfo.shortcut); - if (info.shortcut.toLowerCase() !== shortcut.toLowerCase()) { + if ( + (this.coinInfo.type === 'ethereum' && + info.network.toLowerCase() !== this.coinInfo.chain?.toLowerCase()) || + (this.coinInfo.type !== 'ethereum' && + info.shortcut.toLowerCase() !== shortcut.toLowerCase()) + ) { throw ERRORS.TypedError('Backend_Invalid'); } diff --git a/packages/suite-web/e2e/fixtures/eth-account.ts b/packages/suite-web/e2e/fixtures/eth-account.ts index ae51aae5757f..bbe00cab4f6a 100644 --- a/packages/suite-web/e2e/fixtures/eth-account.ts +++ b/packages/suite-web/e2e/fixtures/eth-account.ts @@ -103,6 +103,7 @@ export const fixtures = [ bestHeight: 19960825, bestHash: '0x8339e411cd2f62b9493e36c444f7bd11ec716ceaa94f491e9726233d22abc024', block0Hash: '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', + network: 'ETH', testnet: false, backend: { version: 'erigon/2.59.3/linux-amd64/go1.21.6', diff --git a/packages/suite-web/e2e/fixtures/send-form-doge.ts b/packages/suite-web/e2e/fixtures/send-form-doge.ts index 0c94e214f539..e17e33b8ac80 100644 --- a/packages/suite-web/e2e/fixtures/send-form-doge.ts +++ b/packages/suite-web/e2e/fixtures/send-form-doge.ts @@ -131,6 +131,7 @@ export const fixtures = [ bestHeight: 4484566, bestHash: '38fbb073e7eb4bfac9ed485dd0b3212247fb2a3d8b509dc9738c01a86ede33b3', block0Hash: '1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691', + network: 'DOGE', testnet: false, backend: { version: '1140600', subversion: '/Shibetoshi:1.14.6/' }, }, diff --git a/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts b/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts index c1c86db86711..cd7ac4240613 100644 --- a/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts +++ b/packages/suite-web/e2e/fixtures/send-form-ltc-mimble-wimble.ts @@ -95,6 +95,7 @@ export const fixtures = [ bestHeight: 2373436, bestHash: '2c1bc2b99f8a4447a57dfc7b694b9c82bff1b3af7cce8ff151df01238dc07c8b', block0Hash: '12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2', + network: 'LTC', testnet: false, backend: { version: '210201', subversion: '/LitecoinCore:0.21.2.1/' }, },