@ledgerhq/coin-tezos 6.6.0-nightly.1 → 6.6.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +30 -4
- package/CHANGELOG.md +17 -8
- package/jest.integ.config.js +0 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +40 -188
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +10 -79
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +5 -7
- package/lib/api/types.d.ts.map +1 -1
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +11 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/broadcast.test.d.ts +2 -0
- package/lib/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/bridge/broadcast.test.js +36 -0
- package/lib/bridge/broadcast.test.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +28 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +30 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +21 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +39 -0
- package/lib/bridge/getFeesForTransaction.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +108 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.test.js +107 -0
- package/lib/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/bridge/index.d.ts +10 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +59 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/logic.d.ts +10 -0
- package/lib/bridge/logic.d.ts.map +1 -0
- package/lib/bridge/logic.js +155 -0
- package/lib/bridge/logic.js.map +1 -0
- package/lib/bridge/preload.d.ts +9 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +23 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +5 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.integ.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.integ.test.js +34 -0
- package/lib/bridge/prepareTransaction.integ.test.js.map +1 -0
- package/lib/bridge/prepareTransaction.js +57 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.test.js +178 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/serialization.d.ts +7 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +26 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +16 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +88 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/signOperation.test.d.ts +2 -0
- package/lib/bridge/signOperation.test.d.ts.map +1 -0
- package/lib/bridge/signOperation.test.js +283 -0
- package/lib/bridge/signOperation.test.js.map +1 -0
- package/lib/bridge/synchronization.d.ts +5 -0
- package/lib/bridge/synchronization.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.d.ts +2 -0
- package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.js +32 -0
- package/lib/bridge/synchronization.integ.test.js.map +1 -0
- package/lib/bridge/synchronization.js +100 -0
- package/lib/bridge/synchronization.js.map +1 -0
- package/lib/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/{transaction.js → bridge/transaction.js} +3 -3
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +3 -4
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +0 -7
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +0 -1
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.integ.test.js +2 -8
- package/lib/logic/estimateFees.integ.test.js.map +1 -1
- package/lib/logic/estimateFees.js +45 -119
- 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/index.d.ts +0 -2
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +1 -5
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +10 -56
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +10 -14
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/types/bridge.d.ts +0 -3
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/bridge.fixture.d.ts.map +1 -1
- package/lib/types/bridge.fixture.js +0 -1
- package/lib/types/bridge.fixture.js.map +1 -1
- package/lib/types/bridge.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +41 -189
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +10 -79
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +5 -7
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +7 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.test.js +31 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +21 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +17 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +23 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +21 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +33 -0
- package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +101 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.js +102 -0
- package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/bridge/index.d.ts +10 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +53 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/logic.d.ts +10 -0
- package/lib-es/bridge/logic.d.ts.map +1 -0
- package/lib-es/bridge/logic.js +145 -0
- package/lib-es/bridge/logic.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +9 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +17 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +5 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.integ.test.js +29 -0
- package/lib-es/bridge/prepareTransaction.integ.test.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +50 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.js +173 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +7 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +20 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +16 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +83 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/signOperation.test.d.ts +2 -0
- package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.test.js +255 -0
- package/lib-es/bridge/signOperation.test.js.map +1 -0
- package/lib-es/bridge/synchronization.d.ts +5 -0
- package/lib-es/bridge/synchronization.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts +2 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.js +27 -0
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
- package/lib-es/bridge/synchronization.js +70 -0
- package/lib-es/bridge/synchronization.js.map +1 -0
- package/lib-es/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/{transaction.js → bridge/transaction.js} +3 -3
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +3 -4
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/index.d.ts +1 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +0 -7
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +0 -1
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.integ.test.js +2 -8
- package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +45 -119
- 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/index.d.ts +0 -2
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +0 -2
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +10 -56
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +10 -14
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/types/bridge.d.ts +0 -3
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.js +0 -1
- package/lib-es/types/bridge.fixture.js.map +1 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/package.json +14 -11
- package/src/api/index.test.ts +15 -87
- package/src/api/index.ts +55 -204
- package/src/api/types.ts +6 -11
- package/src/bridge/broadcast.test.ts +36 -0
- package/src/bridge/broadcast.ts +13 -0
- package/src/bridge/buildOptimisticOperation.ts +28 -0
- package/src/bridge/createTransaction.ts +19 -0
- package/src/bridge/estimateMaxSpendable.ts +37 -0
- package/src/bridge/getFeesForTransaction.ts +49 -0
- package/src/bridge/getTransactionStatus.test.ts +124 -0
- package/src/bridge/getTransactionStatus.ts +123 -0
- package/src/bridge/index.ts +74 -0
- package/src/bridge/logic.ts +171 -0
- package/src/bridge/preload.ts +18 -0
- package/src/bridge/prepareTransaction.integ.test.ts +35 -0
- package/src/bridge/prepareTransaction.test.ts +205 -0
- package/src/bridge/prepareTransaction.ts +69 -0
- package/src/bridge/serialization.ts +27 -0
- package/src/bridge/signOperation.test.ts +284 -0
- package/src/bridge/signOperation.ts +130 -0
- package/src/bridge/synchronization.integ.test.ts +33 -0
- package/src/bridge/synchronization.ts +100 -0
- package/src/{transaction.ts → bridge/transaction.ts} +4 -4
- package/src/config.ts +2 -9
- package/src/index.ts +2 -1
- package/src/logic/craftTransaction.test.ts +0 -1
- package/src/logic/craftTransaction.ts +0 -8
- package/src/logic/estimateFees.integ.test.ts +2 -8
- package/src/logic/estimateFees.ts +49 -140
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/index.ts +0 -2
- package/src/logic/listOperations.test.ts +54 -64
- package/src/logic/listOperations.ts +9 -57
- package/src/types/bridge.fixture.ts +0 -1
- package/src/types/bridge.ts +1 -6
- package/lib/logic/getStakes.d.ts +0 -3
- package/lib/logic/getStakes.d.ts.map +0 -1
- package/lib/logic/getStakes.js +0 -26
- package/lib/logic/getStakes.js.map +0 -1
- package/lib/logic/getStakes.test.d.ts +0 -2
- package/lib/logic/getStakes.test.d.ts.map +0 -1
- package/lib/logic/getStakes.test.js +0 -133
- package/lib/logic/getStakes.test.js.map +0 -1
- package/lib/logic/validateIntent.d.ts +0 -3
- package/lib/logic/validateIntent.d.ts.map +0 -1
- package/lib/logic/validateIntent.js +0 -179
- package/lib/logic/validateIntent.js.map +0 -1
- package/lib/logic/validateIntent.test.d.ts +0 -2
- package/lib/logic/validateIntent.test.d.ts.map +0 -1
- package/lib/logic/validateIntent.test.js +0 -249
- package/lib/logic/validateIntent.test.js.map +0 -1
- package/lib/transaction.d.ts.map +0 -1
- package/lib/transaction.js.map +0 -1
- package/lib/utils.d.ts +0 -48
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -112
- package/lib/utils.js.map +0 -1
- package/lib-es/logic/getStakes.d.ts +0 -3
- package/lib-es/logic/getStakes.d.ts.map +0 -1
- package/lib-es/logic/getStakes.js +0 -20
- package/lib-es/logic/getStakes.js.map +0 -1
- package/lib-es/logic/getStakes.test.d.ts +0 -2
- package/lib-es/logic/getStakes.test.d.ts.map +0 -1
- package/lib-es/logic/getStakes.test.js +0 -128
- package/lib-es/logic/getStakes.test.js.map +0 -1
- package/lib-es/logic/validateIntent.d.ts +0 -3
- package/lib-es/logic/validateIntent.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.js +0 -173
- package/lib-es/logic/validateIntent.js.map +0 -1
- package/lib-es/logic/validateIntent.test.d.ts +0 -2
- package/lib-es/logic/validateIntent.test.d.ts.map +0 -1
- package/lib-es/logic/validateIntent.test.js +0 -221
- package/lib-es/logic/validateIntent.test.js.map +0 -1
- package/lib-es/transaction.d.ts.map +0 -1
- package/lib-es/transaction.js.map +0 -1
- package/lib-es/utils.d.ts +0 -48
- package/lib-es/utils.d.ts.map +0 -1
- package/lib-es/utils.js +0 -105
- package/lib-es/utils.js.map +0 -1
- package/src/logic/getStakes.test.ts +0 -145
- package/src/logic/getStakes.ts +0 -20
- package/src/logic/validateIntent.test.ts +0 -262
- package/src/logic/validateIntent.ts +0 -207
- package/src/utils.ts +0 -115
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { TezosAccount, Transaction } from "../types";
|
|
3
|
+
import { estimateFees } from "../logic";
|
|
4
|
+
|
|
5
|
+
export type EstimatedFees = {
|
|
6
|
+
fees: BigNumber;
|
|
7
|
+
gasLimit: BigNumber;
|
|
8
|
+
storageLimit: BigNumber;
|
|
9
|
+
estimatedFees: BigNumber;
|
|
10
|
+
amount?: BigNumber;
|
|
11
|
+
taquitoError?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Fetch the transaction fees for a transaction
|
|
15
|
+
*
|
|
16
|
+
* @param {Account} a
|
|
17
|
+
* @param {Transaction} t
|
|
18
|
+
*/
|
|
19
|
+
export default async function getEstimatedFees({
|
|
20
|
+
account,
|
|
21
|
+
transaction,
|
|
22
|
+
}: {
|
|
23
|
+
account: TezosAccount;
|
|
24
|
+
transaction: Transaction;
|
|
25
|
+
}): Promise<EstimatedFees> {
|
|
26
|
+
const estimate = await estimateFees({
|
|
27
|
+
account: {
|
|
28
|
+
xpub: account.xpub,
|
|
29
|
+
address: account.freshAddress,
|
|
30
|
+
balance: BigInt(account.balance.toString()),
|
|
31
|
+
revealed: account.tezosResources.revealed,
|
|
32
|
+
},
|
|
33
|
+
transaction: {
|
|
34
|
+
mode: transaction.mode,
|
|
35
|
+
recipient: transaction.recipient,
|
|
36
|
+
amount: BigInt(transaction.amount.toString()),
|
|
37
|
+
useAllAmount: transaction.useAllAmount,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
fees: BigNumber(estimate.fees.toString()),
|
|
43
|
+
gasLimit: BigNumber(estimate.gasLimit.toString()),
|
|
44
|
+
storageLimit: BigNumber(estimate.storageLimit.toString()),
|
|
45
|
+
estimatedFees: BigNumber(estimate.estimatedFees.toString()),
|
|
46
|
+
amount: estimate.amount !== undefined ? BigNumber(estimate.amount.toString()) : BigNumber(0),
|
|
47
|
+
taquitoError: estimate.taquitoError,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
3
|
+
import { validateRecipient } from "../logic";
|
|
4
|
+
import { isAccountDelegating } from "../network/bakers";
|
|
5
|
+
import api from "../network/tzkt";
|
|
6
|
+
import {
|
|
7
|
+
AmountRequired,
|
|
8
|
+
FeeTooHigh,
|
|
9
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
10
|
+
NotEnoughBalance,
|
|
11
|
+
NotEnoughBalanceBecauseDestinationNotCreated,
|
|
12
|
+
RecommendUndelegation,
|
|
13
|
+
} from "@ledgerhq/errors";
|
|
14
|
+
import { TezosAccount, Transaction } from "../types";
|
|
15
|
+
|
|
16
|
+
jest.mock("../logic", () => ({
|
|
17
|
+
validateRecipient: jest.fn(),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
jest.mock("../network/bakers", () => ({
|
|
21
|
+
isAccountDelegating: jest.fn(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
jest.mock("../network/tzkt", () => ({
|
|
25
|
+
getAccountByAddress: jest.fn(),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
describe("getTransactionStatus", () => {
|
|
29
|
+
const mockAccount = {
|
|
30
|
+
type: "Account",
|
|
31
|
+
freshAddress: "tz1SourceAddress",
|
|
32
|
+
balance: new BigNumber(1000000),
|
|
33
|
+
currency: {
|
|
34
|
+
type: "CryptoCurrency",
|
|
35
|
+
units: [
|
|
36
|
+
{
|
|
37
|
+
name: "tezos",
|
|
38
|
+
code: "XTZ",
|
|
39
|
+
magnitude: 6,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
tezosResources: {
|
|
44
|
+
revealed: true,
|
|
45
|
+
counter: 0,
|
|
46
|
+
},
|
|
47
|
+
} as unknown as TezosAccount;
|
|
48
|
+
|
|
49
|
+
const mockTransaction = {
|
|
50
|
+
family: "tezos",
|
|
51
|
+
mode: "send",
|
|
52
|
+
amount: new BigNumber(500000),
|
|
53
|
+
recipient: "tz1RecipientAddress",
|
|
54
|
+
estimatedFees: new BigNumber(1000),
|
|
55
|
+
useAllAmount: false,
|
|
56
|
+
} as Transaction;
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
jest.clearAllMocks();
|
|
60
|
+
(validateRecipient as jest.Mock).mockResolvedValue({
|
|
61
|
+
recipientError: null,
|
|
62
|
+
recipientWarning: null,
|
|
63
|
+
});
|
|
64
|
+
(api.getAccountByAddress as jest.Mock).mockResolvedValue({ type: "empty" });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should return an error if the recipient is the same as the source address", async () => {
|
|
68
|
+
const transaction = { ...mockTransaction, recipient: mockAccount.freshAddress };
|
|
69
|
+
const result = await getTransactionStatus(mockAccount, transaction);
|
|
70
|
+
expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should return an error if the amount is zero and useAllAmount is false", async () => {
|
|
74
|
+
const transaction = { ...mockTransaction, amount: new BigNumber(0) };
|
|
75
|
+
const result = await getTransactionStatus(mockAccount, transaction);
|
|
76
|
+
expect(result.errors.amount).toBeInstanceOf(AmountRequired);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should return a warning if the fees are too high compared to the amount", async () => {
|
|
80
|
+
const transaction = { ...mockTransaction, amount: new BigNumber(1000) };
|
|
81
|
+
const result = await getTransactionStatus(mockAccount, transaction);
|
|
82
|
+
expect(result.warnings.feeTooHigh).toBeInstanceOf(FeeTooHigh);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("should return a warning if the balance after transaction is below the threshold", async () => {
|
|
86
|
+
(isAccountDelegating as jest.Mock).mockReturnValue(true);
|
|
87
|
+
const transaction = { ...mockTransaction, amount: new BigNumber(999000) };
|
|
88
|
+
const result = await getTransactionStatus(mockAccount, transaction);
|
|
89
|
+
expect(result.warnings.amount).toBeInstanceOf(RecommendUndelegation);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should map taquito errors to appropriate errors", async () => {
|
|
93
|
+
const transaction = { ...mockTransaction, taquitoError: "balance_too_low" };
|
|
94
|
+
const result = await getTransactionStatus(mockAccount, transaction);
|
|
95
|
+
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should return an error if the account balance is zero or less", async () => {
|
|
99
|
+
const account = { ...mockAccount, balance: new BigNumber(0) };
|
|
100
|
+
const result = await getTransactionStatus(account, mockTransaction);
|
|
101
|
+
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should return an error if the account balance is less than the estimated fees for delegation", async () => {
|
|
105
|
+
const transaction = { ...mockTransaction, mode: "delegate" } as Transaction;
|
|
106
|
+
const account = { ...mockAccount, balance: new BigNumber(500) };
|
|
107
|
+
const result = await getTransactionStatus(account, transaction);
|
|
108
|
+
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should return an error if the recipient account is empty and the amount is below the existential deposit", async () => {
|
|
112
|
+
const transaction = { ...mockTransaction, amount: new BigNumber(100000) };
|
|
113
|
+
const result = await getTransactionStatus(mockAccount, transaction);
|
|
114
|
+
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalanceBecauseDestinationNotCreated);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should return no errors or warnings for a valid transaction", async () => {
|
|
118
|
+
const account = { ...mockAccount, balance: new BigNumber(2000000) };
|
|
119
|
+
const transaction = { ...mockTransaction, amount: new BigNumber(500000) };
|
|
120
|
+
const result = await getTransactionStatus(account, transaction);
|
|
121
|
+
expect(result.errors).toEqual({});
|
|
122
|
+
expect(result.warnings).toEqual({});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AmountRequired,
|
|
3
|
+
FeeTooHigh,
|
|
4
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
5
|
+
NotEnoughBalance,
|
|
6
|
+
NotEnoughBalanceBecauseDestinationNotCreated,
|
|
7
|
+
NotEnoughBalanceToDelegate,
|
|
8
|
+
RecommendUndelegation,
|
|
9
|
+
} from "@ledgerhq/errors";
|
|
10
|
+
import { log } from "@ledgerhq/logs";
|
|
11
|
+
import BigNumber from "bignumber.js";
|
|
12
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
13
|
+
import { InvalidAddressBecauseAlreadyDelegated } from "../types/errors";
|
|
14
|
+
import { validateRecipient } from "../logic";
|
|
15
|
+
import { isAccountDelegating } from "../network/bakers";
|
|
16
|
+
import api from "../network/tzkt";
|
|
17
|
+
import { Transaction } from "../types";
|
|
18
|
+
|
|
19
|
+
const EXISTENTIAL_DEPOSIT = new BigNumber(275000);
|
|
20
|
+
|
|
21
|
+
export const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"] = async (
|
|
22
|
+
account,
|
|
23
|
+
transaction,
|
|
24
|
+
) => {
|
|
25
|
+
const errors: Record<string, Error> = {};
|
|
26
|
+
const warnings: Record<string, Error> = {};
|
|
27
|
+
let resetTotalSpent = false;
|
|
28
|
+
|
|
29
|
+
// Recipient validation logic
|
|
30
|
+
if (transaction.mode !== "undelegate") {
|
|
31
|
+
if (account.freshAddress === transaction.recipient) {
|
|
32
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
33
|
+
} else {
|
|
34
|
+
const { recipientError, recipientWarning } = await validateRecipient(transaction.recipient);
|
|
35
|
+
if (recipientError) {
|
|
36
|
+
errors.recipient = recipientError;
|
|
37
|
+
}
|
|
38
|
+
if (recipientWarning) {
|
|
39
|
+
warnings.recipient = recipientWarning;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Pre validation of amount field
|
|
45
|
+
const estimatedFees = transaction.estimatedFees || new BigNumber(0);
|
|
46
|
+
if (transaction.mode === "send") {
|
|
47
|
+
if (!errors.amount && transaction.amount.eq(0) && !transaction.useAllAmount) {
|
|
48
|
+
resetTotalSpent = true;
|
|
49
|
+
errors.amount = new AmountRequired();
|
|
50
|
+
} else if (transaction.amount.gt(0) && estimatedFees.times(10).gt(transaction.amount)) {
|
|
51
|
+
warnings.feeTooHigh = new FeeTooHigh();
|
|
52
|
+
}
|
|
53
|
+
const thresholdWarning = 0.5 * 10 ** account.currency.units[0].magnitude;
|
|
54
|
+
if (
|
|
55
|
+
!errors.amount &&
|
|
56
|
+
account.balance.minus(transaction.amount).minus(estimatedFees).lt(thresholdWarning)
|
|
57
|
+
) {
|
|
58
|
+
if (isAccountDelegating(account)) {
|
|
59
|
+
if (transaction.useAllAmount) {
|
|
60
|
+
errors.amount = new RecommendUndelegation();
|
|
61
|
+
} else {
|
|
62
|
+
warnings.amount = new RecommendUndelegation();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// effective amount
|
|
69
|
+
// if we also have taquitoError, we interprete them and they override the previously inferred errors
|
|
70
|
+
if (transaction.taquitoError) {
|
|
71
|
+
log("taquitoerror", String(transaction.taquitoError));
|
|
72
|
+
|
|
73
|
+
// remap taquito errors
|
|
74
|
+
if (
|
|
75
|
+
transaction.taquitoError.endsWith("balance_too_low") ||
|
|
76
|
+
transaction.taquitoError.endsWith("subtraction_underflow")
|
|
77
|
+
) {
|
|
78
|
+
if (transaction.mode === "send") {
|
|
79
|
+
resetTotalSpent = true;
|
|
80
|
+
errors.amount = new NotEnoughBalance();
|
|
81
|
+
} else {
|
|
82
|
+
errors.amount = new NotEnoughBalanceToDelegate();
|
|
83
|
+
}
|
|
84
|
+
} else if (transaction.taquitoError.endsWith("delegate.unchanged")) {
|
|
85
|
+
errors.recipient = new InvalidAddressBecauseAlreadyDelegated();
|
|
86
|
+
} else if (!errors.amount) {
|
|
87
|
+
// unidentified error case
|
|
88
|
+
errors.amount = new Error(transaction.taquitoError);
|
|
89
|
+
resetTotalSpent = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!errors.amount && account.balance.lte(0)) {
|
|
94
|
+
resetTotalSpent = true;
|
|
95
|
+
errors.amount = new NotEnoughBalance();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!errors.amount && transaction.mode === "delegate" && account.balance.lte(estimatedFees)) {
|
|
99
|
+
resetTotalSpent = true;
|
|
100
|
+
errors.amount = new NotEnoughBalance();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Catch a specific case that requires a minimum amount
|
|
104
|
+
if (
|
|
105
|
+
!errors.amount &&
|
|
106
|
+
transaction.mode === "send" &&
|
|
107
|
+
transaction.amount.lt(EXISTENTIAL_DEPOSIT) &&
|
|
108
|
+
(await api.getAccountByAddress(transaction.recipient)).type === "empty"
|
|
109
|
+
) {
|
|
110
|
+
resetTotalSpent = true;
|
|
111
|
+
errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
|
|
112
|
+
minimalAmount: "0.275 XTZ",
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
errors,
|
|
118
|
+
warnings,
|
|
119
|
+
estimatedFees,
|
|
120
|
+
amount: transaction.amount,
|
|
121
|
+
totalSpent: resetTotalSpent ? new BigNumber(0) : transaction.amount.plus(estimatedFees),
|
|
122
|
+
};
|
|
123
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSerializedAddressParameters,
|
|
3
|
+
updateTransaction,
|
|
4
|
+
makeAccountBridgeReceive,
|
|
5
|
+
makeScanAccounts,
|
|
6
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
7
|
+
import { CoinConfig } from "@ledgerhq/coin-framework/config";
|
|
8
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
9
|
+
import type { CurrencyBridge, AccountBridge } from "@ledgerhq/types-live";
|
|
10
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
11
|
+
import type { TezosAccount, TezosSigner, Transaction, TransactionStatus } from "../types";
|
|
12
|
+
import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
|
|
13
|
+
import { getPreloadStrategy, hydrate, preload } from "./preload";
|
|
14
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
15
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
16
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
17
|
+
import { getAccountShape, sync } from "./synchronization";
|
|
18
|
+
import { createTransaction } from "./createTransaction";
|
|
19
|
+
import { buildSignOperation } from "./signOperation";
|
|
20
|
+
import signerGetAddress from "../signer";
|
|
21
|
+
import { broadcast } from "./broadcast";
|
|
22
|
+
import tezosCoinConfig, { TezosCoinConfig } from "../config";
|
|
23
|
+
|
|
24
|
+
function buildCurrencyBridge(signerContext: SignerContext<TezosSigner>): CurrencyBridge {
|
|
25
|
+
const getAddress = signerGetAddress(signerContext);
|
|
26
|
+
|
|
27
|
+
const scanAccounts = makeScanAccounts({
|
|
28
|
+
getAccountShape,
|
|
29
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
getPreloadStrategy,
|
|
34
|
+
preload,
|
|
35
|
+
hydrate,
|
|
36
|
+
scanAccounts,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildAccountBridge(
|
|
41
|
+
signerContext: SignerContext<TezosSigner>,
|
|
42
|
+
): AccountBridge<Transaction, TezosAccount, TransactionStatus> {
|
|
43
|
+
const getAddress = signerGetAddress(signerContext);
|
|
44
|
+
|
|
45
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
46
|
+
const signOperation = buildSignOperation(signerContext);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
estimateMaxSpendable,
|
|
50
|
+
createTransaction,
|
|
51
|
+
updateTransaction,
|
|
52
|
+
getTransactionStatus,
|
|
53
|
+
prepareTransaction,
|
|
54
|
+
sync,
|
|
55
|
+
receive,
|
|
56
|
+
signOperation,
|
|
57
|
+
broadcast,
|
|
58
|
+
assignFromAccountRaw,
|
|
59
|
+
assignToAccountRaw,
|
|
60
|
+
getSerializedAddressParameters,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createBridges(
|
|
65
|
+
signerContext: SignerContext<TezosSigner>,
|
|
66
|
+
coinConfig: CoinConfig<TezosCoinConfig>,
|
|
67
|
+
) {
|
|
68
|
+
tezosCoinConfig.setCoinConfig(coinConfig);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
72
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { blake2b } from "@noble/hashes/blake2";
|
|
2
|
+
import bs58check from "bs58check";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { OperationType } from "@ledgerhq/types-live";
|
|
5
|
+
import { decodeAccountId } from "@ledgerhq/coin-framework/account";
|
|
6
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
7
|
+
import { type APIOperation } from "../network/types";
|
|
8
|
+
import { TezosAccount, TezosOperation } from "../types";
|
|
9
|
+
|
|
10
|
+
export const txToOp =
|
|
11
|
+
({ address, accountId }: { address: string; accountId: string }) =>
|
|
12
|
+
(tx: APIOperation): TezosOperation | null | undefined => {
|
|
13
|
+
let type: OperationType;
|
|
14
|
+
let maybeValue;
|
|
15
|
+
let senders: string[] = [];
|
|
16
|
+
let recipients: string[] = [];
|
|
17
|
+
const hasFailed = tx.status ? tx.status !== "applied" : false;
|
|
18
|
+
|
|
19
|
+
switch (tx.type) {
|
|
20
|
+
case "transaction": {
|
|
21
|
+
const initiator = tx.initiator?.address;
|
|
22
|
+
const from = tx.sender?.address;
|
|
23
|
+
const to = tx.target?.address;
|
|
24
|
+
if (from !== address && to !== address && initiator !== address) {
|
|
25
|
+
// failsafe for a case that shouldn't happen.
|
|
26
|
+
console.warn("found tx is unrelated to account! " + tx.hash);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
senders = [from || initiator || ""];
|
|
30
|
+
recipients = [to || ""];
|
|
31
|
+
if (
|
|
32
|
+
(from === address && to === address) || // self tx
|
|
33
|
+
(from !== address && to !== address) // initiator but not in from/to
|
|
34
|
+
) {
|
|
35
|
+
// we just pay fees in that case
|
|
36
|
+
type = "FEES";
|
|
37
|
+
} else {
|
|
38
|
+
type = to === address ? "IN" : "OUT";
|
|
39
|
+
if (!hasFailed) {
|
|
40
|
+
maybeValue = new BigNumber(tx.amount || 0);
|
|
41
|
+
if (maybeValue.eq(0)) {
|
|
42
|
+
type = "FEES";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "delegation":
|
|
49
|
+
type = tx.newDelegate ? "DELEGATE" : "UNDELEGATE";
|
|
50
|
+
senders = [address];
|
|
51
|
+
// convention was to use recipient for the new delegation address or "" if undelegation
|
|
52
|
+
recipients = [tx.newDelegate ? tx.newDelegate.address : ""];
|
|
53
|
+
break;
|
|
54
|
+
case "reveal":
|
|
55
|
+
type = "REVEAL";
|
|
56
|
+
senders = [address];
|
|
57
|
+
recipients = [address];
|
|
58
|
+
break;
|
|
59
|
+
case "migration":
|
|
60
|
+
type = tx.balanceChange < 0 ? "OUT" : "IN";
|
|
61
|
+
maybeValue = new BigNumber(Math.abs(tx.balanceChange || 0));
|
|
62
|
+
senders = [address];
|
|
63
|
+
recipients = [address];
|
|
64
|
+
break;
|
|
65
|
+
case "origination":
|
|
66
|
+
type = "CREATE";
|
|
67
|
+
maybeValue = new BigNumber(tx.contractBalance || 0);
|
|
68
|
+
senders = [address];
|
|
69
|
+
recipients = [tx.originatedContract?.address || ""];
|
|
70
|
+
break;
|
|
71
|
+
case "activation":
|
|
72
|
+
type = "IN";
|
|
73
|
+
senders = [address];
|
|
74
|
+
recipients = [address];
|
|
75
|
+
maybeValue = new BigNumber(tx.balance || 0);
|
|
76
|
+
break;
|
|
77
|
+
// TODO more type of tx
|
|
78
|
+
default:
|
|
79
|
+
console.warn("unsupported tx:", tx);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let { hash } = tx;
|
|
84
|
+
const {
|
|
85
|
+
id,
|
|
86
|
+
allocationFee,
|
|
87
|
+
bakerFee,
|
|
88
|
+
storageFee,
|
|
89
|
+
level: blockHeight,
|
|
90
|
+
block: blockHash,
|
|
91
|
+
timestamp,
|
|
92
|
+
} = tx;
|
|
93
|
+
|
|
94
|
+
if (!hash) {
|
|
95
|
+
// in migration case, there is no hash...
|
|
96
|
+
hash = "";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let value = maybeValue || new BigNumber(0);
|
|
100
|
+
if (type === "IN" && value.eq(0)) {
|
|
101
|
+
return; // not interesting op
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let fee = new BigNumber(bakerFee || 0);
|
|
105
|
+
|
|
106
|
+
if (!hasFailed) {
|
|
107
|
+
fee = fee.plus(allocationFee || 0).plus(storageFee || 0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (type !== "IN") {
|
|
111
|
+
value = value.plus(fee);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
id: encodeOperationId(accountId, hash, type),
|
|
116
|
+
hash,
|
|
117
|
+
type,
|
|
118
|
+
value,
|
|
119
|
+
fee,
|
|
120
|
+
senders,
|
|
121
|
+
recipients,
|
|
122
|
+
blockHeight,
|
|
123
|
+
blockHash,
|
|
124
|
+
accountId,
|
|
125
|
+
date: new Date(timestamp),
|
|
126
|
+
extra: { id },
|
|
127
|
+
hasFailed,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export function reconciliatePublicKey(
|
|
132
|
+
publicKey: string | undefined,
|
|
133
|
+
account: TezosAccount | undefined,
|
|
134
|
+
): string {
|
|
135
|
+
if (publicKey) return publicKey;
|
|
136
|
+
if (account) {
|
|
137
|
+
const { xpubOrAddress } = decodeAccountId(account.id);
|
|
138
|
+
return xpubOrAddress;
|
|
139
|
+
}
|
|
140
|
+
throw new Error("publicKey wasn't properly restored");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function encodeAddress(publicKey: Buffer) {
|
|
144
|
+
const curve = 0;
|
|
145
|
+
const curveData = {
|
|
146
|
+
pkB58Prefix: Buffer.from([13, 15, 37, 217]),
|
|
147
|
+
pkhB58Prefix: Buffer.from([6, 161, 159]),
|
|
148
|
+
compressPublicKey: (publicKey: Buffer, curve: number) => {
|
|
149
|
+
publicKey = publicKey.slice(0);
|
|
150
|
+
publicKey[0] = curve;
|
|
151
|
+
return publicKey;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const publicKeyBuf = curveData.compressPublicKey(publicKey, curve);
|
|
155
|
+
const key = publicKeyBuf.slice(1);
|
|
156
|
+
const keyHashSize = 20;
|
|
157
|
+
const hash = Buffer.from(blake2b(key, { dkLen: keyHashSize }));
|
|
158
|
+
const address = bs58check.encode(Buffer.concat([curveData.pkhB58Prefix, hash]));
|
|
159
|
+
return address;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function isStringHex(s: string): boolean {
|
|
163
|
+
for (let i = 0; i < s.length; i += 2) {
|
|
164
|
+
const ss = s.slice(i, i + 2);
|
|
165
|
+
const x = parseInt(ss, 16);
|
|
166
|
+
if (Number.isNaN(x)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
2
|
+
import { fetchAllBakers, hydrateBakers } from "../network/bakers";
|
|
3
|
+
|
|
4
|
+
export const getPreloadStrategy = (_currency: CryptoCurrency) => ({
|
|
5
|
+
preloadMaxAge: 30 * 1000,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const preload = async () => {
|
|
9
|
+
const bakers = await fetchAllBakers();
|
|
10
|
+
return { bakers };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const hydrate = (data: any) => {
|
|
14
|
+
if (!data || typeof data !== "object") return;
|
|
15
|
+
const { bakers } = data;
|
|
16
|
+
if (!bakers || typeof bakers !== "object" || !Array.isArray(bakers)) return;
|
|
17
|
+
hydrateBakers(bakers);
|
|
18
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
3
|
+
import prepareTransaction from "./prepareTransaction";
|
|
4
|
+
import coinConfig, { TezosCoinConfig } from "../config";
|
|
5
|
+
import { mockConfig } from "../test/config";
|
|
6
|
+
|
|
7
|
+
describe.only("prepareTransaction", () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
coinConfig.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns the same transaction when account balance is 0", async () => {
|
|
13
|
+
// Given
|
|
14
|
+
const tx = createFixtureTransaction({ amount: BigNumber(0) });
|
|
15
|
+
|
|
16
|
+
// When
|
|
17
|
+
const newTx = await prepareTransaction(createFixtureAccount(), tx);
|
|
18
|
+
|
|
19
|
+
// Then
|
|
20
|
+
expect(newTx).toBe(tx);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("returns error when amount is 0", async () => {
|
|
24
|
+
const tx = createFixtureTransaction({
|
|
25
|
+
amount: BigNumber(0),
|
|
26
|
+
recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const newTx = await prepareTransaction(createFixtureAccount({ balance: BigNumber(10) }), tx);
|
|
30
|
+
|
|
31
|
+
// initial expectation was proto.020-PsParisC.contract.empty_transaction
|
|
32
|
+
// and evolved to proto.021-PsQuebec.contract.empty_transaction
|
|
33
|
+
expect(newTx.taquitoError?.includes(".contract.empty_transaction")).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
});
|