@ledgerhq/live-common 21.14.1 → 21.16.2
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/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +85 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js +2 -2
- package/lib/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.js +20 -10
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js +2 -2
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.js.map +1 -1
- package/lib/account/formatters.d.ts.map +1 -1
- package/lib/account/formatters.js +33 -1
- package/lib/account/formatters.js.map +1 -1
- package/lib/account/groupOperations.js +1 -1
- package/lib/account/groupOperations.js.map +1 -1
- package/lib/account/pending.d.ts +1 -0
- package/lib/account/pending.d.ts.map +1 -1
- package/lib/account/serialization.d.ts +6 -4
- package/lib/account/serialization.d.ts.map +1 -1
- package/lib/account/serialization.js +47 -9
- package/lib/account/serialization.js.map +1 -1
- package/lib/api/Ethereum.d.ts +22 -1
- package/lib/api/Ethereum.d.ts.map +1 -1
- package/lib/api/Ethereum.js +21 -1
- package/lib/api/Ethereum.js.map +1 -1
- package/lib/apps/polyfill.d.ts.map +1 -1
- package/lib/apps/polyfill.js +3 -0
- package/lib/apps/polyfill.js.map +1 -1
- package/lib/bridge/jsHelpers.d.ts +2 -1
- package/lib/bridge/jsHelpers.d.ts.map +1 -1
- package/lib/bridge/jsHelpers.js +27 -1
- package/lib/bridge/jsHelpers.js.map +1 -1
- package/lib/csvExport.d.ts.map +1 -1
- package/lib/csvExport.js +3 -1
- package/lib/csvExport.js.map +1 -1
- package/lib/currencies/sortByMarketcap.d.ts.map +1 -1
- package/lib/currencies/sortByMarketcap.js +8 -1
- package/lib/currencies/sortByMarketcap.js.map +1 -1
- package/lib/currencies/support.d.ts.map +1 -1
- package/lib/currencies/support.js.map +1 -1
- package/lib/env.d.ts +15 -5
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +11 -0
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.js +4 -0
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_cash.js +4 -0
- package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin_gold.js +4 -0
- package/lib/families/bitcoin/datasets/bitcoin_gold.js.map +1 -1
- package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/dash.js +4 -0
- package/lib/families/bitcoin/datasets/dash.js.map +1 -1
- package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/decred.js +4 -0
- package/lib/families/bitcoin/datasets/decred.js.map +1 -1
- package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/digibyte.js +4 -0
- package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/dogecoin.js +4 -0
- package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/komodo.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/komodo.js +4 -0
- package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.js +4 -0
- package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/peercoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/peercoin.js +4 -0
- package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/pivx.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/pivx.js +4 -0
- package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
- package/lib/families/bitcoin/datasets/qtum.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/qtum.js +4 -0
- package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
- package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/stakenet.js +4 -0
- package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/vertcoin.js +4 -0
- package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/viacoin.js +4 -0
- package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/zcash.js +4 -0
- package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
- package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/zencash.js +4 -0
- package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
- package/lib/families/bitcoin/js-buildTransaction.d.ts.map +1 -1
- package/lib/families/bitcoin/js-buildTransaction.js +1 -1
- package/lib/families/bitcoin/js-buildTransaction.js.map +1 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +1 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.js +1 -1
- package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js +26 -14
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/logic.d.ts +1 -1
- package/lib/families/bitcoin/logic.d.ts.map +1 -1
- package/lib/families/bitcoin/logic.js +6 -0
- package/lib/families/bitcoin/logic.js.map +1 -1
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +2 -1
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/test-dataset.js +2 -2
- package/lib/families/bitcoin/test-dataset.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js +16 -12
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js +12 -7
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js +12 -7
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/Merge.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts +2 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/pickingstrategies/types.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts +38 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.js +104 -32
- package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.js +6 -3
- package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/xpub.js +2 -2
- package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
- package/lib/families/ethereum/signOperation.d.ts.map +1 -1
- package/lib/families/ethereum/signOperation.js +7 -0
- package/lib/families/ethereum/signOperation.js.map +1 -1
- package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
- package/lib/families/ethereum/synchronisation.js +175 -15
- package/lib/families/ethereum/synchronisation.js.map +1 -1
- package/lib/families/ethereum/versions.d.ts +2 -0
- package/lib/families/ethereum/versions.d.ts.map +1 -0
- package/lib/families/ethereum/versions.js +5 -0
- package/lib/families/ethereum/versions.js.map +1 -0
- package/lib/nft/NftMetadataProvider/index.d.ts +17 -0
- package/lib/nft/NftMetadataProvider/index.d.ts.map +1 -0
- package/lib/nft/NftMetadataProvider/index.js +244 -0
- package/lib/nft/NftMetadataProvider/index.js.map +1 -0
- package/lib/nft/NftMetadataProvider/logic.d.ts +3 -0
- package/lib/nft/NftMetadataProvider/logic.d.ts.map +1 -0
- package/lib/nft/NftMetadataProvider/logic.js +22 -0
- package/lib/nft/NftMetadataProvider/logic.js.map +1 -0
- package/lib/nft/NftMetadataProvider/types.d.ts +44 -0
- package/lib/nft/NftMetadataProvider/types.d.ts.map +1 -0
- package/lib/nft/NftMetadataProvider/types.js +3 -0
- package/lib/nft/NftMetadataProvider/types.js.map +1 -0
- package/lib/nft/helpers.d.ts +10 -0
- package/lib/nft/helpers.d.ts.map +1 -0
- package/lib/nft/helpers.js +85 -0
- package/lib/nft/helpers.js.map +1 -0
- package/lib/nft/index.d.ts +4 -0
- package/lib/nft/index.d.ts.map +1 -0
- package/lib/nft/index.js +16 -0
- package/lib/nft/index.js.map +1 -0
- package/lib/nft/nftId.d.ts +3 -0
- package/lib/nft/nftId.d.ts.map +1 -0
- package/lib/nft/nftId.js +33 -0
- package/lib/nft/nftId.js.map +1 -0
- package/lib/operation.d.ts +1 -1
- package/lib/operation.d.ts.map +1 -1
- package/lib/operation.js +19 -5
- package/lib/operation.js.map +1 -1
- package/lib/reconciliation.d.ts.map +1 -1
- package/lib/reconciliation.js +6 -0
- package/lib/reconciliation.js.map +1 -1
- package/lib/types/account.d.ts +3 -0
- package/lib/types/account.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/nft.d.ts +29 -0
- package/lib/types/nft.d.ts.map +1 -0
- package/lib/types/nft.js +3 -0
- package/lib/types/nft.js.map +1 -0
- package/lib/types/operation.d.ts +12 -1
- package/lib/types/operation.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/.DS_Store +0 -0
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +11643 -127265
- package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +105 -0
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.estimateMaxSpendable.test.ts +3 -2
- package/src/__tests__/families/bitcoin/wallet-btc/wallet.integration.test.ts +2 -2
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.ts +35 -31
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.NP2WPKH.integration.test.ts +3 -2
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.P2WPKH.integration.test.ts +3 -2
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.integration.test.ts +6 -4
- package/src/account/formatters.ts +43 -0
- package/src/account/groupOperations.ts +2 -2
- package/src/account/serialization.ts +52 -0
- package/src/api/Ethereum.ts +40 -2
- package/src/apps/polyfill.ts +3 -0
- package/src/bridge/jsHelpers.ts +35 -0
- package/src/csvExport.ts +3 -2
- package/src/currencies/.DS_Store +0 -0
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +1354 -1
- package/src/currencies/sortByMarketcap.ts +9 -1
- package/src/currencies/support.ts +1 -0
- package/src/env.ts +11 -0
- package/src/families/bitcoin/datasets/bitcoin.ts +4 -0
- package/src/families/bitcoin/datasets/bitcoin_cash.ts +4 -0
- package/src/families/bitcoin/datasets/bitcoin_gold.ts +4 -0
- package/src/families/bitcoin/datasets/dash.ts +4 -0
- package/src/families/bitcoin/datasets/decred.ts +4 -0
- package/src/families/bitcoin/datasets/digibyte.ts +4 -0
- package/src/families/bitcoin/datasets/dogecoin.ts +4 -0
- package/src/families/bitcoin/datasets/komodo.ts +4 -0
- package/src/families/bitcoin/datasets/litecoin.ts +4 -0
- package/src/families/bitcoin/datasets/peercoin.ts +4 -0
- package/src/families/bitcoin/datasets/pivx.ts +4 -0
- package/src/families/bitcoin/datasets/qtum.ts +4 -0
- package/src/families/bitcoin/datasets/stakenet.ts +4 -0
- package/src/families/bitcoin/datasets/vertcoin.ts +4 -0
- package/src/families/bitcoin/datasets/viacoin.ts +4 -0
- package/src/families/bitcoin/datasets/zcash.ts +4 -0
- package/src/families/bitcoin/datasets/zencash.ts +4 -0
- package/src/families/bitcoin/js-buildTransaction.ts +2 -1
- package/src/families/bitcoin/js-estimateMaxSpendable.ts +2 -1
- package/src/families/bitcoin/js-synchronisation.ts +30 -16
- package/src/families/bitcoin/logic.ts +7 -2
- package/src/families/bitcoin/specs.ts +6 -1
- package/src/families/bitcoin/test-dataset.ts +2 -2
- package/src/families/bitcoin/wallet-btc/pickingstrategies/CoinSelect.ts +34 -22
- package/src/families/bitcoin/wallet-btc/pickingstrategies/DeepFirst.ts +30 -9
- package/src/families/bitcoin/wallet-btc/pickingstrategies/Merge.ts +30 -9
- package/src/families/bitcoin/wallet-btc/pickingstrategies/types.ts +3 -3
- package/src/families/bitcoin/wallet-btc/utils.ts +118 -35
- package/src/families/bitcoin/wallet-btc/wallet.ts +9 -4
- package/src/families/bitcoin/wallet-btc/xpub.ts +5 -5
- package/src/families/ethereum/modules/__snapshots__/compound.resilience.test.ts.snap +2876 -0
- package/src/families/ethereum/signOperation.ts +8 -0
- package/src/families/ethereum/synchronisation.ts +185 -6
- package/src/families/ethereum/versions.ts +1 -0
- package/src/nft/NftMetadataProvider/index.tsx +205 -0
- package/src/nft/NftMetadataProvider/logic.ts +20 -0
- package/src/nft/NftMetadataProvider/types.ts +60 -0
- package/src/nft/helpers.ts +78 -0
- package/src/nft/index.ts +3 -0
- package/src/nft/nftId.ts +17 -0
- package/src/operation.ts +22 -3
- package/src/reconciliation.ts +7 -0
- package/src/types/account.ts +4 -0
- package/src/types/index.ts +1 -0
- package/src/types/nft.ts +38 -0
- package/src/types/operation.ts +23 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { bech32m, bech32, BechLib } from "bech32";
|
|
2
2
|
import * as utils from "../../../../families/bitcoin/wallet-btc/utils";
|
|
3
3
|
import { Currency } from "../../../../families/bitcoin/wallet-btc/crypto/types";
|
|
4
|
+
import cryptoFactory from "../../../../families/bitcoin/wallet-btc/crypto/factory";
|
|
5
|
+
import { DerivationModes } from "../../../../families/bitcoin/wallet-btc";
|
|
4
6
|
|
|
5
7
|
function validateAddrs(
|
|
6
8
|
addresses: string[],
|
|
@@ -208,3 +210,106 @@ describe("Unit tests for various utils functions", () => {
|
|
|
208
210
|
validateAddrs(["S6NMcEfYbavHrP3Uo1wbEUvKhAbKeMugaa"], "stealthcoin", false);
|
|
209
211
|
});
|
|
210
212
|
});
|
|
213
|
+
|
|
214
|
+
describe("Unit tests for maxTxSize", () => {
|
|
215
|
+
const btc = cryptoFactory("bitcoin_testnet");
|
|
216
|
+
it("Empty tx non-segwit", () => {
|
|
217
|
+
const s = utils.maxTxSizeCeil(0, [], false, btc, DerivationModes.LEGACY);
|
|
218
|
+
expect(s).toEqual(10);
|
|
219
|
+
});
|
|
220
|
+
it("Empty tx segwit", () => {
|
|
221
|
+
const s = utils.maxTxSizeCeil(
|
|
222
|
+
0,
|
|
223
|
+
[],
|
|
224
|
+
false,
|
|
225
|
+
btc,
|
|
226
|
+
DerivationModes.NATIVE_SEGWIT
|
|
227
|
+
);
|
|
228
|
+
expect(s).toEqual(11);
|
|
229
|
+
});
|
|
230
|
+
it("1 p2wpkh input 1 p2wpkh output", () => {});
|
|
231
|
+
|
|
232
|
+
const tr = "tb1pdedptfps5k6hmzars9ks93ejsujh28kw5dhe06gutt9svap40j8qql2dw2";
|
|
233
|
+
const sh = "2Mv9bnjkBUr1GfCybJc7XmnJ5VG4SAT3shT";
|
|
234
|
+
const pkh = "mkQiYQGCkCC7Wus3vfhfTDjgJzQK554evn";
|
|
235
|
+
const wpkh = "tb1qhff3j7euu6t3lv8s5gsy9t5x82wuhfw5z863gj";
|
|
236
|
+
const p2tr = DerivationModes.TAPROOT;
|
|
237
|
+
const p2sh = DerivationModes.SEGWIT;
|
|
238
|
+
const p2pkh = DerivationModes.LEGACY;
|
|
239
|
+
const p2wpkh = DerivationModes.NATIVE_SEGWIT;
|
|
240
|
+
|
|
241
|
+
test.each([
|
|
242
|
+
// In 148 out 34
|
|
243
|
+
[0, [], false, p2pkh, 10],
|
|
244
|
+
[0, [], true, p2pkh, 44],
|
|
245
|
+
[0, [pkh], false, p2pkh, 44],
|
|
246
|
+
[0, [pkh], true, p2pkh, 78],
|
|
247
|
+
[1, [pkh], true, p2pkh, 226],
|
|
248
|
+
[2, [pkh], true, p2pkh, 374],
|
|
249
|
+
[1, [wpkh], true, p2pkh, 223],
|
|
250
|
+
[1, [sh], true, p2pkh, 224],
|
|
251
|
+
[1, [tr], true, p2pkh, 235],
|
|
252
|
+
|
|
253
|
+
// In 68 out 31
|
|
254
|
+
[0, [], false, p2wpkh, 11],
|
|
255
|
+
[0, [], true, p2wpkh, 42],
|
|
256
|
+
[1, [], false, p2wpkh, 79],
|
|
257
|
+
[1, [], true, p2wpkh, 110],
|
|
258
|
+
[2, [], true, p2wpkh, 178],
|
|
259
|
+
|
|
260
|
+
// In 90 out 32, scriptSig 22
|
|
261
|
+
[0, [], false, p2sh, 11],
|
|
262
|
+
[0, [], true, p2sh, 43],
|
|
263
|
+
[1, [], false, p2sh, 101],
|
|
264
|
+
[1, [sh], false, p2sh, 133],
|
|
265
|
+
[2, [sh], false, p2sh, 223],
|
|
266
|
+
|
|
267
|
+
// Fixed 10.5 In 57.75 out 43
|
|
268
|
+
[0, [], false, p2tr, 11],
|
|
269
|
+
[0, [], true, p2tr, 54],
|
|
270
|
+
[1, [], true, p2tr, Math.ceil(53.5 + 57.75 * 1)],
|
|
271
|
+
[2, [], true, p2tr, Math.ceil(53.5 + 57.75 * 2)],
|
|
272
|
+
[3, [], true, p2tr, Math.ceil(53.5 + 57.75 * 3)],
|
|
273
|
+
|
|
274
|
+
// 0xfc=252 inputs
|
|
275
|
+
[247, [], true, p2tr, Math.ceil(53.5 + 57.75 * 247)],
|
|
276
|
+
[248, [], true, p2tr, Math.ceil(53.5 + 57.75 * 248)],
|
|
277
|
+
[249, [], true, p2tr, Math.ceil(53.5 + 57.75 * 249)],
|
|
278
|
+
[250, [], true, p2tr, Math.ceil(53.5 + 57.75 * 250)],
|
|
279
|
+
[251, [], true, p2tr, Math.ceil(53.5 + 57.75 * 251)],
|
|
280
|
+
[252, [], true, p2tr, Math.ceil(53.5 + 57.75 * 252)],
|
|
281
|
+
// 0xfd=253 inputs will add 2 bytes for >= 0xfd
|
|
282
|
+
[253, [], true, p2tr, Math.ceil(53.5 + 57.75 * 253 + 2)],
|
|
283
|
+
[
|
|
284
|
+
256 * 256 - 1,
|
|
285
|
+
[],
|
|
286
|
+
true,
|
|
287
|
+
p2tr,
|
|
288
|
+
Math.ceil(53.5 + 57.75 * (256 * 256 - 1) + 2),
|
|
289
|
+
],
|
|
290
|
+
// 0xffff inputs will add 4 bytes
|
|
291
|
+
[256 * 256, [], true, p2tr, Math.ceil(53.5 + 57.75 * (256 * 256) + 4)],
|
|
292
|
+
|
|
293
|
+
// test address with witness version 16 and witness program [0x01, 0x02] => tb1sqypqyuzpgh
|
|
294
|
+
[
|
|
295
|
+
2,
|
|
296
|
+
[tr, sh, pkh, wpkh, "tb1sqypqyuzpgh"],
|
|
297
|
+
false,
|
|
298
|
+
p2wpkh,
|
|
299
|
+
Math.ceil(10.5 + 68 * 2 + 43 + 32 + 34 + 31 + 13),
|
|
300
|
+
],
|
|
301
|
+
])(
|
|
302
|
+
"%i, %s, %s, %s => %i",
|
|
303
|
+
(inputCount, outputAddrs, useChange, derivationMode, exp) => {
|
|
304
|
+
const s = utils.maxTxSizeCeil(
|
|
305
|
+
inputCount,
|
|
306
|
+
outputAddrs,
|
|
307
|
+
useChange,
|
|
308
|
+
btc,
|
|
309
|
+
derivationMode
|
|
310
|
+
);
|
|
311
|
+
//const s = utils.estimateTxSize(inputCount, outputAddrs.length + (useChange ? 1 : 0), btc, derivationMode);
|
|
312
|
+
expect(s).toEqual(exp);
|
|
313
|
+
}
|
|
314
|
+
);
|
|
315
|
+
});
|
|
@@ -57,9 +57,10 @@ describe("testing estimateMaxSpendable", () => {
|
|
|
57
57
|
expect(maxSpendable.toNumber()).toEqual(
|
|
58
58
|
balance -
|
|
59
59
|
feesPerByte *
|
|
60
|
-
utils.
|
|
60
|
+
utils.maxTxSizeCeil(
|
|
61
61
|
2,
|
|
62
|
-
|
|
62
|
+
[],
|
|
63
|
+
true,
|
|
63
64
|
account.xpub.crypto,
|
|
64
65
|
account.xpub.derivationMode
|
|
65
66
|
)
|
|
@@ -63,7 +63,7 @@ describe("testing wallet", () => {
|
|
|
63
63
|
fromAccount: account,
|
|
64
64
|
txInfo,
|
|
65
65
|
});
|
|
66
|
-
expect(
|
|
66
|
+
expect(Buffer.from(tx, "hex")).toHaveLength(20);
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it("should allow to build a transaction splitting outputs", async () => {
|
|
@@ -87,7 +87,7 @@ describe("testing wallet", () => {
|
|
|
87
87
|
fromAccount: account,
|
|
88
88
|
txInfo,
|
|
89
89
|
});
|
|
90
|
-
expect(
|
|
90
|
+
expect(Buffer.from(tx, "hex")).toHaveLength(20);
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it("should throw during sync if there is an error in explorer", async () => {
|
package/src/__tests__/families/bitcoin/wallet-btc/xpub.pickingStrategies.integration.test.ts
CHANGED
|
@@ -3,7 +3,10 @@ import * as bip39 from "bip39";
|
|
|
3
3
|
import * as bitcoin from "bitcoinjs-lib";
|
|
4
4
|
import coininfo from "coininfo";
|
|
5
5
|
import BigNumber from "bignumber.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
DerivationModes,
|
|
8
|
+
OutputInfo,
|
|
9
|
+
} from "../../../../families/bitcoin/wallet-btc/types";
|
|
7
10
|
import Xpub from "../../../../families/bitcoin/wallet-btc/xpub";
|
|
8
11
|
import BitcoinLikeExplorer from "../../../../families/bitcoin/wallet-btc/explorer";
|
|
9
12
|
import Crypto from "../../../../families/bitcoin/wallet-btc/crypto/bitcoin";
|
|
@@ -42,6 +45,17 @@ describe("testing xpub legacy transactions", () => {
|
|
|
42
45
|
xpub,
|
|
43
46
|
};
|
|
44
47
|
|
|
48
|
+
function outputs(amount: number): OutputInfo[] {
|
|
49
|
+
return [
|
|
50
|
+
{
|
|
51
|
+
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
|
|
52
|
+
isChange: false,
|
|
53
|
+
script: Buffer.from([]),
|
|
54
|
+
value: new BigNumber(amount),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
45
59
|
it("merge output strategy should be correct", async () => {
|
|
46
60
|
// Initialize the xpub with 2 txs. So that it has 2 utxo
|
|
47
61
|
dataset.xpub.storage.appendTxs([
|
|
@@ -134,17 +148,15 @@ describe("testing xpub legacy transactions", () => {
|
|
|
134
148
|
);
|
|
135
149
|
let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
136
150
|
dataset.xpub,
|
|
137
|
-
|
|
138
|
-
0
|
|
139
|
-
1
|
|
151
|
+
outputs(10000),
|
|
152
|
+
0
|
|
140
153
|
);
|
|
141
154
|
expect(res.unspentUtxos.length).toEqual(1); // only 1 utxo is enough
|
|
142
155
|
expect(Number(res.unspentUtxos[0].value)).toEqual(300000000); // use cheaper utxo first
|
|
143
156
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
144
157
|
dataset.xpub,
|
|
145
|
-
|
|
146
|
-
0
|
|
147
|
-
1
|
|
158
|
+
outputs(500000000),
|
|
159
|
+
0
|
|
148
160
|
);
|
|
149
161
|
expect(res.unspentUtxos.length).toEqual(2); // need 2 utxo
|
|
150
162
|
expect(
|
|
@@ -161,17 +173,15 @@ describe("testing xpub legacy transactions", () => {
|
|
|
161
173
|
);
|
|
162
174
|
let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
163
175
|
dataset.xpub,
|
|
164
|
-
|
|
165
|
-
0
|
|
166
|
-
1
|
|
176
|
+
outputs(10000),
|
|
177
|
+
0
|
|
167
178
|
);
|
|
168
179
|
expect(res.unspentUtxos.length).toEqual(1); // only 1 utxo is enough
|
|
169
180
|
expect(Number(res.unspentUtxos[0].value)).toEqual(5000000000); // use old utxo first
|
|
170
181
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
171
182
|
dataset.xpub,
|
|
172
|
-
|
|
173
|
-
0
|
|
174
|
-
1
|
|
183
|
+
outputs(5200000000),
|
|
184
|
+
0
|
|
175
185
|
);
|
|
176
186
|
expect(res.unspentUtxos.length).toEqual(2); // need 2 utxo
|
|
177
187
|
expect(
|
|
@@ -323,45 +333,40 @@ describe("testing xpub legacy transactions", () => {
|
|
|
323
333
|
);
|
|
324
334
|
let res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
325
335
|
dataset.xpub,
|
|
326
|
-
|
|
327
|
-
10
|
|
328
|
-
1
|
|
336
|
+
outputs(10000),
|
|
337
|
+
10
|
|
329
338
|
);
|
|
330
339
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
331
340
|
expect(Number(res.unspentUtxos[0].value)).toEqual(100000000);
|
|
332
341
|
|
|
333
342
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
334
343
|
dataset.xpub,
|
|
335
|
-
|
|
336
|
-
10
|
|
337
|
-
1
|
|
344
|
+
outputs(290000000),
|
|
345
|
+
10
|
|
338
346
|
);
|
|
339
347
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
340
348
|
expect(Number(res.unspentUtxos[0].value)).toEqual(300000000);
|
|
341
349
|
|
|
342
350
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
343
351
|
dataset.xpub,
|
|
344
|
-
|
|
345
|
-
10
|
|
346
|
-
1
|
|
352
|
+
outputs(500000000),
|
|
353
|
+
10
|
|
347
354
|
);
|
|
348
355
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
349
356
|
expect(Number(res.unspentUtxos[0].value)).toEqual(600000000);
|
|
350
357
|
|
|
351
358
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
352
359
|
dataset.xpub,
|
|
353
|
-
|
|
354
|
-
10
|
|
355
|
-
1
|
|
360
|
+
outputs(800000000),
|
|
361
|
+
10
|
|
356
362
|
);
|
|
357
363
|
expect(res.unspentUtxos.length).toEqual(1);
|
|
358
364
|
expect(Number(res.unspentUtxos[0].value)).toEqual(5000000000);
|
|
359
365
|
|
|
360
366
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
361
367
|
dataset.xpub,
|
|
362
|
-
|
|
363
|
-
10
|
|
364
|
-
1
|
|
368
|
+
outputs(5000000000),
|
|
369
|
+
10
|
|
365
370
|
);
|
|
366
371
|
expect(res.unspentUtxos.length).toEqual(2);
|
|
367
372
|
expect(
|
|
@@ -370,9 +375,8 @@ describe("testing xpub legacy transactions", () => {
|
|
|
370
375
|
|
|
371
376
|
res = await utxoPickingStrategy.selectUnspentUtxosToUse(
|
|
372
377
|
dataset.xpub,
|
|
373
|
-
|
|
374
|
-
10
|
|
375
|
-
1
|
|
378
|
+
outputs(5600000000),
|
|
379
|
+
10
|
|
376
380
|
);
|
|
377
381
|
expect(res.unspentUtxos.length).toEqual(3);
|
|
378
382
|
expect(
|
|
@@ -178,9 +178,10 @@ describe.skip("testing xpub segwit transactions", () => {
|
|
|
178
178
|
await xpubs[1].xpub.sync();
|
|
179
179
|
|
|
180
180
|
expectedFee1 =
|
|
181
|
-
utils.
|
|
181
|
+
utils.maxTxSizeCeil(
|
|
182
182
|
inputs.length,
|
|
183
|
-
outputs.
|
|
183
|
+
outputs.map((o) => o.address),
|
|
184
|
+
false,
|
|
184
185
|
crypto,
|
|
185
186
|
DerivationModes.SEGWIT
|
|
186
187
|
) * 100;
|
|
@@ -167,9 +167,10 @@ describe.skip("testing xpub native segwit transactions", () => {
|
|
|
167
167
|
await xpubs[1].xpub.sync();
|
|
168
168
|
|
|
169
169
|
expectedFee1 =
|
|
170
|
-
utils.
|
|
170
|
+
utils.maxTxSizeCeil(
|
|
171
171
|
inputs.length,
|
|
172
|
-
outputs.
|
|
172
|
+
outputs.map((o) => o.address),
|
|
173
|
+
false,
|
|
173
174
|
crypto,
|
|
174
175
|
DerivationModes.NATIVE_SEGWIT
|
|
175
176
|
) * 100;
|
|
@@ -148,9 +148,10 @@ describe.skip("testing xpub legacy transactions", () => {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
expectedFee1 =
|
|
151
|
-
utils.
|
|
151
|
+
utils.maxTxSizeCeil(
|
|
152
152
|
inputs.length,
|
|
153
|
-
outputs.
|
|
153
|
+
outputs.map((o) => o.address),
|
|
154
|
+
false,
|
|
154
155
|
crypto,
|
|
155
156
|
DerivationModes.LEGACY
|
|
156
157
|
) * 100;
|
|
@@ -280,9 +281,10 @@ describe.skip("testing xpub legacy transactions", () => {
|
|
|
280
281
|
await xpubs[1].xpub.sync();
|
|
281
282
|
|
|
282
283
|
expectedFee2 =
|
|
283
|
-
utils.
|
|
284
|
+
utils.maxTxSizeCeil(
|
|
284
285
|
inputs.length,
|
|
285
|
-
outputs.
|
|
286
|
+
outputs.map((o) => o.address),
|
|
287
|
+
false,
|
|
286
288
|
crypto,
|
|
287
289
|
DerivationModes.LEGACY
|
|
288
290
|
) * 100;
|
|
@@ -12,6 +12,15 @@ import { formatCurrencyUnit } from "../currencies";
|
|
|
12
12
|
import { getOperationAmountNumber } from "../operation";
|
|
13
13
|
import { getTagDerivationMode } from "../derivation";
|
|
14
14
|
import byFamily from "../generated/account";
|
|
15
|
+
import { nftsByCollections } from "../nft";
|
|
16
|
+
|
|
17
|
+
const styling = {
|
|
18
|
+
bold: (str: string) => `\x1b[1m${str}\x1b[22m`,
|
|
19
|
+
underline: (str: string) => `\x1b[4m${str}\x1b[24m`,
|
|
20
|
+
cyan: (str: string) => `\x1b[36m${str}\x1b[37m`,
|
|
21
|
+
magenta: (str: string) => `\x1b[35m${str}\x1b[37m`,
|
|
22
|
+
reverse: (str: string) => `\x1b[7m${str}\x1b[27m`,
|
|
23
|
+
};
|
|
15
24
|
|
|
16
25
|
const isSignificantAccount = (acc) =>
|
|
17
26
|
acc.balance.gt(10 ** (getAccountUnit(acc).magnitude - 6));
|
|
@@ -80,6 +89,7 @@ const cliFormat = (account, level?: string) => {
|
|
|
80
89
|
derivationMode,
|
|
81
90
|
index,
|
|
82
91
|
operations,
|
|
92
|
+
nfts,
|
|
83
93
|
} = account;
|
|
84
94
|
const tag = getTagDerivationMode(account.currency, derivationMode);
|
|
85
95
|
const balance = formatCurrencyUnit(account.unit, account.balance, {
|
|
@@ -122,6 +132,39 @@ const cliFormat = (account, level?: string) => {
|
|
|
122
132
|
maybeDisplaySumOfOpsIssue(ta.operations, ta.balance, getAccountUnit(ta))
|
|
123
133
|
)
|
|
124
134
|
.join("\n");
|
|
135
|
+
|
|
136
|
+
if (nfts?.length) {
|
|
137
|
+
const NFTCollections = nftsByCollections(nfts);
|
|
138
|
+
|
|
139
|
+
str += "\n";
|
|
140
|
+
str += `NFT Collections (${NFTCollections.length}) `;
|
|
141
|
+
str += "\n";
|
|
142
|
+
|
|
143
|
+
str += NFTCollections.map(
|
|
144
|
+
// nfts are set to any because there not just NFT, we added a metadata prop on the fly
|
|
145
|
+
// in the first step of the Rxjs flow to avoid having some async code here
|
|
146
|
+
({ contract, nfts }: { contract: string; nfts: any[] }) => {
|
|
147
|
+
const tokenName = nfts?.[0]?.metadata?.tokenName;
|
|
148
|
+
const { bold, magenta, cyan, reverse } = styling;
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
`${bold(tokenName ?? "Unknown Collection Name")} (${magenta(
|
|
152
|
+
contract
|
|
153
|
+
)}): ` +
|
|
154
|
+
nfts
|
|
155
|
+
.map((t) =>
|
|
156
|
+
t?.metadata?.nftName
|
|
157
|
+
? `\n ${t.amount}x ${reverse(
|
|
158
|
+
` ${t?.metadata?.nftName} `
|
|
159
|
+
)} ${cyan("#" + t.tokenId)}`
|
|
160
|
+
: `\n ${t.amount}x ${cyan("#" + t.tokenId)}`
|
|
161
|
+
)
|
|
162
|
+
.join()
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
).join("\n");
|
|
166
|
+
}
|
|
167
|
+
|
|
125
168
|
if (level === "basic") return str;
|
|
126
169
|
str += "\nOPERATIONS (" + operations.length + ")";
|
|
127
170
|
str += operations
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AccountLikeArray, AccountLike, Operation } from "../types";
|
|
2
2
|
import { flattenAccounts } from "./helpers";
|
|
3
|
-
import {
|
|
3
|
+
import { flattenOperationWithInternalsAndNfts } from "../operation";
|
|
4
4
|
export type DailyOperationsSection = {
|
|
5
5
|
day: Date;
|
|
6
6
|
data: Operation[];
|
|
@@ -105,7 +105,7 @@ export function groupAccountsOperationsByDay(
|
|
|
105
105
|
indexes[bestOpInfo.accountI]++;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const ops =
|
|
108
|
+
const ops = flattenOperationWithInternalsAndNfts(bestOp);
|
|
109
109
|
return {
|
|
110
110
|
ops,
|
|
111
111
|
date: bestOp.date,
|
|
@@ -16,6 +16,8 @@ import type {
|
|
|
16
16
|
OperationRaw,
|
|
17
17
|
SubAccount,
|
|
18
18
|
SubAccountRaw,
|
|
19
|
+
NFT,
|
|
20
|
+
NFTRaw,
|
|
19
21
|
} from "../types";
|
|
20
22
|
import type { TronResources, TronResourcesRaw } from "../families/tron/types";
|
|
21
23
|
import {
|
|
@@ -101,6 +103,7 @@ export const toOperationRaw = (
|
|
|
101
103
|
fee,
|
|
102
104
|
subOperations,
|
|
103
105
|
internalOperations,
|
|
106
|
+
nftOperations,
|
|
104
107
|
extra,
|
|
105
108
|
id,
|
|
106
109
|
hash,
|
|
@@ -112,6 +115,10 @@ export const toOperationRaw = (
|
|
|
112
115
|
transactionSequenceNumber,
|
|
113
116
|
accountId,
|
|
114
117
|
hasFailed,
|
|
118
|
+
contract,
|
|
119
|
+
operator,
|
|
120
|
+
standard,
|
|
121
|
+
tokenId,
|
|
115
122
|
}: Operation,
|
|
116
123
|
preserveSubOperation?: boolean
|
|
117
124
|
): OperationRaw => {
|
|
@@ -142,6 +149,10 @@ export const toOperationRaw = (
|
|
|
142
149
|
date: date.toISOString(),
|
|
143
150
|
value: value.toFixed(),
|
|
144
151
|
fee: fee.toString(),
|
|
152
|
+
contract,
|
|
153
|
+
operator,
|
|
154
|
+
standard,
|
|
155
|
+
tokenId,
|
|
145
156
|
};
|
|
146
157
|
|
|
147
158
|
if (transactionSequenceNumber !== undefined) {
|
|
@@ -160,6 +171,10 @@ export const toOperationRaw = (
|
|
|
160
171
|
copy.internalOperations = internalOperations.map((o) => toOperationRaw(o));
|
|
161
172
|
}
|
|
162
173
|
|
|
174
|
+
if (nftOperations) {
|
|
175
|
+
copy.nftOperations = nftOperations.map((o) => toOperationRaw(o));
|
|
176
|
+
}
|
|
177
|
+
|
|
163
178
|
return copy;
|
|
164
179
|
};
|
|
165
180
|
export const inferSubOperations = (
|
|
@@ -198,6 +213,7 @@ export const fromOperationRaw = (
|
|
|
198
213
|
extra,
|
|
199
214
|
subOperations,
|
|
200
215
|
internalOperations,
|
|
216
|
+
nftOperations,
|
|
201
217
|
id,
|
|
202
218
|
hash,
|
|
203
219
|
type,
|
|
@@ -207,6 +223,10 @@ export const fromOperationRaw = (
|
|
|
207
223
|
blockHash,
|
|
208
224
|
transactionSequenceNumber,
|
|
209
225
|
hasFailed,
|
|
226
|
+
contract,
|
|
227
|
+
operator,
|
|
228
|
+
standard,
|
|
229
|
+
tokenId,
|
|
210
230
|
}: OperationRaw,
|
|
211
231
|
accountId: string,
|
|
212
232
|
subAccounts?: SubAccount[] | null | undefined
|
|
@@ -238,6 +258,10 @@ export const fromOperationRaw = (
|
|
|
238
258
|
value: new BigNumber(value),
|
|
239
259
|
fee: new BigNumber(fee),
|
|
240
260
|
extra: e || {},
|
|
261
|
+
contract,
|
|
262
|
+
operator,
|
|
263
|
+
standard,
|
|
264
|
+
tokenId,
|
|
241
265
|
};
|
|
242
266
|
|
|
243
267
|
if (transactionSequenceNumber !== undefined) {
|
|
@@ -262,6 +286,12 @@ export const fromOperationRaw = (
|
|
|
262
286
|
);
|
|
263
287
|
}
|
|
264
288
|
|
|
289
|
+
if (nftOperations) {
|
|
290
|
+
res.nftOperations = nftOperations.map((o) =>
|
|
291
|
+
fromOperationRaw(o, o.accountId)
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
265
295
|
return res;
|
|
266
296
|
};
|
|
267
297
|
export const toTronResourcesRaw = ({
|
|
@@ -677,6 +707,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
|
|
|
677
707
|
polkadotResources,
|
|
678
708
|
elrondResources,
|
|
679
709
|
cryptoOrgResources,
|
|
710
|
+
nfts,
|
|
680
711
|
} = rawAccount;
|
|
681
712
|
const subAccounts =
|
|
682
713
|
subAccountsRaw &&
|
|
@@ -734,6 +765,7 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
|
|
|
734
765
|
swapHistory: [],
|
|
735
766
|
syncHash,
|
|
736
767
|
balanceHistoryCache: balanceHistoryCache || emptyHistoryCache,
|
|
768
|
+
nfts: nfts?.map((n) => fromNFTRaw(n)),
|
|
737
769
|
};
|
|
738
770
|
res.balanceHistoryCache = generateHistoryFromOperations(res);
|
|
739
771
|
|
|
@@ -834,6 +866,7 @@ export function toAccountRaw({
|
|
|
834
866
|
polkadotResources,
|
|
835
867
|
elrondResources,
|
|
836
868
|
cryptoOrgResources,
|
|
869
|
+
nfts,
|
|
837
870
|
}: Account): AccountRaw {
|
|
838
871
|
const res: AccountRaw = {
|
|
839
872
|
id,
|
|
@@ -857,6 +890,7 @@ export function toAccountRaw({
|
|
|
857
890
|
lastSyncDate: lastSyncDate.toISOString(),
|
|
858
891
|
balance: balance.toFixed(),
|
|
859
892
|
spendableBalance: spendableBalance.toFixed(),
|
|
893
|
+
nfts: nfts?.map((n) => toNFTRaw(n)),
|
|
860
894
|
};
|
|
861
895
|
|
|
862
896
|
if (balanceHistory) {
|
|
@@ -914,3 +948,21 @@ export function toAccountRaw({
|
|
|
914
948
|
}
|
|
915
949
|
return res;
|
|
916
950
|
}
|
|
951
|
+
|
|
952
|
+
export function toNFTRaw({ id, tokenId, amount, collection }: NFT): NFTRaw {
|
|
953
|
+
return {
|
|
954
|
+
id,
|
|
955
|
+
tokenId,
|
|
956
|
+
amount: amount.toFixed(),
|
|
957
|
+
collection,
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
export function fromNFTRaw({ id, tokenId, amount, collection }: NFTRaw): NFT {
|
|
962
|
+
return {
|
|
963
|
+
id,
|
|
964
|
+
tokenId,
|
|
965
|
+
amount: new BigNumber(amount),
|
|
966
|
+
collection,
|
|
967
|
+
};
|
|
968
|
+
}
|
package/src/api/Ethereum.ts
CHANGED
|
@@ -3,12 +3,14 @@ import invariant from "invariant";
|
|
|
3
3
|
import { BigNumber } from "bignumber.js";
|
|
4
4
|
import { LedgerAPINotAvailable } from "@ledgerhq/errors";
|
|
5
5
|
import JSONBigNumber from "@ledgerhq/json-bignumber";
|
|
6
|
-
import type { CryptoCurrency } from "../types";
|
|
6
|
+
import type { CryptoCurrency, NFTMetadataResponse } from "../types";
|
|
7
7
|
import type { EthereumGasLimitRequest } from "../families/ethereum/types";
|
|
8
8
|
import network from "../network";
|
|
9
9
|
import { blockchainBaseURL } from "./Ledger";
|
|
10
10
|
import { FeeEstimationFailed } from "../errors";
|
|
11
11
|
import { makeLRUCache } from "../cache";
|
|
12
|
+
import { getEnv } from "../env";
|
|
13
|
+
|
|
12
14
|
export type Block = {
|
|
13
15
|
height: BigNumber;
|
|
14
16
|
}; // TODO more fields actually
|
|
@@ -37,6 +39,22 @@ export type Tx = {
|
|
|
37
39
|
}>;
|
|
38
40
|
truncated: boolean;
|
|
39
41
|
};
|
|
42
|
+
erc721_transfer_events?: Array<{
|
|
43
|
+
contract: string;
|
|
44
|
+
sender: string;
|
|
45
|
+
receiver: string;
|
|
46
|
+
token_id: string;
|
|
47
|
+
}>;
|
|
48
|
+
erc1155_transfer_events?: Array<{
|
|
49
|
+
contract: string;
|
|
50
|
+
sender: string;
|
|
51
|
+
operator: string;
|
|
52
|
+
receiver: string;
|
|
53
|
+
transfers: Array<{
|
|
54
|
+
id: string;
|
|
55
|
+
value: string;
|
|
56
|
+
}>;
|
|
57
|
+
}>;
|
|
40
58
|
actions?: Array<{
|
|
41
59
|
from: string;
|
|
42
60
|
to: string;
|
|
@@ -59,6 +77,12 @@ export type ERC20BalanceOutput = Array<{
|
|
|
59
77
|
contract: string;
|
|
60
78
|
balance: BigNumber;
|
|
61
79
|
}>;
|
|
80
|
+
export type NFTMetadataInput = Readonly<
|
|
81
|
+
Array<{
|
|
82
|
+
contract: string;
|
|
83
|
+
tokenId: string;
|
|
84
|
+
}>
|
|
85
|
+
>;
|
|
62
86
|
export type API = {
|
|
63
87
|
getTransactions: (
|
|
64
88
|
address: string,
|
|
@@ -72,6 +96,7 @@ export type API = {
|
|
|
72
96
|
getAccountNonce: (address: string) => Promise<number>;
|
|
73
97
|
broadcastTransaction: (signedTransaction: string) => Promise<string>;
|
|
74
98
|
getERC20Balances: (input: ERC20BalancesInput) => Promise<ERC20BalanceOutput>;
|
|
99
|
+
getNFTMetadata: (input: NFTMetadataInput) => Promise<NFTMetadataResponse[]>;
|
|
75
100
|
getAccountBalance: (address: string) => Promise<BigNumber>;
|
|
76
101
|
roughlyEstimateGasLimit: (address: string) => Promise<BigNumber>;
|
|
77
102
|
getERC20ApprovalsPerContract: (
|
|
@@ -107,7 +132,10 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
|
|
|
107
132
|
let { data } = await network({
|
|
108
133
|
method: "GET",
|
|
109
134
|
url: URL.format({
|
|
110
|
-
pathname:
|
|
135
|
+
pathname:
|
|
136
|
+
getEnv("NFT") && currency.ticker === "ETH"
|
|
137
|
+
? `https://explorers.api-01.live.ledger-stg.com/blockchain/v3/eth/addresses/${address}/transactions`
|
|
138
|
+
: `${baseURL}/addresses/${address}/transactions`,
|
|
111
139
|
query: {
|
|
112
140
|
batch_size,
|
|
113
141
|
noinput: true,
|
|
@@ -178,6 +206,16 @@ export const apiForCurrency = (currency: CryptoCurrency): API => {
|
|
|
178
206
|
return data;
|
|
179
207
|
},
|
|
180
208
|
|
|
209
|
+
async getNFTMetadata(input) {
|
|
210
|
+
const { data }: { data: NFTMetadataResponse[] } = await network({
|
|
211
|
+
method: "POST",
|
|
212
|
+
url: getEnv("NFT_ETH_METADATA_SERVICE"),
|
|
213
|
+
data: input,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return data;
|
|
217
|
+
},
|
|
218
|
+
|
|
181
219
|
async getERC20ApprovalsPerContract(owner, contract) {
|
|
182
220
|
try {
|
|
183
221
|
const { data } = await network({
|
package/src/apps/polyfill.ts
CHANGED
|
@@ -49,6 +49,9 @@ export const whitelistDependencies = ["Decred", "Decred Testnet"];
|
|
|
49
49
|
["Opensea", "Ethereum"],
|
|
50
50
|
["StakeDAO", "Ethereum"],
|
|
51
51
|
["Yearn", "Ethereum"],
|
|
52
|
+
["RocketPool", "Ethereum"],
|
|
53
|
+
["POAP", "Ethereum"],
|
|
54
|
+
["OlympusDAO", "Ethereum"],
|
|
52
55
|
].forEach(([name, dep]) => declareDep(name, dep));
|
|
53
56
|
export const getDependencies = (appName: string): string[] =>
|
|
54
57
|
directDep[appName] || [];
|