@ledgerhq/coin-evm 9.0.1 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.oxlintrc.json +2 -6
- package/CHANGELOG.md +18 -0
- package/lib/abis/index.d.ts +8 -0
- package/lib/abis/index.d.ts.map +1 -1
- package/lib/abis/index.js +30 -0
- package/lib/abis/index.js.map +1 -1
- package/lib/adapters/blockOperations.js +2 -2
- package/lib/adapters/blockOperations.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/internalTxSources.d.ts.map +1 -1
- package/lib/internalTxSources.js +21 -3
- package/lib/internalTxSources.js.map +1 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +11 -3
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +4 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +4 -2
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.js +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +2 -2
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/listOperations.js +1 -1
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/predicates.d.ts +17 -0
- package/lib/logic/predicates.d.ts.map +1 -0
- package/lib/logic/predicates.js +126 -0
- package/lib/logic/predicates.js.map +1 -0
- package/lib/logic/validateIntent.d.ts.map +1 -1
- package/lib/logic/validateIntent.js +4 -6
- package/lib/logic/validateIntent.js.map +1 -1
- package/lib/network/explorer/index.d.ts +1 -1
- package/lib/network/explorer/index.d.ts.map +1 -1
- package/lib/network/explorer/index.js +2 -2
- package/lib/network/explorer/index.js.map +1 -1
- package/lib/network/explorer/ledger.js +3 -3
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js +11 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts +1 -2
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js +3 -5
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/gasTracker/types.d.ts +1 -2
- package/lib/network/gasTracker/types.d.ts.map +1 -1
- package/lib/network/gasTracker/types.js.map +1 -1
- package/lib/network/node/explorerProxy.d.ts.map +1 -1
- package/lib/network/node/explorerProxy.js +10 -5
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.js +10 -12
- package/lib/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib/network/node/index.js +1 -1
- package/lib/network/node/index.js.map +1 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +11 -7
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +60 -70
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +6 -7
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js +0 -27
- package/lib/network/node/types.js.map +1 -1
- package/lib/nodeSources.d.ts.map +1 -1
- package/lib/nodeSources.js +11 -3
- package/lib/nodeSources.js.map +1 -1
- package/lib/staking/contracts.d.ts.map +1 -1
- package/lib/staking/contracts.js +1 -3
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/detectOperationType.d.ts +0 -3
- package/lib/staking/detectOperationType.d.ts.map +1 -1
- package/lib/staking/detectOperationType.js +15 -14
- package/lib/staking/detectOperationType.js.map +1 -1
- package/lib/staking/fetchers.d.ts.map +1 -1
- package/lib/staking/fetchers.js +2 -3
- package/lib/staking/fetchers.js.map +1 -1
- package/lib/staking/operations/index.d.ts.map +1 -1
- package/lib/staking/operations/index.js +18 -1
- package/lib/staking/operations/index.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +4 -7
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/unbondings.d.ts.map +1 -1
- package/lib/staking/unbondings.js +3 -4
- package/lib/staking/unbondings.js.map +1 -1
- package/lib/staking/utils.d.ts.map +1 -1
- package/lib/staking/utils.js +22 -27
- package/lib/staking/utils.js.map +1 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +16 -8
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js +4 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.js +5 -5
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.js +5 -5
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/abis/index.d.ts +8 -0
- package/lib-es/abis/index.d.ts.map +1 -1
- package/lib-es/abis/index.js +29 -0
- package/lib-es/abis/index.js.map +1 -1
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/internalTxSources.d.ts.map +1 -1
- package/lib-es/internalTxSources.js +21 -3
- package/lib-es/internalTxSources.js.map +1 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +11 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +4 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +4 -2
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.js +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +2 -2
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/listOperations.js +1 -1
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/predicates.d.ts +17 -0
- package/lib-es/logic/predicates.d.ts.map +1 -0
- package/lib-es/logic/predicates.js +114 -0
- package/lib-es/logic/predicates.js.map +1 -0
- package/lib-es/logic/validateIntent.d.ts.map +1 -1
- package/lib-es/logic/validateIntent.js +4 -6
- package/lib-es/logic/validateIntent.js.map +1 -1
- package/lib-es/network/explorer/index.d.ts +1 -1
- package/lib-es/network/explorer/index.d.ts.map +1 -1
- package/lib-es/network/explorer/index.js +2 -2
- package/lib-es/network/explorer/index.js.map +1 -1
- package/lib-es/network/explorer/ledger.js +3 -3
- package/lib-es/network/explorer/ledger.js.map +1 -1
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js +11 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts +1 -2
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +3 -5
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/gasTracker/types.d.ts +1 -2
- package/lib-es/network/gasTracker/types.d.ts.map +1 -1
- package/lib-es/network/gasTracker/types.js.map +1 -1
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
- package/lib-es/network/node/explorerProxy.js +10 -5
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js +4 -6
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib-es/network/node/index.js +1 -1
- package/lib-es/network/node/index.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +11 -7
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +58 -68
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +6 -7
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js +0 -25
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/nodeSources.d.ts.map +1 -1
- package/lib-es/nodeSources.js +11 -3
- package/lib-es/nodeSources.js.map +1 -1
- package/lib-es/staking/contracts.d.ts.map +1 -1
- package/lib-es/staking/contracts.js +1 -3
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/detectOperationType.d.ts +0 -3
- package/lib-es/staking/detectOperationType.d.ts.map +1 -1
- package/lib-es/staking/detectOperationType.js +15 -14
- package/lib-es/staking/detectOperationType.js.map +1 -1
- package/lib-es/staking/fetchers.d.ts.map +1 -1
- package/lib-es/staking/fetchers.js +2 -3
- package/lib-es/staking/fetchers.js.map +1 -1
- package/lib-es/staking/operations/index.d.ts.map +1 -1
- package/lib-es/staking/operations/index.js +18 -1
- package/lib-es/staking/operations/index.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +2 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +1 -4
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/unbondings.d.ts.map +1 -1
- package/lib-es/staking/unbondings.js +3 -4
- package/lib-es/staking/unbondings.js.map +1 -1
- package/lib-es/staking/utils.d.ts.map +1 -1
- package/lib-es/staking/utils.js +20 -25
- package/lib-es/staking/utils.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +13 -5
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +2 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.js +3 -3
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +3 -3
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/package.json +2 -2
- package/src/abis/index.test.ts +36 -0
- package/src/abis/index.ts +30 -0
- package/src/adapters/blockOperations.ts +1 -1
- package/src/api/index.cronos.integ.test.ts +28 -0
- package/src/api/index.integ.test.ts +57 -94
- package/src/api/index.ts +3 -2
- package/src/internalTxSources.ts +20 -3
- package/src/logic/common.ts +13 -3
- package/src/logic/craftTransaction.ts +4 -2
- package/src/logic/estimateFees.ts +4 -3
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/internalTransactionsFetcher.ts +2 -2
- package/src/logic/listOperations.ts +1 -1
- package/src/logic/predicates.ts +124 -0
- package/src/logic/tests/craftTransaction.test.ts +1 -1
- package/src/logic/tests/getStakes.test.ts +1 -0
- package/src/logic/tests/validateIntent.test.ts +4 -1
- package/src/logic/validateIntent.ts +2 -6
- package/src/network/explorer/index.test.ts +9 -16
- package/src/network/explorer/index.ts +2 -2
- package/src/network/explorer/ledger.test.ts +21 -15
- package/src/network/explorer/ledger.ts +3 -3
- package/src/network/explorer/types.ts +12 -3
- package/src/network/gasTracker/ledger.test.ts +0 -10
- package/src/network/gasTracker/ledger.ts +2 -7
- package/src/network/gasTracker/types.ts +0 -2
- package/src/network/node/explorerProxy.ts +11 -8
- package/src/network/node/gethCallTracerToTraceBlockItems.test.ts +1 -1
- package/src/network/node/gethCallTracerToTraceBlockItems.ts +6 -9
- package/src/network/node/index.ts +1 -1
- package/src/network/node/ledger.ts +15 -12
- package/src/network/node/rpc.common.ts +92 -88
- package/src/network/node/rpc.test.ts +119 -0
- package/src/network/node/types.ts +6 -35
- package/src/nodeSources.ts +11 -3
- package/src/staking/contracts.ts +1 -3
- package/src/staking/detectOperationType.ts +15 -14
- package/src/staking/fetchers.ts +2 -3
- package/src/staking/operations/index.test.ts +1 -0
- package/src/staking/operations/index.ts +26 -7
- package/src/staking/prepareIntents.ts +2 -1
- package/src/staking/redelegations.ts +1 -5
- package/src/staking/unbondings.ts +2 -4
- package/src/staking/utils.ts +19 -26
- package/src/staking/validators/monad.test.ts +6 -4
- package/src/staking/validators/monad.ts +12 -5
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.test.ts +1 -0
- package/src/staking/validators/somnia.ts +5 -5
- package/src/staking/validators/zero_gravity.test.ts +1 -0
- package/src/staking/validators/zero_gravity.ts +3 -3
- package/lib/logic/evmUnit.d.ts +0 -3
- package/lib/logic/evmUnit.d.ts.map +0 -1
- package/lib/logic/evmUnit.js +0 -94
- package/lib/logic/evmUnit.js.map +0 -1
- package/lib-es/logic/evmUnit.d.ts +0 -3
- package/lib-es/logic/evmUnit.d.ts.map +0 -1
- package/lib-es/logic/evmUnit.js +0 -91
- package/lib-es/logic/evmUnit.js.map +0 -1
- package/src/logic/evmUnit.ts +0 -93
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
LogWithAddress,
|
|
6
|
+
TraceBlockCallAction,
|
|
7
|
+
TraceBlockItem,
|
|
8
|
+
TransactionReceipt,
|
|
9
|
+
} from '../network/node/types'
|
|
10
|
+
import type { FeesStrategy } from '@ledgerhq/coin-module-framework/api/index'
|
|
11
|
+
|
|
12
|
+
/** Plain object. Arrays are objects in JavaScript, so they are rejected here. */
|
|
13
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
14
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isString(value: unknown): value is string {
|
|
18
|
+
return typeof value === 'string'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isBigInt(value: unknown): value is bigint {
|
|
22
|
+
return typeof value === 'bigint'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isOptionalString(value: unknown): value is string | null | undefined {
|
|
26
|
+
return value === undefined || value === null || isString(value)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A quantity already decoded by ethers (`bigint`) or still carried as a string. */
|
|
30
|
+
export function isQuantity(value: unknown): value is bigint | string {
|
|
31
|
+
return isBigInt(value) || isString(value)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** {@link isQuantity}, or JSON null / a missing field. */
|
|
35
|
+
export function isOptionalQuantity(value: unknown): value is bigint | string | null | undefined {
|
|
36
|
+
return isOptionalString(value) || isBigInt(value)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Hex or decimal integer string that `BigInt` accepts. Rejects leading-zero decimals such as `"01"`. */
|
|
40
|
+
function isBigIntString(value: unknown): value is string {
|
|
41
|
+
if (!isString(value) || !/^(?:0x[0-9a-fA-F]+|[0-9]+)$/.test(value)) return false
|
|
42
|
+
try {
|
|
43
|
+
BigInt(value)
|
|
44
|
+
return true
|
|
45
|
+
} catch {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isOptionalBigIntString(value: unknown): value is string | null | undefined {
|
|
51
|
+
return value === undefined || value === null || isBigIntString(value)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Value `Number` can convert without producing `NaN` or dropping low bits.
|
|
56
|
+
* Accepts a safe integer, or a hex/decimal string equal to that integer.
|
|
57
|
+
*/
|
|
58
|
+
function isNonNegativeSafeInteger(value: unknown): value is string | number {
|
|
59
|
+
if (typeof value === 'number') return Number.isSafeInteger(value) && value >= 0
|
|
60
|
+
if (!isBigIntString(value)) return false
|
|
61
|
+
const parsed = Number(value)
|
|
62
|
+
return Number.isSafeInteger(parsed) && parsed >= 0 && BigInt(parsed) === BigInt(value)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isReceiptStatus(value: unknown): value is TransactionReceipt['status'] {
|
|
66
|
+
return value === null || isNonNegativeSafeInteger(value)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isReceiptType(value: unknown): value is TransactionReceipt['type'] {
|
|
70
|
+
if (value === undefined || value === null) return true
|
|
71
|
+
return isString(value) && isNonNegativeSafeInteger(value)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isLogWithAddress(value: unknown): value is LogWithAddress {
|
|
75
|
+
if (!isRecord(value)) return false
|
|
76
|
+
if (!isString(value.address)) return false
|
|
77
|
+
// `0x` is valid empty log data. Any longer value is passed to `BigInt` for ERC20 amounts.
|
|
78
|
+
if (!isString(value.data) || !/^0x[0-9a-fA-F]*$/.test(value.data)) return false
|
|
79
|
+
return Array.isArray(value.topics) && value.topics.every(isString)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function isTransactionReceipt(value: unknown): value is TransactionReceipt {
|
|
83
|
+
if (!isRecord(value)) return false
|
|
84
|
+
if (!isString(value.transactionHash)) return false
|
|
85
|
+
if (!isBigIntString(value.gasUsed)) return false
|
|
86
|
+
if (!isOptionalBigIntString(value.effectiveGasPrice)) return false
|
|
87
|
+
if (!isOptionalBigIntString(value.gasPrice)) return false
|
|
88
|
+
if (!isReceiptStatus(value.status)) return false
|
|
89
|
+
if (!isReceiptType(value.type)) return false
|
|
90
|
+
// Non-standard OP-stack field. Only a string is later passed to `BigInt`.
|
|
91
|
+
if (isString(value.l1Fee) && !isBigIntString(value.l1Fee)) return false
|
|
92
|
+
return Array.isArray(value.logs) && value.logs.every(isLogWithAddress)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function isTraceBlockCallAction(action: unknown): action is TraceBlockCallAction {
|
|
96
|
+
if (!isRecord(action)) return false
|
|
97
|
+
return (
|
|
98
|
+
isString(action.from) &&
|
|
99
|
+
isString(action.to) &&
|
|
100
|
+
isString(action.callType) &&
|
|
101
|
+
isString(action.value)
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Type guard for {@link TraceBlockItem} (Erigon `trace_block` and Geth adapter output). */
|
|
106
|
+
export function isTraceBlockItem(value: unknown): value is TraceBlockItem {
|
|
107
|
+
if (!isRecord(value) || !isRecord(value.action)) return false
|
|
108
|
+
if (value.error !== undefined && !isString(value.error)) return false
|
|
109
|
+
|
|
110
|
+
const result = value.result
|
|
111
|
+
const resultOk =
|
|
112
|
+
result === undefined ||
|
|
113
|
+
result === null ||
|
|
114
|
+
(isRecord(result) && (result.error === undefined || isString(result.error)))
|
|
115
|
+
const validCall = isString(value.transactionHash) && resultOk
|
|
116
|
+
|
|
117
|
+
return !isTraceBlockCallAction(value.action) || validCall
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const FEES_STRATEGIES = new Set<string>(['slow', 'medium', 'fast', 'custom'])
|
|
121
|
+
|
|
122
|
+
export function isFeesStrategy(value: unknown): value is FeesStrategy {
|
|
123
|
+
return isString(value) && FEES_STRATEGIES.has(value)
|
|
124
|
+
}
|
|
@@ -493,8 +493,8 @@ describe('craftTransaction', () => {
|
|
|
493
493
|
const context = createMockEvmContext({ node: mkExternalNode() })
|
|
494
494
|
|
|
495
495
|
await expect(
|
|
496
|
-
// @ts-ignore — intentionally bare staking intent to test unsupported-currency error path
|
|
497
496
|
craftTransaction(context, 'unsupported_network', {
|
|
497
|
+
// @ts-expect-error bare staking intent
|
|
498
498
|
transactionIntent: { type: 'staking', mode: 'delegate' },
|
|
499
499
|
})
|
|
500
500
|
).rejects.toThrow(
|
|
@@ -37,6 +37,7 @@ const externalNodeConfig = { type: 'external' as const, uri: 'https://test' }
|
|
|
37
37
|
const context = createMockEvmContext({
|
|
38
38
|
node: externalNodeConfig,
|
|
39
39
|
name: 'Celo',
|
|
40
|
+
unit: { name: 'CELO', code: 'CELO', magnitude: 18 },
|
|
40
41
|
})
|
|
41
42
|
const makeValidator = (validatorAddress: string) => ({
|
|
42
43
|
id: validatorAddress,
|
|
@@ -384,7 +384,10 @@ describe('validateIntent', () => {
|
|
|
384
384
|
eip1559Intent({
|
|
385
385
|
recipient: '0xe2ca7390e76c5A992749bB622087310d2e63ca29',
|
|
386
386
|
amount: 0n,
|
|
387
|
-
asset: {
|
|
387
|
+
asset: {
|
|
388
|
+
type: 'erc20',
|
|
389
|
+
assetReference: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
390
|
+
},
|
|
388
391
|
}),
|
|
389
392
|
[{ value: 50n, asset: { type: 'native' } }]
|
|
390
393
|
)
|
|
@@ -56,7 +56,6 @@ import {
|
|
|
56
56
|
DEFAULT_CALLDATA_FLOOR_ZERO_BYTE_TOKENS,
|
|
57
57
|
} from './computeGasLimit'
|
|
58
58
|
import estimateFees from './estimateFees'
|
|
59
|
-
import { evmUnit } from './evmUnit'
|
|
60
59
|
|
|
61
60
|
function assetsAreEqual(asset1: AssetInfo, asset2: AssetInfo): boolean {
|
|
62
61
|
if (asset1.type === 'native' && asset2.type === 'native') return true
|
|
@@ -188,7 +187,6 @@ function validateRecipient(
|
|
|
188
187
|
*/
|
|
189
188
|
async function validateGas(
|
|
190
189
|
config: EvmConfigInfo,
|
|
191
|
-
currencyId: string,
|
|
192
190
|
intent: TransactionIntent<MemoNotSupported, BufferTxData>,
|
|
193
191
|
balances: Balance[],
|
|
194
192
|
estimatedFees: FeeEstimation
|
|
@@ -256,8 +254,8 @@ async function validateGas(
|
|
|
256
254
|
) {
|
|
257
255
|
errors.gasPrice = new NotEnoughGas(undefined, {
|
|
258
256
|
// "You need {{fees}} {{ticker}} for network fees to swap as you are on {{cryptoName}} network. <link0>Buy {{ticker}}</link0>"
|
|
259
|
-
fees: formatCurrencyUnit(
|
|
260
|
-
ticker:
|
|
257
|
+
fees: formatCurrencyUnit(config.unit, new BigNumber(totalFees.toString())),
|
|
258
|
+
ticker: config.unit.code,
|
|
261
259
|
cryptoName: config.name,
|
|
262
260
|
links: ['ledgerlive://buy'],
|
|
263
261
|
})
|
|
@@ -300,7 +298,6 @@ async function validateGas(
|
|
|
300
298
|
|
|
301
299
|
const gasTracker = getGasTracker(config)
|
|
302
300
|
const gasOptions = await gasTracker?.getGasOptions({
|
|
303
|
-
currencyId,
|
|
304
301
|
config,
|
|
305
302
|
options: { useEIP1559: true },
|
|
306
303
|
})
|
|
@@ -492,7 +489,6 @@ export async function validateIntent(
|
|
|
492
489
|
)
|
|
493
490
|
const { errors: gasErr, warnings: gasWarn } = await validateGas(
|
|
494
491
|
config,
|
|
495
|
-
currencyId,
|
|
496
492
|
intent,
|
|
497
493
|
balances,
|
|
498
494
|
estimatedFees
|
|
@@ -23,7 +23,6 @@ const configFor = (currencyId: string): EvmConfigInfo => {
|
|
|
23
23
|
return createMockEvmConfigInfo({
|
|
24
24
|
chainId: 1,
|
|
25
25
|
node,
|
|
26
|
-
// @ts-expect-error — intentional invalid explorer type to test UnknownExplorer error path
|
|
27
26
|
explorer: { type: 'anything', uri: 'notworking' },
|
|
28
27
|
})
|
|
29
28
|
case 'etherscan-coin':
|
|
@@ -68,7 +67,7 @@ describe('EVM Family', () => {
|
|
|
68
67
|
describe('getExplorerApi', () => {
|
|
69
68
|
it('should throw when requesting a non existing explorer', () => {
|
|
70
69
|
try {
|
|
71
|
-
getExplorerApi(configFor('anything-coin')
|
|
70
|
+
getExplorerApi(configFor('anything-coin'))
|
|
72
71
|
fail('Promise should have been rejected')
|
|
73
72
|
} catch (e) {
|
|
74
73
|
if (e instanceof AssertionError) {
|
|
@@ -79,35 +78,29 @@ describe('EVM Family', () => {
|
|
|
79
78
|
})
|
|
80
79
|
|
|
81
80
|
it('should return the etherscan api', () => {
|
|
82
|
-
const explorerA = getExplorerApi(configFor('etherscan-coin')
|
|
83
|
-
const explorerB = getExplorerApi(configFor('blockscout-coin')
|
|
81
|
+
const explorerA = getExplorerApi(configFor('etherscan-coin'))
|
|
82
|
+
const explorerB = getExplorerApi(configFor('blockscout-coin'))
|
|
84
83
|
|
|
85
84
|
expect(explorerA).toBe(etherscanLikeApi.explorerApi)
|
|
86
85
|
expect(explorerB).toBe(etherscanLikeApi.explorerApi)
|
|
87
86
|
})
|
|
88
87
|
|
|
89
88
|
it('should return the no cache etherscan api', () => {
|
|
90
|
-
const explorerA = getExplorerApi(
|
|
91
|
-
|
|
92
|
-
'etherscan-coin-no-cache'
|
|
93
|
-
)
|
|
94
|
-
const explorerB = getExplorerApi(
|
|
95
|
-
configFor('blockscout-coin-no-cache'),
|
|
96
|
-
'blockscout-coin-no-cache'
|
|
97
|
-
)
|
|
89
|
+
const explorerA = getExplorerApi(configFor('etherscan-coin-no-cache'))
|
|
90
|
+
const explorerB = getExplorerApi(configFor('blockscout-coin-no-cache'))
|
|
98
91
|
|
|
99
92
|
expect(explorerA).toBe(etherscanLikeApi.explorerApiNoCache)
|
|
100
93
|
expect(explorerB).toBe(etherscanLikeApi.explorerApiNoCache)
|
|
101
94
|
})
|
|
102
95
|
|
|
103
96
|
it('should return the ledger api', () => {
|
|
104
|
-
const explorerA = getExplorerApi(configFor('ledger-coin')
|
|
97
|
+
const explorerA = getExplorerApi(configFor('ledger-coin'))
|
|
105
98
|
|
|
106
99
|
expect(explorerA).toBe(ledgerExplorerApi)
|
|
107
100
|
})
|
|
108
101
|
|
|
109
102
|
it('should return the none api', () => {
|
|
110
|
-
const explorerA = getExplorerApi(configFor('none-coin')
|
|
103
|
+
const explorerA = getExplorerApi(configFor('none-coin'))
|
|
111
104
|
|
|
112
105
|
expect(explorerA).toBe(noExplorerAPI)
|
|
113
106
|
})
|
|
@@ -117,13 +110,13 @@ describe('EVM Family', () => {
|
|
|
117
110
|
['ledger', 'ledger-coin'],
|
|
118
111
|
['none', 'none-coin'],
|
|
119
112
|
])('%s arm exposes discoverTokenAssets', (_type, currencyId) => {
|
|
120
|
-
const explorer = getExplorerApi(configFor(currencyId)
|
|
113
|
+
const explorer = getExplorerApi(configFor(currencyId))
|
|
121
114
|
|
|
122
115
|
expect(typeof explorer.discoverTokenAssets).toBe('function')
|
|
123
116
|
})
|
|
124
117
|
|
|
125
118
|
it('the none arm resolves discoverTokenAssets to an empty array', async () => {
|
|
126
|
-
const explorer = getExplorerApi(configFor('none-coin')
|
|
119
|
+
const explorer = getExplorerApi(configFor('none-coin'))
|
|
127
120
|
|
|
128
121
|
await expect(
|
|
129
122
|
explorer.discoverTokenAssets(configFor('none-coin'), testLogger, 'none-coin', '0xaddress')
|
|
@@ -11,7 +11,7 @@ import noExplorerAPI from './none'
|
|
|
11
11
|
/**
|
|
12
12
|
* Switch to select one of the compatible explorer
|
|
13
13
|
*/
|
|
14
|
-
export const getExplorerApi = (config: EvmConfigInfo
|
|
14
|
+
export const getExplorerApi = (config: EvmConfigInfo): ExplorerApi => {
|
|
15
15
|
switch (config?.explorer?.type) {
|
|
16
16
|
case 'etherscan':
|
|
17
17
|
case 'blockscout':
|
|
@@ -28,6 +28,6 @@ export const getExplorerApi = (config: EvmConfigInfo, currencyId: string): Explo
|
|
|
28
28
|
return noExplorerAPI
|
|
29
29
|
|
|
30
30
|
default:
|
|
31
|
-
throw new UnknownExplorer(`Unknown explorer for currency: ${
|
|
31
|
+
throw new UnknownExplorer(`Unknown explorer for currency: ${config.name}`)
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -168,7 +168,7 @@ describe('EVM Family', () => {
|
|
|
168
168
|
})
|
|
169
169
|
|
|
170
170
|
it('should recursively fetch paginated data', async () => {
|
|
171
|
-
jest.spyOn(axios, 'request').mockImplementation(async ({ params }) => {
|
|
171
|
+
jest.spyOn(axios, 'request').mockImplementation(async ({ params }: AxiosRequestConfig) => {
|
|
172
172
|
switch (params.token) {
|
|
173
173
|
case 'abc':
|
|
174
174
|
return {
|
|
@@ -1453,11 +1453,13 @@ describe('EVM Family', () => {
|
|
|
1453
1453
|
})
|
|
1454
1454
|
|
|
1455
1455
|
it('issues exactly one request per page and stops on a falsy token', async () => {
|
|
1456
|
-
const request = jest
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1456
|
+
const request = jest
|
|
1457
|
+
.spyOn(axios, 'request')
|
|
1458
|
+
.mockImplementation(async ({ params }: AxiosRequestConfig) => {
|
|
1459
|
+
if (params.token === null) return { data: { data: [discoveryRecord([])], token: 'p2' } }
|
|
1460
|
+
if (params.token === 'p2') return { data: { data: [discoveryRecord([])], token: '' } }
|
|
1461
|
+
throw new Error('should not be called again')
|
|
1462
|
+
})
|
|
1461
1463
|
|
|
1462
1464
|
await LEDGER_API.discoverTokenAssets(config, testLogger, 'ethereum', ADDR)
|
|
1463
1465
|
|
|
@@ -1465,10 +1467,12 @@ describe('EVM Family', () => {
|
|
|
1465
1467
|
})
|
|
1466
1468
|
|
|
1467
1469
|
it('stops when an empty page still carries a token', async () => {
|
|
1468
|
-
const request = jest
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1470
|
+
const request = jest
|
|
1471
|
+
.spyOn(axios, 'request')
|
|
1472
|
+
.mockImplementation(async ({ params }: AxiosRequestConfig) => {
|
|
1473
|
+
if (params.token === null) return { data: { data: [], token: 'p2' } }
|
|
1474
|
+
throw new Error('should not be called again')
|
|
1475
|
+
})
|
|
1472
1476
|
|
|
1473
1477
|
await LEDGER_API.discoverTokenAssets(config, testLogger, 'ethereum', ADDR)
|
|
1474
1478
|
|
|
@@ -1476,11 +1480,13 @@ describe('EVM Family', () => {
|
|
|
1476
1480
|
})
|
|
1477
1481
|
|
|
1478
1482
|
it('stops when the explorer returns the same token twice (cycling cursor guard)', async () => {
|
|
1479
|
-
const request = jest
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1483
|
+
const request = jest
|
|
1484
|
+
.spyOn(axios, 'request')
|
|
1485
|
+
.mockImplementation(async ({ params }: AxiosRequestConfig) => {
|
|
1486
|
+
if (params.token === null) return { data: { data: [discoveryRecord([])], token: 'p2' } }
|
|
1487
|
+
if (params.token === 'p2') return { data: { data: [discoveryRecord([])], token: 'p2' } }
|
|
1488
|
+
throw new Error('should not be called again')
|
|
1489
|
+
})
|
|
1484
1490
|
|
|
1485
1491
|
await LEDGER_API.discoverTokenAssets(config, testLogger, 'ethereum', ADDR)
|
|
1486
1492
|
|
|
@@ -422,7 +422,7 @@ export const getOperations: ExplorerApi['getOperations'] = async (
|
|
|
422
422
|
const { explorer } = config || /* istanbul ignore next */ {}
|
|
423
423
|
if (!isLedgerExplorerConfig(explorer)) {
|
|
424
424
|
throw new LedgerExplorerUsedIncorrectly(
|
|
425
|
-
`Ledger explorer used incorrectly with currency: ${
|
|
425
|
+
`Ledger explorer used incorrectly with currency: ${config?.name ?? 'unknown'}`
|
|
426
426
|
)
|
|
427
427
|
}
|
|
428
428
|
|
|
@@ -481,14 +481,14 @@ export const getOperations: ExplorerApi['getOperations'] = async (
|
|
|
481
481
|
export const discoverTokenAssets: ExplorerApi['discoverTokenAssets'] = async (
|
|
482
482
|
config,
|
|
483
483
|
logger,
|
|
484
|
-
|
|
484
|
+
_currencyId,
|
|
485
485
|
address,
|
|
486
486
|
fromBlock
|
|
487
487
|
) => {
|
|
488
488
|
const { explorer } = config || /* istanbul ignore next */ {}
|
|
489
489
|
if (!isLedgerExplorerConfig(explorer)) {
|
|
490
490
|
throw new LedgerExplorerUsedIncorrectly(
|
|
491
|
-
`Ledger explorer used incorrectly with currency: ${
|
|
491
|
+
`Ledger explorer used incorrectly with currency: ${config?.name ?? 'unknown'}`
|
|
492
492
|
)
|
|
493
493
|
}
|
|
494
494
|
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
Operation,
|
|
9
9
|
} from '@ledgerhq/coin-module-framework/api/types'
|
|
10
10
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
11
|
+
import { isString } from '../../logic/predicates'
|
|
11
12
|
|
|
12
13
|
/** Constant representing no pagination token (end of pagination or first page) */
|
|
13
14
|
export const NO_TOKEN = ''
|
|
@@ -62,6 +63,15 @@ export const isLedgerExplorerConfig = (
|
|
|
62
63
|
return explorerConfig?.type === 'ledger'
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
const ETHERSCAN_LIKE_EXPLORER_TYPES = new Set<string>([
|
|
67
|
+
'etherscan',
|
|
68
|
+
'blockscout',
|
|
69
|
+
'teloscan',
|
|
70
|
+
'klaytnfinder',
|
|
71
|
+
'corescan',
|
|
72
|
+
'cronos',
|
|
73
|
+
])
|
|
74
|
+
|
|
65
75
|
/**
|
|
66
76
|
* Type guard
|
|
67
77
|
*/
|
|
@@ -70,7 +80,6 @@ export const isEtherscanLikeExplorerConfig = (
|
|
|
70
80
|
): explorerConfig is ExplorerConfig & {
|
|
71
81
|
type: 'etherscan' | 'blockscout' | 'teloscan' | 'klaytnfinder' | 'corescan' | 'cronos'
|
|
72
82
|
} => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
83
|
+
const explorerType = explorerConfig?.type
|
|
84
|
+
return isString(explorerType) && ETHERSCAN_LIKE_EXPLORER_TYPES.has(explorerType)
|
|
76
85
|
}
|
|
@@ -42,7 +42,6 @@ describe('EVM Family', () => {
|
|
|
42
42
|
describe('EIP-1559 gas options', () => {
|
|
43
43
|
it('should return EIP-1559 gas options', async () => {
|
|
44
44
|
const gasOptions: GasOptions = await getGasOptions({
|
|
45
|
-
currencyId: 'ethereum',
|
|
46
45
|
config: ledgerGasTrackerConfig,
|
|
47
46
|
options: {
|
|
48
47
|
useEIP1559: true,
|
|
@@ -81,7 +80,6 @@ describe('EVM Family', () => {
|
|
|
81
80
|
)
|
|
82
81
|
|
|
83
82
|
const gasOptions: GasOptions = await getGasOptions({
|
|
84
|
-
currencyId: 'ethereum',
|
|
85
83
|
config: { ...ledgerGasTrackerConfig, eip1559BaseFeeMultiplier: 1.5 },
|
|
86
84
|
options: {
|
|
87
85
|
useEIP1559: true,
|
|
@@ -103,7 +101,6 @@ describe('EVM Family', () => {
|
|
|
103
101
|
)
|
|
104
102
|
|
|
105
103
|
const gasOptions: GasOptions = await getGasOptions({
|
|
106
|
-
currencyId: 'ethereum',
|
|
107
104
|
config: ledgerGasTrackerConfig,
|
|
108
105
|
options: {
|
|
109
106
|
useEIP1559: true,
|
|
@@ -121,7 +118,6 @@ describe('EVM Family', () => {
|
|
|
121
118
|
|
|
122
119
|
it('should use overrideGasTracker', async () => {
|
|
123
120
|
await getGasOptions({
|
|
124
|
-
currencyId: 'ethereum',
|
|
125
121
|
config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
126
122
|
options: {
|
|
127
123
|
useEIP1559: true,
|
|
@@ -139,7 +135,6 @@ describe('EVM Family', () => {
|
|
|
139
135
|
describe('legacy gas options', () => {
|
|
140
136
|
it('should return legacy gas options', async () => {
|
|
141
137
|
const gasOptions: GasOptions = await getGasOptions({
|
|
142
|
-
currencyId: 'ethereum',
|
|
143
138
|
config: ledgerGasTrackerConfig,
|
|
144
139
|
options: {
|
|
145
140
|
useEIP1559: false,
|
|
@@ -172,7 +167,6 @@ describe('EVM Family', () => {
|
|
|
172
167
|
|
|
173
168
|
it('should return legacy gas options when EIP-1559 not supported by gas tracker', async () => {
|
|
174
169
|
const gasOptions: GasOptions = await getGasOptions({
|
|
175
|
-
currencyId: 'ethereum_classic',
|
|
176
170
|
config: createMockEvmConfigInfo({
|
|
177
171
|
chainId: 1,
|
|
178
172
|
node: mkExternalNode(),
|
|
@@ -213,7 +207,6 @@ describe('EVM Family', () => {
|
|
|
213
207
|
)
|
|
214
208
|
|
|
215
209
|
const gasOptions: GasOptions = await getGasOptions({
|
|
216
|
-
currencyId: 'ethereum',
|
|
217
210
|
config: ledgerGasTrackerConfig,
|
|
218
211
|
options: {
|
|
219
212
|
useEIP1559: false,
|
|
@@ -229,7 +222,6 @@ describe('EVM Family', () => {
|
|
|
229
222
|
|
|
230
223
|
it('should use overrideGasTracker', async () => {
|
|
231
224
|
await getGasOptions({
|
|
232
|
-
currencyId: 'ethereum',
|
|
233
225
|
config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
234
226
|
options: {
|
|
235
227
|
useEIP1559: false,
|
|
@@ -247,7 +239,6 @@ describe('EVM Family', () => {
|
|
|
247
239
|
it("should throw if the gas tracker type isn't ledger", async () => {
|
|
248
240
|
try {
|
|
249
241
|
await getGasOptions({
|
|
250
|
-
currencyId: 'ethereum',
|
|
251
242
|
config: createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() }),
|
|
252
243
|
})
|
|
253
244
|
fail('Promise should have been rejected')
|
|
@@ -262,7 +253,6 @@ describe('EVM Family', () => {
|
|
|
262
253
|
it("should throw if the gas tracker explorerId doesn't exist", async () => {
|
|
263
254
|
try {
|
|
264
255
|
await getGasOptions({
|
|
265
|
-
currencyId: 'ethereum',
|
|
266
256
|
config: createMockEvmConfigInfo({
|
|
267
257
|
chainId: 1,
|
|
268
258
|
node: mkExternalNode(),
|
|
@@ -32,21 +32,16 @@ const explorerIdGasTrackerMap = new Map<string, GasTracker>([
|
|
|
32
32
|
])
|
|
33
33
|
|
|
34
34
|
export const getGasOptions = async ({
|
|
35
|
-
currencyId,
|
|
36
35
|
config,
|
|
37
36
|
options,
|
|
38
37
|
}: {
|
|
39
|
-
currencyId: string
|
|
40
38
|
config: EvmConfigInfo
|
|
41
39
|
options?: {
|
|
42
40
|
useEIP1559: boolean
|
|
43
41
|
overrideGasTracker?: EvmConfigInfo['gasTracker']
|
|
44
42
|
}
|
|
45
43
|
}): Promise<GasOptions> => {
|
|
46
|
-
const gasTracker =
|
|
47
|
-
options?.overrideGasTracker ||
|
|
48
|
-
config.gasTracker ||
|
|
49
|
-
/* istanbul ignore next */ ({} as EvmConfigInfo['gasTracker'])
|
|
44
|
+
const gasTracker = options?.overrideGasTracker ?? config.gasTracker
|
|
50
45
|
|
|
51
46
|
if (!isLedgerGasTracker(gasTracker)) {
|
|
52
47
|
throw new LedgerGasTrackerUsedIncorrectly()
|
|
@@ -54,7 +49,7 @@ export const getGasOptions = async ({
|
|
|
54
49
|
|
|
55
50
|
const gasTrackerConfig = explorerIdGasTrackerMap.get(gasTracker.explorerId)
|
|
56
51
|
if (!gasTrackerConfig) {
|
|
57
|
-
throw new NoGasTrackerFound(`No gas tracker found for ${
|
|
52
|
+
throw new NoGasTrackerFound(`No gas tracker found for ${config.name}`)
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
// We use the eip1559 display parameter only if requested AND the currency supports it
|
|
@@ -5,6 +5,7 @@ import type { BlockByHeightResult, NodeApi, TransactionInfo } from './types'
|
|
|
5
5
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
6
6
|
import axios from 'axios'
|
|
7
7
|
import { isSmartContractInput, safeEncodeEIP55 } from '../../logic-public'
|
|
8
|
+
import { isRecord } from '../../logic/predicates'
|
|
8
9
|
import { ETHERSCAN_TIMEOUT } from '../explorer/etherscan'
|
|
9
10
|
import { withRetries } from '../withRetries'
|
|
10
11
|
import { parseERC20TransfersFromLogs } from './rpc.common'
|
|
@@ -89,8 +90,8 @@ export async function getBlockFromExplorerProxy(
|
|
|
89
90
|
explorerUri,
|
|
90
91
|
{ action: 'eth_getBlockByNumber', tag: hexHeight, boolean: 'false' },
|
|
91
92
|
(result) => {
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
if (!isRecord(result)) return null
|
|
94
|
+
const block = result
|
|
94
95
|
|
|
95
96
|
const hash = block.hash
|
|
96
97
|
if (typeof hash !== 'string' || !hash || /^0x0+$/.test(hash)) return null
|
|
@@ -142,8 +143,9 @@ export async function getTransactionFromExplorerProxy(
|
|
|
142
143
|
explorerUri,
|
|
143
144
|
{ action: 'eth_getTransactionByHash', txhash: hash },
|
|
144
145
|
(r) => {
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
if (!isRecord(r)) return null
|
|
147
|
+
const t = r
|
|
148
|
+
if (typeof t.hash !== 'string') return null
|
|
147
149
|
if (t.hash.toLowerCase() !== hash.toLowerCase()) return null
|
|
148
150
|
return t
|
|
149
151
|
},
|
|
@@ -154,8 +156,9 @@ export async function getTransactionFromExplorerProxy(
|
|
|
154
156
|
explorerUri,
|
|
155
157
|
{ action: 'eth_getTransactionReceipt', txhash: hash },
|
|
156
158
|
(r) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
if (!isRecord(r)) return null
|
|
160
|
+
const rec = r
|
|
161
|
+
if (typeof rec.transactionHash !== 'string') return null
|
|
159
162
|
if (rec.transactionHash.toLowerCase() !== hash.toLowerCase()) return null
|
|
160
163
|
return rec
|
|
161
164
|
},
|
|
@@ -196,8 +199,8 @@ export async function getTransactionFromExplorerProxy(
|
|
|
196
199
|
if (!Array.isArray(receipt.logs)) return null
|
|
197
200
|
const logs: { address: string; topics: string[]; data: string }[] = []
|
|
198
201
|
for (const l of receipt.logs) {
|
|
199
|
-
if (!l
|
|
200
|
-
const entry = l
|
|
202
|
+
if (!isRecord(l)) return null
|
|
203
|
+
const entry = l
|
|
201
204
|
if (typeof entry.address !== 'string') return null
|
|
202
205
|
if (typeof entry.data !== 'string') return null
|
|
203
206
|
if (
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TraceBlockItem } from './types'
|
|
5
|
+
import { isTraceBlockItem } from '../../logic/predicates'
|
|
5
6
|
import { gethCallTracerToTraceBlockItems } from './gethCallTracerToTraceBlockItems'
|
|
6
7
|
import flareBlock0x36ffc39CallTracerTrace from './resources/flare-0x36ffc39-debug-trace-block-call-tracer.json'
|
|
7
|
-
import { isTraceBlockItem } from './types'
|
|
8
8
|
|
|
9
9
|
describe('gethCallTracerToTraceBlockItems', () => {
|
|
10
10
|
const blockNumber = 12345
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import type { TraceBlockItem, TraceBlockOtherAction, TraceBlockResult } from './types'
|
|
5
|
+
import { isRecord, isString } from '../../logic/predicates'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Geth `debug_traceBlockByNumber` with `callTracer` returns one entry per transaction (same order as
|
|
@@ -39,10 +40,6 @@ export function gethCallTracerToTraceBlockItems(
|
|
|
39
40
|
.filter((item) => item !== null)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
function isString(value: unknown): value is string {
|
|
43
|
-
return typeof value === 'string'
|
|
44
|
-
}
|
|
45
|
-
|
|
46
43
|
function stringValue(value: unknown, orDefault: string): string {
|
|
47
44
|
if (isString(value)) return value
|
|
48
45
|
return orDefault
|
|
@@ -64,8 +61,8 @@ function parseDebugTraceBlockEntry(
|
|
|
64
61
|
entry: unknown,
|
|
65
62
|
index: number
|
|
66
63
|
): { txHash: string; root: Record<string, unknown> } | null {
|
|
67
|
-
if (
|
|
68
|
-
const o = entry
|
|
64
|
+
if (!isRecord(entry)) return null
|
|
65
|
+
const o = entry
|
|
69
66
|
const txHash = extractTxHash(o)
|
|
70
67
|
|
|
71
68
|
if (txHash !== null) {
|
|
@@ -80,13 +77,13 @@ function parseDebugTraceBlockEntry(
|
|
|
80
77
|
`debug_traceBlockByNumber entry at index ${index} (tx ${txHash}) has null or undefined "result"`
|
|
81
78
|
)
|
|
82
79
|
}
|
|
83
|
-
if (
|
|
80
|
+
if (!isRecord(inner)) {
|
|
84
81
|
throw new TypeError(
|
|
85
82
|
`debug_traceBlockByNumber entry at index ${index} (tx ${txHash}) has invalid "result" (expected object)`
|
|
86
83
|
)
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
return { txHash, root: inner
|
|
86
|
+
return { txHash, root: inner }
|
|
90
87
|
}
|
|
91
88
|
|
|
92
89
|
if ('type' in o || 'from' in o || 'calls' in o) {
|
|
@@ -121,7 +118,7 @@ function flattenCallFrame(
|
|
|
121
118
|
|
|
122
119
|
for (let i = 0; i < calls.length; i++) {
|
|
123
120
|
const child = calls[i]
|
|
124
|
-
if (child
|
|
121
|
+
if (isRecord(child)) {
|
|
125
122
|
items.push(
|
|
126
123
|
...flattenCallFrame(
|
|
127
124
|
child,
|