Skip to content

Commit

Permalink
feat(connect): use network shortcut not just symbol for identification
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim authored and adderpositive committed Dec 11, 2024
1 parent 692a0e3 commit 61c9531
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/blockchain-link-types/src/blockbook-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export interface WsInfoRes {
bestHeight: number;
bestHash: string;
block0Hash: string;
network: string;
testnet: boolean;
backend: WsBackendInfo;
}
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link-types/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface ServerInfo {
blockHeight: number;
blockHash: string;
consensusBranchId?: number; // zcash current branch id
network: string;
}

export type TokenStandard = 'ERC20' | 'ERC1155' | 'ERC721' | 'SPL' | 'BEP20';
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link-utils/src/blockbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link-utils/src/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link/src/workers/blockfrost/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const getInfo = async (request: Request<MessageTypes.GetInfo>) => {
type: RESPONSES.GET_INFO,
payload: {
url: api.options.url,
network: info.shortcut,
...info,
},
} as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const getInfo: Api<Req, Res> = client => {
blockHash: blockheaderToBlockhash(hex),
name: 'Bitcoin',
shortcut: coin,
network: coin,
testnet: coin === 'REGTEST',
decimals: 8,
});
Expand Down
1 change: 1 addition & 0 deletions packages/blockchain-link/src/workers/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ const getInfo = async (request: Request<MessageTypes.GetInfo>, isTestnet: boolea
blockHeight: Number(blockHeight),
blockHash,
shortcut: isTestnet ? 'dsol' : 'sol',
network: isTestnet ? 'dsol' : 'sol',
url: api.clusterUrl,
name: 'Solana',
version: (await api.rpc.getVersion().send())['solana-core'],
Expand Down
1 change: 1 addition & 0 deletions packages/connect/e2e/__wscache__/blockbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
12 changes: 10 additions & 2 deletions packages/connect/src/backend/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,17 @@ export class Blockchain {
this.serverInfo = info;

const trezorShortcut = getNormalizedTrezorShortcut(this.coinInfo.shortcut);
const backendShortcut = this.serverInfo.shortcut;

if (trezorShortcut.toLowerCase() !== backendShortcut.toLowerCase()) {
// TODO: remove of change
// const backendShortcut = this.serverInfo.shortcut;
// if (trezorShortcut.toLowerCase() !== backendShortcut.toLowerCase()) {

if (
(this.coinInfo.type === 'ethereum' &&
info.network.toLowerCase() !== this.coinInfo.chain?.toLowerCase()) ||
(this.coinInfo.type !== 'ethereum' &&
info.network.toLowerCase() !== trezorShortcut.toLowerCase())
) {
throw ERRORS.TypedError('Backend_Invalid');
}

Expand Down
1 change: 1 addition & 0 deletions packages/suite-web/e2e/fixtures/eth-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/suite-web/e2e/fixtures/send-form-doge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/' },
},
Expand Down

0 comments on commit 61c9531

Please sign in to comment.