Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connect): update blockbook data #13670

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/address-validator/src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ var CURRENCIES = [
},
{
name: 'BNB Smart Chain',
symbol: 'bnb',
symbol: 'bsc',
validator: ETHValidator,
},
{
Expand Down
20 changes: 10 additions & 10 deletions packages/address-validator/tests/wallet_address_validator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ describe('WAValidator.validate()', function () {
isValidAddressType('aaaaaaaaaaaaaaa000000000000000', 'siacoin', 'prod', undefined);
});

it('should return true for correct BNB addresses', function () {
valid('0x0590396689ee1d287147e9383fb8dd24532f2006', 'bnb');
it('should return true for correct BSC addresses', function () {
valid('0x0590396689ee1d287147e9383fb8dd24532f2006', 'bsc');
valid('0x07fc5c2bcaa0fa6bdaa4fff897490312c8f33c27', 'BNB smart chain');
});

Expand Down Expand Up @@ -1116,12 +1116,12 @@ describe('WAValidator.validate()', function () {
});

it('should return true for correct BNB smart chain address', function () {
valid('0x7ae2f5b9e386cd1b50a4550696d957cb4900f03a', 'bnb');
valid('0x7ae2f5b9e386cd1b50a4550696d957cb4900f03a', 'bsc');
valid('0x0000000000000000000000000000000000001000', 'BNB Smart Chain');
});

it('should return false for incorrect BNB smart chain address', function () {
invalid('bnb1xlvns0n2mxh77mzaspn2hgav4rr4m8eerfju38', 'bnb');
invalid('bnb1xlvns0n2mxh77mzaspn2hgav4rr4m8eerfju38', 'bsc');
});

it('should return true for correct xtz(tezos) address', function () {
Expand Down Expand Up @@ -1567,13 +1567,13 @@ describe('WAValidator.validate()', function () {
invalid('g4VPBPrHZkfE8CsjuG2S4yBQNd455UWmk', 'stellar');
});

it('should return false for incorrect bnb addresses', function () {
it('should return false for incorrect bsc addresses', function () {
commonTests('bnb smart chain');
commonTests('bnb');
invalid('xrb_1f5e4w33ndqbkx4bw5jtp13kp5xghebfxcmw9hdt1f7goid1s4373w6tjdgu', 'bnb');
invalid('nano_1f5e4w33ndqbkx4bw5jtp13kp5xghebfxcmw9hdt1f7goid1s4373w6tjdgu', 'bnb');
invalid('xrb_1111111112111111111111111111111111111111111111111111hifc8npp', 'bnb');
invalid('nano_111111111111111111111111111111111111111111111111111hifc8npp', 'bnb');
commonTests('bsc');
invalid('xrb_1f5e4w33ndqbkx4bw5jtp13kp5xghebfxcmw9hdt1f7goid1s4373w6tjdgu', 'bsc');
invalid('nano_1f5e4w33ndqbkx4bw5jtp13kp5xghebfxcmw9hdt1f7goid1s4373w6tjdgu', 'bsc');
invalid('xrb_1111111112111111111111111111111111111111111111111111hifc8npp', 'bsc');
invalid('nano_111111111111111111111111111111111111111111111111111hifc8npp', 'bsc');
});

it('should return false for incorrect xtz(tezos) address', function () {
Expand Down
12 changes: 12 additions & 0 deletions packages/blockchain-link-types/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ export interface BlockchainSettings {
throttleBlockEvent?: number;
}

/**
* Discrepancy between `ServerInfo` and `CoinInfo`
*
* `ServerInfo` type
* - `shortcut` is a label for a network (e.g. for BASE `shortcut` has value ETH)
* - `network` is unique symbol for a network (e.g. for BASE `network` has value BASE)
*
* `CoinInfo` type
* - `shortcut` is a unique network symbol
* - `network` are data about network
*/
export interface ServerInfo {
url: string;
name: string;
Expand All @@ -53,6 +64,7 @@ export interface ServerInfo {
blockHeight: number;
blockHash: string;
consensusBranchId?: number; // zcash current branch id
network: string;
}

export type TokenStandard = 'ERC20' | 'ERC1155' | 'ERC721' | 'SPL' | 'SPL-2022' | '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 @@ -24,6 +24,7 @@ import { Addresses, filterTargets, enhanceVinVout, sumVinVout, transformTarget }
export const transformServerInfo = (payload: ServerInfo) => ({
name: payload.name,
shortcut: payload.shortcut,
network: payload.network ?? payload.shortcut, // some instances don't send network (e.g. regtest)
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 @@ -411,6 +411,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
32 changes: 32 additions & 0 deletions packages/blockchain-link/tests/unit/fixtures/getInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
decimals: 9,
name: 'TestMock',
shortcut: 'test',
network: 'test',
},
},
{
Expand All @@ -18,6 +19,7 @@ export default {
data: {
tomasklim marked this conversation as resolved.
Show resolved Hide resolved
name: 'Zcash',
shortcut: 'zec',
network: 'zec',
decimals: 8,
bestHeight: 1,
backend: {
Expand All @@ -34,9 +36,37 @@ export default {
decimals: 8,
name: 'Zcash',
shortcut: 'zec',
network: 'zec',
consensusBranchId: 3268858036,
},
},
{
description: 'BASE L2 network',
serverFixtures: [
{
method: 'getInfo',
response: {
data: {
name: 'Base Archive',
shortcut: 'ETH',
network: 'BASE',
decimals: 18,
bestHeight: 23603976,
backend: {
version: 'Geth/v1.101411.2-stable-3dd9b027/linux-amd64/go1.23.3',
},
},
},
},
],
response: {
name: 'Base Archive',
shortcut: 'ETH',
network: 'BASE',
decimals: 18,
blockHeight: 23603976,
},
},
{
description: 'Error',
serverFixtures: [
Expand All @@ -59,6 +89,7 @@ export default {
decimals: 6,
name: 'Ripple',
shortcut: 'xrp',
network: 'xrp',
testnet: false,
version: '1.4.0',
},
Expand Down Expand Up @@ -87,6 +118,7 @@ export default {
decimals: 6,
name: 'BlockfrostMock',
shortcut: 'ada',
network: 'ada',
testnet: false,
version: '1.4.0',
},
Expand Down
15 changes: 12 additions & 3 deletions packages/connect-common/files/coins-eth.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"is_testnet": false,
"name": "Ethereum",
"shortcut": "ETH",
"label": "ETH",
"slip44": 60,
"support": {
"T1B1": "1.6.2",
Expand All @@ -30,7 +31,8 @@
"coingecko_id": "binance-smart-chain",
"is_testnet": false,
"name": "BNB Smart Chain",
"shortcut": "BNB",
"shortcut": "BSC",
"label": "BNB",
"slip44": 714,
"support": {
"T1B1": "1.9.4",
Expand All @@ -51,6 +53,7 @@
"is_testnet": false,
"name": "Ethereum Classic",
"shortcut": "ETC",
"label": "ETC",
"slip44": 61,
"support": {
"T1B1": "1.6.2",
Expand All @@ -71,6 +74,7 @@
"is_testnet": false,
"name": "Polygon",
"shortcut": "POL",
"label": "POL",
"slip44": 966,
"support": {
"T1B1": "1.9.4",
Expand All @@ -91,6 +95,7 @@
"is_testnet": false,
"name": "Arbitrum One",
"shortcut": "ARB",
"label": "ETH",
"slip44": 9001,
"support": {
"T1B1": "1.9.4",
Expand All @@ -111,7 +116,8 @@
"is_testnet": false,
"name": "Base",
"shortcut": "BASE",
"slip44": 1,
"label": "ETH",
"slip44": 8453,
"support": {
"T1B1": "1.9.4",
"T2B1": "2.6.1",
Expand All @@ -131,7 +137,8 @@
"is_testnet": false,
"name": "Optimism",
"shortcut": "OP",
"slip44": 1,
"label": "ETH",
"slip44": 614,
"support": {
"T1B1": "1.9.4",
"T2B1": "2.6.1",
Expand All @@ -150,6 +157,7 @@
"is_testnet": true,
"name": "Holesky",
"shortcut": "tHOL",
"label": "tHOL",
"slip44": 1,
"support": {
"T1B1": "1.11.3",
Expand All @@ -169,6 +177,7 @@
"is_testnet": true,
"name": "Sepolia",
"shortcut": "tSEP",
"label": "tSEP",
"slip44": 1,
"support": {
"T1B1": "1.11.3",
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.network,
testnet: true,
version: '0.0.0-mocked',
},
Expand Down
1 change: 1 addition & 0 deletions packages/connect/e2e/__wscache__/blockfrost.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const blockfrostFixtures = {
data: {
name: 'Blockfrost',
shortcut: params.shortcut,
network: params.network,
decimals: 6,
testnet: false,
version: '1.4.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class BlockchainLink {
url: this.name,
name: this.name,
shortcut: this.name,
network: this.name,
consensusBranchId: 1001,
});
}
Expand Down
10 changes: 3 additions & 7 deletions packages/connect/src/backend/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ const getNormalizedTrezorShortcut = (shortcut: string) => {
return 'XRP';
}

if (['OP', 'BASE', 'ARB'].includes(shortcut)) {
return 'ETH';
}

return shortcut;
};

Expand Down Expand Up @@ -132,10 +128,10 @@ export class Blockchain {

this.serverInfo = info;

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

if (trezorShortcut.toLowerCase() !== backendShortcut.toLowerCase()) {
if (backendNetworkShortcut.toLowerCase() !== trezorNetworkShortcut.toLowerCase()) {
throw ERRORS.TypedError('Backend_Invalid');
}

Expand Down
29 changes: 28 additions & 1 deletion packages/connect/src/backend/__tests__/Blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,34 @@ describe('backend/Blockchain', () => {
});

it('cache estimated fees (ethereum-like)', async () => {
const coinInfo = getEthereumNetwork('Ethereum');
const coinInfo = getEthereumNetwork('ETH');
if (!coinInfo) throw new Error('coinInfo is missing');

const spy = jest.spyOn(BlockchainLink.prototype, 'estimateFee');

const backend = await initBlockchain(coinInfo, () => {});

// blocks: 1 was not requested before
await backend.estimateFee({ blocks: [1] });
expect(spy.mock.calls.length).toEqual(1);

// blocks: 1 is requested again, returned from cache
await backend.estimateFee({ blocks: [1] });
expect(spy.mock.calls.length).toEqual(1);

// blocks: 2 was not requested before
await backend.estimateFee({ blocks: [1, 2] });
expect(spy.mock.calls.length).toEqual(2);

// request with "specific" field
await backend.estimateFee({ blocks: [1, 2], specific: { value: '0x0' } });
expect(spy.mock.calls.length).toEqual(3);

spy.mockClear();
});

it('cache estimated fees (ethereum-like) - L2 network', async () => {
const coinInfo = getEthereumNetwork('BASE');
if (!coinInfo) throw new Error('coinInfo is missing');

const spy = jest.spyOn(BlockchainLink.prototype, 'estimateFee');
Expand Down
16 changes: 8 additions & 8 deletions packages/connect/src/data/coinInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ export const getBitcoinNetwork = (pathOrName: DerivationPath) => {
return networks.find(n => n.slip44 === slip44);
};

export const getEthereumNetwork = (pathOrName: DerivationPath) => {
export const getEthereumNetwork = (pathOrNetworkSymbol: DerivationPath) => {
tomasklim marked this conversation as resolved.
Show resolved Hide resolved
const networks = cloneObject(ethereumNetworks);
if (typeof pathOrName === 'string') {
const name = pathOrName.toLowerCase();

return networks.find(
n => n.name.toLowerCase() === name || n.shortcut.toLowerCase() === name,
);
if (typeof pathOrNetworkSymbol === 'string') {
const networkSymbol = pathOrNetworkSymbol.toLowerCase();

return networks.find(network => network.shortcut.toLowerCase() === networkSymbol);
}
const slip44 = fromHardened(pathOrName[1]);

const slip44 = fromHardened(pathOrNetworkSymbol[1]);

return networks.find(n => n.slip44 === slip44);
};
Expand Down Expand Up @@ -261,7 +261,7 @@ const parseEthereumNetworksJson = (json: any) => {
...ethereumNetworkInfoBase,
blockchainLink: network.blockchain_link,
chainId: network.chain_id,
label: network.name,
label: network.label,
name: network.name,
shortcut: network.shortcut,
slip44: network.slip44,
Expand Down
Loading
Loading