@ledgerhq/coin-hedera 1.12.1-nightly.1 → 1.13.0-nightly.3
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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +1 -1
- package/CHANGELOG.md +29 -0
- package/jest.config.js +1 -1
- package/jest.integ.config.js +8 -0
- package/lib/api/index.d.ts +4 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +119 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +6 -9
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +14 -11
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/createTransaction.d.ts +1 -1
- package/lib/bridge/createTransaction.d.ts.map +1 -1
- package/lib/bridge/createTransaction.js +2 -0
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -2
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +11 -10
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +6 -5
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +53 -14
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +24 -11
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/bridge/utils.d.ts +3 -13
- package/lib/bridge/utils.d.ts.map +1 -1
- package/lib/bridge/utils.js +10 -119
- package/lib/bridge/utils.js.map +1 -1
- package/lib/config.d.ts +8 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +11 -8
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +17 -13
- package/lib/constants.js.map +1 -1
- package/lib/deviceTransactionConfig.d.ts +2 -2
- package/lib/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/deviceTransactionConfig.js +4 -4
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/logic/broadcast.d.ts +3 -0
- package/lib/logic/broadcast.d.ts.map +1 -0
- package/lib/logic/broadcast.js +11 -0
- package/lib/logic/broadcast.js.map +1 -0
- package/lib/logic/combine.d.ts +2 -0
- package/lib/logic/combine.d.ts.map +1 -0
- package/lib/logic/combine.js +19 -0
- package/lib/logic/combine.js.map +1 -0
- package/lib/logic/craftTransaction.d.ts +8 -0
- package/lib/logic/craftTransaction.d.ts.map +1 -0
- package/lib/logic/craftTransaction.js +107 -0
- package/lib/logic/craftTransaction.js.map +1 -0
- package/lib/logic/estimateFees.d.ts +5 -0
- package/lib/logic/estimateFees.d.ts.map +1 -0
- package/lib/logic/estimateFees.js +25 -0
- package/lib/logic/estimateFees.js.map +1 -0
- package/lib/logic/getAssetFromToken.d.ts +4 -0
- package/lib/logic/getAssetFromToken.d.ts.map +1 -0
- package/lib/logic/getAssetFromToken.js +14 -0
- package/lib/logic/getAssetFromToken.js.map +1 -0
- package/lib/logic/getBalance.d.ts +4 -0
- package/lib/logic/getBalance.d.ts.map +1 -0
- package/lib/logic/getBalance.js +36 -0
- package/lib/logic/getBalance.js.map +1 -0
- package/lib/logic/getTokenFromAsset.d.ts +4 -0
- package/lib/logic/getTokenFromAsset.d.ts.map +1 -0
- package/lib/logic/getTokenFromAsset.js +13 -0
- package/lib/logic/getTokenFromAsset.js.map +1 -0
- package/lib/logic/index.d.ts +10 -0
- package/lib/logic/index.d.ts.map +1 -0
- package/lib/logic/index.js +22 -0
- package/lib/logic/index.js.map +1 -0
- package/lib/logic/lastBlock.d.ts +12 -0
- package/lib/logic/lastBlock.d.ts.map +1 -0
- package/lib/logic/lastBlock.js +25 -0
- package/lib/logic/lastBlock.js.map +1 -0
- package/lib/logic/listOperations.d.ts +19 -0
- package/lib/logic/listOperations.d.ts.map +1 -0
- package/lib/logic/listOperations.js +179 -0
- package/lib/logic/listOperations.js.map +1 -0
- package/lib/logic/utils.d.ts +55 -0
- package/lib/logic/utils.d.ts.map +1 -0
- package/lib/logic/utils.js +197 -0
- package/lib/logic/utils.js.map +1 -0
- package/lib/network/api.d.ts +24 -0
- package/lib/network/api.d.ts.map +1 -0
- package/lib/network/api.js +119 -0
- package/lib/network/api.js.map +1 -0
- package/lib/network/rpc.d.ts +12 -0
- package/lib/network/rpc.d.ts.map +1 -0
- package/lib/network/rpc.js +22 -0
- package/lib/network/rpc.js.map +1 -0
- package/lib/{api → network}/utils.d.ts +1 -5
- package/lib/network/utils.d.ts.map +1 -0
- package/lib/network/utils.js +52 -0
- package/lib/network/utils.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib/test/bridgeDatasetTest.js +5 -1
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/fixtures/account.fixture.d.ts +17 -0
- package/lib/test/fixtures/account.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/account.fixture.js +18 -1
- package/lib/test/fixtures/account.fixture.js.map +1 -1
- package/lib/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/currency.fixture.js +1 -1
- package/lib/test/fixtures/currency.fixture.js.map +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts +1 -1
- package/lib/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/network.fixture.d.ts +3 -0
- package/lib/test/fixtures/network.fixture.d.ts.map +1 -0
- package/lib/test/fixtures/network.fixture.js +9 -0
- package/lib/test/fixtures/network.fixture.js.map +1 -0
- package/lib/test/fixtures/transaction.fixture.d.ts.map +1 -1
- package/lib/test/fixtures/transaction.fixture.js +3 -0
- package/lib/test/fixtures/transaction.fixture.js.map +1 -1
- package/lib/transaction.d.ts +1 -1
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +35 -6
- package/lib/transaction.js.map +1 -1
- package/lib/types/alpaca.d.ts +3 -0
- package/lib/types/alpaca.d.ts.map +1 -0
- package/lib/{api/types.js → types/alpaca.js} +1 -1
- package/lib/types/alpaca.js.map +1 -0
- package/lib/types/bridge.d.ts +28 -9
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -0
- package/lib/types/index.js.map +1 -1
- package/lib/{api/types.d.ts → types/mirror.d.ts} +21 -2
- package/lib/types/mirror.d.ts.map +1 -0
- package/lib/types/mirror.js +3 -0
- package/lib/types/mirror.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +112 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +4 -7
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +12 -9
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/createTransaction.d.ts +1 -1
- package/lib-es/bridge/createTransaction.d.ts.map +1 -1
- package/lib-es/bridge/createTransaction.js +2 -0
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -2
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +7 -6
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -3
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +53 -14
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +24 -11
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/bridge/utils.d.ts +3 -13
- package/lib-es/bridge/utils.d.ts.map +1 -1
- package/lib-es/bridge/utils.js +7 -113
- package/lib-es/bridge/utils.js.map +1 -1
- package/lib-es/config.d.ts +8 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +11 -8
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +13 -9
- package/lib-es/constants.js.map +1 -1
- package/lib-es/deviceTransactionConfig.d.ts +2 -2
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/deviceTransactionConfig.js +2 -2
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/logic/broadcast.d.ts +3 -0
- package/lib-es/logic/broadcast.d.ts.map +1 -0
- package/lib-es/logic/broadcast.js +7 -0
- package/lib-es/logic/broadcast.js.map +1 -0
- package/lib-es/logic/combine.d.ts +2 -0
- package/lib-es/logic/combine.d.ts.map +1 -0
- package/lib-es/logic/combine.js +12 -0
- package/lib-es/logic/combine.js.map +1 -0
- package/lib-es/logic/craftTransaction.d.ts +8 -0
- package/lib-es/logic/craftTransaction.d.ts.map +1 -0
- package/lib-es/logic/craftTransaction.js +100 -0
- package/lib-es/logic/craftTransaction.js.map +1 -0
- package/lib-es/logic/estimateFees.d.ts +5 -0
- package/lib-es/logic/estimateFees.d.ts.map +1 -0
- package/lib-es/logic/estimateFees.js +18 -0
- package/lib-es/logic/estimateFees.js.map +1 -0
- package/lib-es/logic/getAssetFromToken.d.ts +4 -0
- package/lib-es/logic/getAssetFromToken.d.ts.map +1 -0
- package/lib-es/logic/getAssetFromToken.js +10 -0
- package/lib-es/logic/getAssetFromToken.js.map +1 -0
- package/lib-es/logic/getBalance.d.ts +4 -0
- package/lib-es/logic/getBalance.d.ts.map +1 -0
- package/lib-es/logic/getBalance.js +32 -0
- package/lib-es/logic/getBalance.js.map +1 -0
- package/lib-es/logic/getTokenFromAsset.d.ts +4 -0
- package/lib-es/logic/getTokenFromAsset.d.ts.map +1 -0
- package/lib-es/logic/getTokenFromAsset.js +9 -0
- package/lib-es/logic/getTokenFromAsset.js.map +1 -0
- package/lib-es/logic/index.d.ts +10 -0
- package/lib-es/logic/index.d.ts.map +1 -0
- package/lib-es/logic/index.js +10 -0
- package/lib-es/logic/index.js.map +1 -0
- package/lib-es/logic/lastBlock.d.ts +12 -0
- package/lib-es/logic/lastBlock.d.ts.map +1 -0
- package/lib-es/logic/lastBlock.js +21 -0
- package/lib-es/logic/lastBlock.js.map +1 -0
- package/lib-es/logic/listOperations.d.ts +19 -0
- package/lib-es/logic/listOperations.d.ts.map +1 -0
- package/lib-es/logic/listOperations.js +172 -0
- package/lib-es/logic/listOperations.js.map +1 -0
- package/lib-es/logic/utils.d.ts +55 -0
- package/lib-es/logic/utils.d.ts.map +1 -0
- package/lib-es/logic/utils.js +174 -0
- package/lib-es/logic/utils.js.map +1 -0
- package/lib-es/network/api.d.ts +24 -0
- package/lib-es/network/api.d.ts.map +1 -0
- package/lib-es/network/api.js +113 -0
- package/lib-es/network/api.js.map +1 -0
- package/lib-es/network/rpc.d.ts +12 -0
- package/lib-es/network/rpc.d.ts.map +1 -0
- package/lib-es/network/rpc.js +19 -0
- package/lib-es/network/rpc.js.map +1 -0
- package/lib-es/{api → network}/utils.d.ts +1 -5
- package/lib-es/network/utils.d.ts.map +1 -0
- package/lib-es/network/utils.js +45 -0
- package/lib-es/network/utils.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +5 -1
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/fixtures/account.fixture.d.ts +17 -0
- package/lib-es/test/fixtures/account.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/account.fixture.js +17 -0
- package/lib-es/test/fixtures/account.fixture.js.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/currency.fixture.js +1 -1
- package/lib-es/test/fixtures/currency.fixture.js.map +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts +1 -1
- package/lib-es/test/fixtures/mirror.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/network.fixture.d.ts +3 -0
- package/lib-es/test/fixtures/network.fixture.d.ts.map +1 -0
- package/lib-es/test/fixtures/network.fixture.js +5 -0
- package/lib-es/test/fixtures/network.fixture.js.map +1 -0
- package/lib-es/test/fixtures/transaction.fixture.d.ts.map +1 -1
- package/lib-es/test/fixtures/transaction.fixture.js +3 -0
- package/lib-es/test/fixtures/transaction.fixture.js.map +1 -1
- package/lib-es/transaction.d.ts +1 -1
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +35 -6
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types/alpaca.d.ts +3 -0
- package/lib-es/types/alpaca.d.ts.map +1 -0
- package/lib-es/types/alpaca.js +2 -0
- package/lib-es/types/alpaca.js.map +1 -0
- package/lib-es/types/bridge.d.ts +28 -9
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +2 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +2 -0
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/{api/types.d.ts → types/mirror.d.ts} +21 -2
- package/lib-es/types/mirror.d.ts.map +1 -0
- package/lib-es/types/mirror.js +2 -0
- package/lib-es/types/mirror.js.map +1 -0
- package/package.json +8 -7
- package/src/api/index.integ.test.ts +401 -0
- package/src/api/index.test.ts +30 -0
- package/src/api/index.ts +149 -0
- package/src/bridge/broadcast.ts +5 -10
- package/src/bridge/buildOptimisticOperation.integration.test.ts +8 -8
- package/src/bridge/buildOptimisticOperation.ts +13 -10
- package/src/bridge/createTransaction.ts +3 -1
- package/src/bridge/estimateMaxSpendable.ts +6 -3
- package/src/bridge/getTransactionStatus.test.ts +11 -10
- package/src/bridge/getTransactionStatus.ts +12 -11
- package/src/bridge/js-estimateMaxSpendable.integration.test.ts +6 -3
- package/src/bridge/prepareTransaction.test.ts +9 -17
- package/src/bridge/prepareTransaction.ts +5 -4
- package/src/bridge/serialization.test.ts +6 -6
- package/src/bridge/signOperation.ts +69 -16
- package/src/bridge/synchronisation.ts +22 -14
- package/src/bridge/utils.integration.test.ts +19 -248
- package/src/bridge/utils.ts +14 -160
- package/src/config.ts +7 -0
- package/src/constants.ts +15 -9
- package/src/deviceTransactionConfig.ts +4 -4
- package/src/logic/broadcast.test.ts +58 -0
- package/src/logic/broadcast.ts +8 -0
- package/src/logic/combine.test.ts +119 -0
- package/src/logic/combine.ts +14 -0
- package/src/logic/craftTransaction.test.ts +215 -0
- package/src/logic/craftTransaction.ts +175 -0
- package/src/logic/estimateFees.test.ts +99 -0
- package/src/logic/estimateFees.ts +28 -0
- package/src/logic/getAssetFromToken.test.ts +27 -0
- package/src/logic/getAssetFromToken.ts +12 -0
- package/src/logic/getBalance.test.ts +200 -0
- package/src/logic/getBalance.ts +39 -0
- package/src/logic/getTokenFromAsset.test.ts +22 -0
- package/src/logic/getTokenFromAsset.ts +17 -0
- package/src/logic/index.ts +9 -0
- package/src/logic/lastBlock.test.ts +23 -0
- package/src/logic/lastBlock.ts +23 -0
- package/src/logic/listOperations.test.ts +388 -0
- package/src/logic/listOperations.ts +247 -0
- package/src/logic/utils.test.ts +432 -0
- package/src/logic/utils.ts +255 -0
- package/src/{api/mirror.test.ts → network/api.test.ts} +81 -35
- package/src/network/api.ts +159 -0
- package/src/network/rpc.test.ts +68 -0
- package/src/network/rpc.ts +25 -0
- package/src/network/utils.test.ts +175 -0
- package/src/network/utils.ts +58 -0
- package/src/test/bridgeDatasetTest.ts +6 -2
- package/src/test/fixtures/account.fixture.ts +18 -0
- package/src/test/fixtures/currency.fixture.ts +1 -1
- package/src/test/fixtures/mirror.fixture.ts +1 -1
- package/src/test/fixtures/network.fixture.ts +6 -0
- package/src/test/fixtures/transaction.fixture.ts +5 -2
- package/src/transaction.ts +40 -9
- package/src/types/alpaca.ts +3 -0
- package/src/types/bridge.ts +36 -10
- package/src/types/index.ts +2 -0
- package/src/{api/types.ts → types/mirror.ts} +23 -1
- package/lib/api/mirror.d.ts +0 -6
- package/lib/api/mirror.d.ts.map +0 -1
- package/lib/api/mirror.js +0 -84
- package/lib/api/mirror.js.map +0 -1
- package/lib/api/network.d.ts +0 -11
- package/lib/api/network.d.ts.map +0 -1
- package/lib/api/network.js +0 -80
- package/lib/api/network.js.map +0 -1
- package/lib/api/types.d.ts.map +0 -1
- package/lib/api/types.js.map +0 -1
- package/lib/api/utils.d.ts.map +0 -1
- package/lib/api/utils.js +0 -132
- package/lib/api/utils.js.map +0 -1
- package/lib/logic.d.ts +0 -11
- package/lib/logic.d.ts.map +0 -1
- package/lib/logic.js +0 -37
- package/lib/logic.js.map +0 -1
- package/lib-es/api/mirror.d.ts +0 -6
- package/lib-es/api/mirror.d.ts.map +0 -1
- package/lib-es/api/mirror.js +0 -74
- package/lib-es/api/mirror.js.map +0 -1
- package/lib-es/api/network.d.ts +0 -11
- package/lib-es/api/network.d.ts.map +0 -1
- package/lib-es/api/network.js +0 -71
- package/lib-es/api/network.js.map +0 -1
- package/lib-es/api/types.d.ts.map +0 -1
- package/lib-es/api/types.js +0 -2
- package/lib-es/api/types.js.map +0 -1
- package/lib-es/api/utils.d.ts.map +0 -1
- package/lib-es/api/utils.js +0 -124
- package/lib-es/api/utils.js.map +0 -1
- package/lib-es/logic.d.ts +0 -11
- package/lib-es/logic.d.ts.map +0 -1
- package/lib-es/logic.js +0 -29
- package/lib-es/logic.js.map +0 -1
- package/src/api/mirror.ts +0 -91
- package/src/api/network.test.ts +0 -49
- package/src/api/network.ts +0 -125
- package/src/api/utils.ts +0 -150
- package/src/logic.test.ts +0 -152
- package/src/logic.ts +0 -66
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
|
|
2
|
+
import { encodeTokenAccountId } from "@ledgerhq/coin-framework/account/accountId";
|
|
3
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
4
|
+
import type { Pagination } from "@ledgerhq/coin-framework/api/types";
|
|
5
|
+
import { listOperations } from "./listOperations";
|
|
6
|
+
import { apiClient } from "../network/api";
|
|
7
|
+
import { getMockedCurrency } from "../test/fixtures/currency.fixture";
|
|
8
|
+
import * as utils from "./utils";
|
|
9
|
+
|
|
10
|
+
jest.mock("@ledgerhq/cryptoassets/tokens");
|
|
11
|
+
jest.mock("@ledgerhq/coin-framework/account/accountId");
|
|
12
|
+
jest.mock("@ledgerhq/coin-framework/operation");
|
|
13
|
+
jest.mock("../network/api");
|
|
14
|
+
jest.mock("./utils");
|
|
15
|
+
|
|
16
|
+
describe("listOperations", () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.clearAllMocks();
|
|
19
|
+
(utils.getMemoFromBase64 as jest.Mock).mockImplementation(memo =>
|
|
20
|
+
memo ? `decoded-${memo}` : null,
|
|
21
|
+
);
|
|
22
|
+
(encodeOperationId as jest.Mock).mockImplementation(
|
|
23
|
+
(accountId, hash, type) => `${accountId}-${hash}-${type}`,
|
|
24
|
+
);
|
|
25
|
+
(encodeTokenAccountId as jest.Mock).mockImplementation(
|
|
26
|
+
(accountId, token) => `${accountId}-${token.id}`,
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should return empty arrays when no transactions are found", async () => {
|
|
31
|
+
const address = "0.0.12345";
|
|
32
|
+
const mockCurrency = getMockedCurrency();
|
|
33
|
+
const pagination: Pagination = {
|
|
34
|
+
minHeight: 0,
|
|
35
|
+
limit: 10,
|
|
36
|
+
order: "asc",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
40
|
+
transactions: [],
|
|
41
|
+
nextCursor: null,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const result = await listOperations({
|
|
45
|
+
currency: mockCurrency,
|
|
46
|
+
address,
|
|
47
|
+
pagination,
|
|
48
|
+
mirrorTokens: [],
|
|
49
|
+
fetchAllPages: true,
|
|
50
|
+
skipFeesForTokenOperations: false,
|
|
51
|
+
useEncodedHash: false,
|
|
52
|
+
useSyntheticBlocks: false,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(apiClient.getAccountTransactions).toHaveBeenCalledTimes(1);
|
|
56
|
+
expect(apiClient.getAccountTransactions).toHaveBeenCalledWith({
|
|
57
|
+
address,
|
|
58
|
+
fetchAllPages: true,
|
|
59
|
+
pagingToken: null,
|
|
60
|
+
order: "asc",
|
|
61
|
+
limit: 10,
|
|
62
|
+
});
|
|
63
|
+
expect(result.coinOperations).toEqual([]);
|
|
64
|
+
expect(result.tokenOperations).toEqual([]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should parse HBAR transfer transactions correctly", async () => {
|
|
68
|
+
const address = "0.0.1234567";
|
|
69
|
+
const mockCurrency = getMockedCurrency();
|
|
70
|
+
const pagination: Pagination = {
|
|
71
|
+
minHeight: 0,
|
|
72
|
+
limit: 10,
|
|
73
|
+
order: "desc",
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const mockTransactions = [
|
|
77
|
+
{
|
|
78
|
+
consensus_timestamp: "1625097600.000000000",
|
|
79
|
+
transaction_hash: "hash1",
|
|
80
|
+
charged_tx_fee: 500000,
|
|
81
|
+
result: "SUCCESS",
|
|
82
|
+
memo_base64: "test-memo",
|
|
83
|
+
token_transfers: [],
|
|
84
|
+
transfers: [
|
|
85
|
+
{ account: address, amount: "-1000000" },
|
|
86
|
+
{ account: "0.0.67890", amount: "1000000" },
|
|
87
|
+
],
|
|
88
|
+
name: "CRYPTOTRANSFER",
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
93
|
+
transactions: mockTransactions,
|
|
94
|
+
nextCursor: null,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const result = await listOperations({
|
|
98
|
+
currency: mockCurrency,
|
|
99
|
+
address,
|
|
100
|
+
pagination,
|
|
101
|
+
mirrorTokens: [],
|
|
102
|
+
fetchAllPages: true,
|
|
103
|
+
skipFeesForTokenOperations: false,
|
|
104
|
+
useEncodedHash: false,
|
|
105
|
+
useSyntheticBlocks: false,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(result.coinOperations).toHaveLength(1);
|
|
109
|
+
expect(result.tokenOperations).toEqual([]);
|
|
110
|
+
|
|
111
|
+
expect(result.coinOperations).toMatchObject([
|
|
112
|
+
{
|
|
113
|
+
type: "OUT",
|
|
114
|
+
value: expect.any(Object),
|
|
115
|
+
hash: "hash1",
|
|
116
|
+
fee: expect.any(Object),
|
|
117
|
+
date: expect.any(Date),
|
|
118
|
+
senders: [address],
|
|
119
|
+
recipients: ["0.0.67890"],
|
|
120
|
+
extra: {
|
|
121
|
+
pagingToken: "1625097600.000000000",
|
|
122
|
+
consensusTimestamp: "1625097600.000000000",
|
|
123
|
+
memo: "decoded-test-memo",
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should parse token transfer transactions correctly", async () => {
|
|
130
|
+
const address = "0.0.12345";
|
|
131
|
+
const mockCurrency = getMockedCurrency();
|
|
132
|
+
const tokenId = "0.0.7890";
|
|
133
|
+
const pagination: Pagination = {
|
|
134
|
+
minHeight: 0,
|
|
135
|
+
limit: 10,
|
|
136
|
+
order: "desc",
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const mockToken = {
|
|
140
|
+
id: "token1",
|
|
141
|
+
contractAddress: tokenId,
|
|
142
|
+
standard: "hts",
|
|
143
|
+
name: "Test Token",
|
|
144
|
+
units: [{ name: "TT", code: "tt", magnitude: 6 }],
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const mockTransactions = [
|
|
148
|
+
{
|
|
149
|
+
consensus_timestamp: "1625097600.000000000",
|
|
150
|
+
transaction_hash: "hash1",
|
|
151
|
+
charged_tx_fee: 500000,
|
|
152
|
+
result: "SUCCESS",
|
|
153
|
+
token_transfers: [
|
|
154
|
+
{ token_id: tokenId, account: address, amount: "-1000" },
|
|
155
|
+
{ token_id: tokenId, account: "0.0.67890", amount: "1000" },
|
|
156
|
+
],
|
|
157
|
+
transfers: [],
|
|
158
|
+
name: "CRYPTOTRANSFER",
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
163
|
+
transactions: mockTransactions,
|
|
164
|
+
nextCursor: null,
|
|
165
|
+
});
|
|
166
|
+
(findTokenByAddressInCurrency as jest.Mock).mockReturnValue(mockToken);
|
|
167
|
+
|
|
168
|
+
const result = await listOperations({
|
|
169
|
+
currency: mockCurrency,
|
|
170
|
+
address,
|
|
171
|
+
pagination,
|
|
172
|
+
mirrorTokens: [],
|
|
173
|
+
fetchAllPages: true,
|
|
174
|
+
skipFeesForTokenOperations: false,
|
|
175
|
+
useEncodedHash: false,
|
|
176
|
+
useSyntheticBlocks: false,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(result.coinOperations).toHaveLength(1);
|
|
180
|
+
expect(result.tokenOperations).toHaveLength(1);
|
|
181
|
+
|
|
182
|
+
expect(result.coinOperations).toMatchObject([
|
|
183
|
+
{
|
|
184
|
+
type: "FEES",
|
|
185
|
+
fee: expect.any(Object),
|
|
186
|
+
},
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
expect(result.tokenOperations).toMatchObject([
|
|
190
|
+
{
|
|
191
|
+
type: "OUT",
|
|
192
|
+
value: expect.any(Object),
|
|
193
|
+
hash: "hash1",
|
|
194
|
+
contract: tokenId,
|
|
195
|
+
standard: "hts",
|
|
196
|
+
senders: [address],
|
|
197
|
+
recipients: ["0.0.67890"],
|
|
198
|
+
extra: {
|
|
199
|
+
pagingToken: "1625097600.000000000",
|
|
200
|
+
consensusTimestamp: "1625097600.000000000",
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
]);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("should parse token associate transactions correctly", async () => {
|
|
207
|
+
const address = "0.0.12345";
|
|
208
|
+
const mockCurrency = getMockedCurrency();
|
|
209
|
+
const pagination: Pagination = {
|
|
210
|
+
minHeight: 0,
|
|
211
|
+
limit: 10,
|
|
212
|
+
order: "desc",
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const mockTransactions = [
|
|
216
|
+
{
|
|
217
|
+
consensus_timestamp: "1625097600.000000000",
|
|
218
|
+
transaction_hash: "hash1",
|
|
219
|
+
charged_tx_fee: 500000,
|
|
220
|
+
result: "SUCCESS",
|
|
221
|
+
token_transfers: [],
|
|
222
|
+
transfers: [{ account: address, amount: "-500000" }],
|
|
223
|
+
name: "TOKENASSOCIATE",
|
|
224
|
+
},
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
228
|
+
transactions: mockTransactions,
|
|
229
|
+
nextCursor: null,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const result = await listOperations({
|
|
233
|
+
currency: mockCurrency,
|
|
234
|
+
address,
|
|
235
|
+
pagination,
|
|
236
|
+
mirrorTokens: [],
|
|
237
|
+
fetchAllPages: true,
|
|
238
|
+
skipFeesForTokenOperations: false,
|
|
239
|
+
useEncodedHash: false,
|
|
240
|
+
useSyntheticBlocks: false,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
expect(result.coinOperations).toHaveLength(1);
|
|
244
|
+
expect(result.tokenOperations).toHaveLength(0);
|
|
245
|
+
|
|
246
|
+
expect(result.coinOperations).toMatchObject([
|
|
247
|
+
{
|
|
248
|
+
type: "ASSOCIATE_TOKEN",
|
|
249
|
+
value: expect.any(Object),
|
|
250
|
+
hash: "hash1",
|
|
251
|
+
fee: expect.any(Object),
|
|
252
|
+
senders: [address],
|
|
253
|
+
recipients: [],
|
|
254
|
+
extra: {
|
|
255
|
+
pagingToken: "1625097600.000000000",
|
|
256
|
+
consensusTimestamp: "1625097600.000000000",
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
]);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("should skip token operations when token is not found in cryptoassets", async () => {
|
|
263
|
+
const address = "0.0.12345";
|
|
264
|
+
const mockCurrency = getMockedCurrency();
|
|
265
|
+
const tokenId = "0.0.7890";
|
|
266
|
+
const pagination: Pagination = {
|
|
267
|
+
minHeight: 0,
|
|
268
|
+
limit: 10,
|
|
269
|
+
order: "desc",
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const mockTransactions = [
|
|
273
|
+
{
|
|
274
|
+
consensus_timestamp: "1625097600.000000000",
|
|
275
|
+
transaction_hash: "hash1",
|
|
276
|
+
charged_tx_fee: 500000,
|
|
277
|
+
result: "SUCCESS",
|
|
278
|
+
token_transfers: [
|
|
279
|
+
{ token_id: tokenId, account: address, amount: "-1000" },
|
|
280
|
+
{ token_id: tokenId, account: "0.0.67890", amount: "1000" },
|
|
281
|
+
],
|
|
282
|
+
transfers: [],
|
|
283
|
+
name: "CRYPTOTRANSFER",
|
|
284
|
+
},
|
|
285
|
+
];
|
|
286
|
+
|
|
287
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
288
|
+
transactions: mockTransactions,
|
|
289
|
+
nextCursor: null,
|
|
290
|
+
});
|
|
291
|
+
(findTokenByAddressInCurrency as jest.Mock).mockReturnValue(null);
|
|
292
|
+
|
|
293
|
+
const result = await listOperations({
|
|
294
|
+
currency: mockCurrency,
|
|
295
|
+
address,
|
|
296
|
+
pagination,
|
|
297
|
+
mirrorTokens: [],
|
|
298
|
+
fetchAllPages: true,
|
|
299
|
+
skipFeesForTokenOperations: false,
|
|
300
|
+
useEncodedHash: false,
|
|
301
|
+
useSyntheticBlocks: false,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
expect(result.coinOperations).toHaveLength(0);
|
|
305
|
+
expect(result.tokenOperations).toHaveLength(0);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should use pagination parameters correctly", async () => {
|
|
309
|
+
const address = "0.0.12345";
|
|
310
|
+
const mockCurrency = getMockedCurrency();
|
|
311
|
+
const pagination: Pagination = {
|
|
312
|
+
minHeight: 0,
|
|
313
|
+
limit: 20,
|
|
314
|
+
order: "asc",
|
|
315
|
+
lastPagingToken: "1625097500.000000000",
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
319
|
+
transactions: [],
|
|
320
|
+
nextCursor: null,
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
await listOperations({
|
|
324
|
+
currency: mockCurrency,
|
|
325
|
+
address,
|
|
326
|
+
pagination,
|
|
327
|
+
mirrorTokens: [],
|
|
328
|
+
fetchAllPages: true,
|
|
329
|
+
skipFeesForTokenOperations: false,
|
|
330
|
+
useEncodedHash: false,
|
|
331
|
+
useSyntheticBlocks: false,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
expect(apiClient.getAccountTransactions).toHaveBeenCalledTimes(1);
|
|
335
|
+
expect(apiClient.getAccountTransactions).toHaveBeenCalledWith({
|
|
336
|
+
address,
|
|
337
|
+
fetchAllPages: true,
|
|
338
|
+
pagingToken: "1625097500.000000000",
|
|
339
|
+
order: "asc",
|
|
340
|
+
limit: 20,
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("should handle failed transactions", async () => {
|
|
345
|
+
const address = "0.0.12345";
|
|
346
|
+
const mockCurrency = getMockedCurrency();
|
|
347
|
+
const pagination: Pagination = {
|
|
348
|
+
minHeight: 0,
|
|
349
|
+
limit: 10,
|
|
350
|
+
order: "desc",
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const mockTransactions = [
|
|
354
|
+
{
|
|
355
|
+
consensus_timestamp: "1625097600.000000000",
|
|
356
|
+
transaction_hash: "hash1",
|
|
357
|
+
charged_tx_fee: 500000,
|
|
358
|
+
result: "INVALID_SIGNATURE",
|
|
359
|
+
memo_base64: null,
|
|
360
|
+
token_transfers: [],
|
|
361
|
+
transfers: [
|
|
362
|
+
{ account: address, amount: "-1000000" },
|
|
363
|
+
{ account: "0.0.67890", amount: "1000000" },
|
|
364
|
+
],
|
|
365
|
+
name: "CRYPTOTRANSFER",
|
|
366
|
+
},
|
|
367
|
+
];
|
|
368
|
+
|
|
369
|
+
(apiClient.getAccountTransactions as jest.Mock).mockResolvedValue({
|
|
370
|
+
transactions: mockTransactions,
|
|
371
|
+
nextCursor: null,
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const result = await listOperations({
|
|
375
|
+
currency: mockCurrency,
|
|
376
|
+
address,
|
|
377
|
+
pagination,
|
|
378
|
+
mirrorTokens: [],
|
|
379
|
+
fetchAllPages: true,
|
|
380
|
+
skipFeesForTokenOperations: false,
|
|
381
|
+
useEncodedHash: false,
|
|
382
|
+
useSyntheticBlocks: false,
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
expect(result.coinOperations).toHaveLength(1);
|
|
386
|
+
expect(result.coinOperations[0].hasFailed).toBe(true);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { Operation } from "@ledgerhq/types-live";
|
|
3
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
|
+
import type { Pagination } from "@ledgerhq/coin-framework/api/types";
|
|
5
|
+
import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets/tokens";
|
|
6
|
+
import { encodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/accountId";
|
|
7
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
8
|
+
import { apiClient } from "../network/api";
|
|
9
|
+
import { parseTransfers } from "../network/utils";
|
|
10
|
+
import type { HederaMirrorToken, HederaMirrorTransaction, HederaOperationExtra } from "../types";
|
|
11
|
+
import { base64ToUrlSafeBase64, getMemoFromBase64, getSyntheticBlock } from "./utils";
|
|
12
|
+
|
|
13
|
+
function getCommonOperationData(
|
|
14
|
+
rawTx: HederaMirrorTransaction,
|
|
15
|
+
useEncodedHash: boolean,
|
|
16
|
+
useSyntheticBlocks: boolean,
|
|
17
|
+
) {
|
|
18
|
+
const timestamp = new Date(Number.parseInt(rawTx.consensus_timestamp.split(".")[0], 10) * 1000);
|
|
19
|
+
const hash = useEncodedHash
|
|
20
|
+
? base64ToUrlSafeBase64(rawTx.transaction_hash)
|
|
21
|
+
: rawTx.transaction_hash;
|
|
22
|
+
const fee = new BigNumber(rawTx.charged_tx_fee);
|
|
23
|
+
const hasFailed = rawTx.result !== "SUCCESS";
|
|
24
|
+
const syntheticBlock = getSyntheticBlock(rawTx.consensus_timestamp);
|
|
25
|
+
const memo = getMemoFromBase64(rawTx.memo_base64);
|
|
26
|
+
const extra: HederaOperationExtra = {
|
|
27
|
+
pagingToken: rawTx.consensus_timestamp,
|
|
28
|
+
consensusTimestamp: rawTx.consensus_timestamp,
|
|
29
|
+
...(memo && { memo }),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
timestamp,
|
|
34
|
+
hash,
|
|
35
|
+
fee,
|
|
36
|
+
hasFailed,
|
|
37
|
+
blockHeight: useSyntheticBlocks ? syntheticBlock.blockHeight : 10,
|
|
38
|
+
blockHash: useSyntheticBlocks ? syntheticBlock.blockHash : null,
|
|
39
|
+
extra,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function processTokenTransfers({
|
|
44
|
+
rawTx,
|
|
45
|
+
address,
|
|
46
|
+
currency,
|
|
47
|
+
ledgerAccountId,
|
|
48
|
+
commonData,
|
|
49
|
+
skipFeesForTokenOperations,
|
|
50
|
+
}: {
|
|
51
|
+
rawTx: HederaMirrorTransaction;
|
|
52
|
+
address: string;
|
|
53
|
+
currency: CryptoCurrency;
|
|
54
|
+
ledgerAccountId: string;
|
|
55
|
+
commonData: ReturnType<typeof getCommonOperationData>;
|
|
56
|
+
skipFeesForTokenOperations: boolean;
|
|
57
|
+
}): {
|
|
58
|
+
coinOperation: Operation<HederaOperationExtra> | undefined;
|
|
59
|
+
tokenOperation: Operation<HederaOperationExtra>;
|
|
60
|
+
} | null {
|
|
61
|
+
const tokenTransfers = rawTx.token_transfers ?? [];
|
|
62
|
+
if (tokenTransfers.length === 0) return null;
|
|
63
|
+
|
|
64
|
+
const tokenId = tokenTransfers[0].token_id;
|
|
65
|
+
const token = findTokenByAddressInCurrency(tokenId, currency.id);
|
|
66
|
+
if (!token) return null;
|
|
67
|
+
|
|
68
|
+
const encodedTokenId = encodeTokenAccountId(ledgerAccountId, token);
|
|
69
|
+
const { type, value, senders, recipients } = parseTransfers(tokenTransfers, address);
|
|
70
|
+
const { hash, fee, timestamp, blockHeight, blockHash, hasFailed } = commonData;
|
|
71
|
+
const extra = { ...commonData.extra };
|
|
72
|
+
|
|
73
|
+
let coinOperation: Operation<HederaOperationExtra> | undefined;
|
|
74
|
+
|
|
75
|
+
// Add main FEES coin operation for send token transfer
|
|
76
|
+
if (type === "OUT" && !skipFeesForTokenOperations) {
|
|
77
|
+
coinOperation = {
|
|
78
|
+
id: encodeOperationId(ledgerAccountId, hash, "FEES"),
|
|
79
|
+
accountId: ledgerAccountId,
|
|
80
|
+
type: "FEES",
|
|
81
|
+
value: fee,
|
|
82
|
+
recipients,
|
|
83
|
+
senders,
|
|
84
|
+
hash,
|
|
85
|
+
fee,
|
|
86
|
+
date: timestamp,
|
|
87
|
+
blockHeight,
|
|
88
|
+
blockHash,
|
|
89
|
+
hasFailed,
|
|
90
|
+
extra,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const tokenOperation = {
|
|
95
|
+
id: encodeOperationId(encodedTokenId, hash, type),
|
|
96
|
+
accountId: encodedTokenId,
|
|
97
|
+
contract: token.contractAddress,
|
|
98
|
+
standard: "hts",
|
|
99
|
+
type,
|
|
100
|
+
value,
|
|
101
|
+
recipients,
|
|
102
|
+
senders,
|
|
103
|
+
hash,
|
|
104
|
+
fee,
|
|
105
|
+
date: timestamp,
|
|
106
|
+
blockHeight,
|
|
107
|
+
blockHash,
|
|
108
|
+
hasFailed,
|
|
109
|
+
extra,
|
|
110
|
+
} satisfies Operation<HederaOperationExtra>;
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
coinOperation,
|
|
114
|
+
tokenOperation,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function processTransfers({
|
|
119
|
+
rawTx,
|
|
120
|
+
address,
|
|
121
|
+
ledgerAccountId,
|
|
122
|
+
commonData,
|
|
123
|
+
mirrorTokens,
|
|
124
|
+
}: {
|
|
125
|
+
rawTx: HederaMirrorTransaction;
|
|
126
|
+
address: string;
|
|
127
|
+
ledgerAccountId: string;
|
|
128
|
+
commonData: ReturnType<typeof getCommonOperationData>;
|
|
129
|
+
mirrorTokens: HederaMirrorToken[];
|
|
130
|
+
}): Operation<HederaOperationExtra> | null {
|
|
131
|
+
const transfers = rawTx.transfers ?? [];
|
|
132
|
+
if (transfers.length === 0) return null;
|
|
133
|
+
|
|
134
|
+
const { type, value, senders, recipients } = parseTransfers(transfers, address);
|
|
135
|
+
const { hash, fee, timestamp, blockHeight, blockHash, hasFailed } = commonData;
|
|
136
|
+
const extra = { ...commonData.extra };
|
|
137
|
+
let operationType = type;
|
|
138
|
+
|
|
139
|
+
// try to enrich ASSOCIATE_TOKEN operation with extra.associatedTokenId
|
|
140
|
+
// this value is used by custom OperationDetails components in Hedera family
|
|
141
|
+
// accounts or contracts must first associate with an HTS token before they can receive or send that token; without association, token transfers fail
|
|
142
|
+
if (rawTx.name === "TOKENASSOCIATE") {
|
|
143
|
+
operationType = "ASSOCIATE_TOKEN";
|
|
144
|
+
|
|
145
|
+
const relatedMirrorToken = mirrorTokens.find(t => {
|
|
146
|
+
return t.created_timestamp === rawTx.consensus_timestamp;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
if (relatedMirrorToken) {
|
|
150
|
+
extra.associatedTokenId = relatedMirrorToken.token_id;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
id: encodeOperationId(ledgerAccountId, hash, operationType),
|
|
156
|
+
accountId: ledgerAccountId,
|
|
157
|
+
type: operationType,
|
|
158
|
+
value,
|
|
159
|
+
recipients,
|
|
160
|
+
senders,
|
|
161
|
+
hash,
|
|
162
|
+
fee,
|
|
163
|
+
date: timestamp,
|
|
164
|
+
blockHeight,
|
|
165
|
+
blockHash,
|
|
166
|
+
hasFailed,
|
|
167
|
+
extra,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function listOperations({
|
|
172
|
+
currency,
|
|
173
|
+
address,
|
|
174
|
+
mirrorTokens,
|
|
175
|
+
pagination,
|
|
176
|
+
fetchAllPages,
|
|
177
|
+
skipFeesForTokenOperations,
|
|
178
|
+
useEncodedHash,
|
|
179
|
+
useSyntheticBlocks,
|
|
180
|
+
}: {
|
|
181
|
+
currency: CryptoCurrency;
|
|
182
|
+
address: string;
|
|
183
|
+
mirrorTokens: HederaMirrorToken[];
|
|
184
|
+
pagination: Pagination;
|
|
185
|
+
// options for compatibility with old bridge
|
|
186
|
+
fetchAllPages: boolean;
|
|
187
|
+
skipFeesForTokenOperations: boolean;
|
|
188
|
+
useEncodedHash: boolean;
|
|
189
|
+
useSyntheticBlocks: boolean;
|
|
190
|
+
}): Promise<{
|
|
191
|
+
coinOperations: Operation<HederaOperationExtra>[];
|
|
192
|
+
tokenOperations: Operation<HederaOperationExtra>[];
|
|
193
|
+
nextCursor: string | null;
|
|
194
|
+
}> {
|
|
195
|
+
const coinOperations: Operation<HederaOperationExtra>[] = [];
|
|
196
|
+
const tokenOperations: Operation<HederaOperationExtra>[] = [];
|
|
197
|
+
const mirrorResult = await apiClient.getAccountTransactions({
|
|
198
|
+
address,
|
|
199
|
+
pagingToken: pagination.lastPagingToken ?? null,
|
|
200
|
+
order: pagination.order,
|
|
201
|
+
limit: pagination.limit,
|
|
202
|
+
fetchAllPages,
|
|
203
|
+
});
|
|
204
|
+
const ledgerAccountId = encodeAccountId({
|
|
205
|
+
type: "js",
|
|
206
|
+
version: "2",
|
|
207
|
+
currencyId: currency.id,
|
|
208
|
+
xpubOrAddress: address,
|
|
209
|
+
derivationMode: "hederaBip44",
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
for (const rawTx of mirrorResult.transactions) {
|
|
213
|
+
const commonData = getCommonOperationData(rawTx, useEncodedHash, useSyntheticBlocks);
|
|
214
|
+
|
|
215
|
+
// process token transfers
|
|
216
|
+
const tokenResult = processTokenTransfers({
|
|
217
|
+
rawTx,
|
|
218
|
+
address,
|
|
219
|
+
currency,
|
|
220
|
+
ledgerAccountId,
|
|
221
|
+
commonData,
|
|
222
|
+
skipFeesForTokenOperations,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
if (tokenResult?.coinOperation) coinOperations.push(tokenResult.coinOperation);
|
|
226
|
+
if (tokenResult?.tokenOperation) tokenOperations.push(tokenResult.tokenOperation);
|
|
227
|
+
|
|
228
|
+
// process regular transfers only if there were no token transfers
|
|
229
|
+
if (!tokenResult) {
|
|
230
|
+
const coinOperation = processTransfers({
|
|
231
|
+
rawTx,
|
|
232
|
+
address,
|
|
233
|
+
ledgerAccountId,
|
|
234
|
+
commonData,
|
|
235
|
+
mirrorTokens,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (coinOperation) coinOperations.push(coinOperation);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
coinOperations,
|
|
244
|
+
tokenOperations,
|
|
245
|
+
nextCursor: mirrorResult.nextCursor,
|
|
246
|
+
};
|
|
247
|
+
}
|