@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,130 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
3
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
4
|
+
import type { SignOperationEvent, AccountBridge } from "@ledgerhq/types-live";
|
|
5
|
+
import type { TezosAccount, TezosSigner, Transaction, TransactionStatus } from "../types";
|
|
6
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
7
|
+
import { craftTransaction, rawEncode } from "../logic";
|
|
8
|
+
import { getTezosToolkit } from "../logic/tezosToolkit";
|
|
9
|
+
|
|
10
|
+
// Exported for test purpose only
|
|
11
|
+
export async function getOperationContents({
|
|
12
|
+
account,
|
|
13
|
+
transaction,
|
|
14
|
+
counter,
|
|
15
|
+
public_key,
|
|
16
|
+
public_key_hash,
|
|
17
|
+
}: {
|
|
18
|
+
account: TezosAccount;
|
|
19
|
+
transaction: Transaction;
|
|
20
|
+
counter: number;
|
|
21
|
+
public_key: string;
|
|
22
|
+
public_key_hash: string;
|
|
23
|
+
}) {
|
|
24
|
+
let publicKey = undefined;
|
|
25
|
+
if (!account.tezosResources.revealed) {
|
|
26
|
+
publicKey = {
|
|
27
|
+
publicKey: public_key,
|
|
28
|
+
publicKeyHash: public_key_hash,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return craftTransaction(
|
|
33
|
+
{
|
|
34
|
+
address: account.freshAddress,
|
|
35
|
+
counter,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: transaction.mode,
|
|
39
|
+
recipient: transaction.recipient,
|
|
40
|
+
amount: BigInt(transaction.amount.toString()),
|
|
41
|
+
fee: {
|
|
42
|
+
fees: (transaction.fees || 0).toString(),
|
|
43
|
+
gasLimit: (transaction.gasLimit || 0).toString(),
|
|
44
|
+
storageLimit: (transaction.storageLimit || 0).toString(),
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
publicKey,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const buildSignOperation =
|
|
52
|
+
(
|
|
53
|
+
signerContext: SignerContext<TezosSigner>,
|
|
54
|
+
): AccountBridge<Transaction, TezosAccount, TransactionStatus>["signOperation"] =>
|
|
55
|
+
({ account, deviceId, transaction }): Observable<SignOperationEvent> =>
|
|
56
|
+
new Observable(o => {
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
|
|
59
|
+
async function main() {
|
|
60
|
+
const { fees } = transaction;
|
|
61
|
+
if (!fees) throw new FeeNotLoaded();
|
|
62
|
+
|
|
63
|
+
const { freshAddressPath, freshAddress } = account;
|
|
64
|
+
|
|
65
|
+
const signedInfo = await signerContext(deviceId, async signer => {
|
|
66
|
+
const ledgerSigner = signer.createLedgerSigner(freshAddressPath, false, 0);
|
|
67
|
+
|
|
68
|
+
const tezosToolkit = getTezosToolkit();
|
|
69
|
+
tezosToolkit.setProvider({ signer: ledgerSigner });
|
|
70
|
+
|
|
71
|
+
const publicKey = await ledgerSigner.publicKey();
|
|
72
|
+
const publicKeyHash = await ledgerSigner.publicKeyHash();
|
|
73
|
+
|
|
74
|
+
const sourceData = await tezosToolkit.rpc.getContract(freshAddress);
|
|
75
|
+
|
|
76
|
+
o.next({ type: "device-signature-requested" });
|
|
77
|
+
|
|
78
|
+
if (cancelled) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { type, contents } = await getOperationContents({
|
|
83
|
+
account,
|
|
84
|
+
transaction,
|
|
85
|
+
counter: Number(sourceData.counter),
|
|
86
|
+
public_key: publicKey,
|
|
87
|
+
public_key_hash: publicKeyHash,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const forgedBytes = await rawEncode(contents);
|
|
91
|
+
|
|
92
|
+
const signature = await ledgerSigner.sign(forgedBytes);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
type,
|
|
96
|
+
signature,
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (!signedInfo) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
o.next({ type: "device-signature-granted" });
|
|
105
|
+
|
|
106
|
+
const { type, signature } = signedInfo;
|
|
107
|
+
const operation = buildOptimisticOperation(account, transaction, type);
|
|
108
|
+
|
|
109
|
+
o.next({
|
|
110
|
+
type: "signed",
|
|
111
|
+
signedOperation: {
|
|
112
|
+
operation,
|
|
113
|
+
// we slice the signature to remove the `03` prefix
|
|
114
|
+
// which souldn't be included in the signature
|
|
115
|
+
signature: signature.sbytes.slice(2),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
main().then(
|
|
121
|
+
() => o.complete(),
|
|
122
|
+
e => o.error(e),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
cancelled = true;
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export default buildSignOperation;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import coinConfig, { TezosCoinConfig } from "../config";
|
|
2
|
+
import { fetchAllTransactions } from "../network/tzkt";
|
|
3
|
+
import { mockConfig } from "../test/config";
|
|
4
|
+
|
|
5
|
+
jest.setTimeout(2 * 60 * 1000);
|
|
6
|
+
|
|
7
|
+
describe("TEZOS_MAX_TX_QUERIES", () => {
|
|
8
|
+
const tezosConfig = mockConfig as TezosCoinConfig;
|
|
9
|
+
const bigAccount = "tz1boBHAVpwcvKkNFAQHYr7mjxAz1PpVgKq7";
|
|
10
|
+
|
|
11
|
+
test("default have more than 100 txs", async () => {
|
|
12
|
+
// Given
|
|
13
|
+
coinConfig.setCoinConfig((): TezosCoinConfig => tezosConfig);
|
|
14
|
+
|
|
15
|
+
const txs = await fetchAllTransactions(bigAccount);
|
|
16
|
+
expect(txs.length).toBeGreaterThan(100);
|
|
17
|
+
});
|
|
18
|
+
test("lowering it to 1 will only fetch a few txs", async () => {
|
|
19
|
+
// Given
|
|
20
|
+
coinConfig.setCoinConfig(
|
|
21
|
+
(): TezosCoinConfig => ({
|
|
22
|
+
...tezosConfig,
|
|
23
|
+
explorer: {
|
|
24
|
+
url: "https://xtz-tzkt-explorer.api.live.ledger.com",
|
|
25
|
+
maxTxQuery: 1,
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const txs = await fetchAllTransactions(bigAccount);
|
|
31
|
+
expect(txs.length).toBeLessThanOrEqual(100);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import type { TokenAccount } from "@ledgerhq/types-live";
|
|
4
|
+
import { GetAccountShape, makeSync, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
+
import { encodeAccountId, areAllOperationsLoaded } from "@ledgerhq/coin-framework/account/index";
|
|
6
|
+
import { encodeAddress, isStringHex, reconciliatePublicKey, txToOp } from "./logic";
|
|
7
|
+
import api, { fetchAllTransactions } from "../network/tzkt";
|
|
8
|
+
import { TezosAccount, TezosOperation } from "../types";
|
|
9
|
+
|
|
10
|
+
export const getAccountShape: GetAccountShape<TezosAccount> = async ({
|
|
11
|
+
initialAccount,
|
|
12
|
+
rest,
|
|
13
|
+
currency,
|
|
14
|
+
derivationMode,
|
|
15
|
+
}) => {
|
|
16
|
+
const publicKey = reconciliatePublicKey(rest?.publicKey, initialAccount);
|
|
17
|
+
invariant(
|
|
18
|
+
isStringHex(publicKey),
|
|
19
|
+
`Invalid public key (${publicKey}). Please reimport your Tezos accounts`,
|
|
20
|
+
);
|
|
21
|
+
const hex = Buffer.from(publicKey, "hex");
|
|
22
|
+
const address = encodeAddress(hex);
|
|
23
|
+
|
|
24
|
+
const accountId = encodeAccountId({
|
|
25
|
+
type: "js",
|
|
26
|
+
version: "2",
|
|
27
|
+
currencyId: currency.id,
|
|
28
|
+
xpubOrAddress: publicKey,
|
|
29
|
+
derivationMode,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const initialStableOperations = (
|
|
33
|
+
initialAccount && initialAccount.id === accountId ? initialAccount.operations : []
|
|
34
|
+
) as TezosOperation[];
|
|
35
|
+
|
|
36
|
+
// fetch transactions, incrementally if possible
|
|
37
|
+
const mostRecentStableOperation = initialStableOperations[0];
|
|
38
|
+
|
|
39
|
+
const lastId =
|
|
40
|
+
initialAccount && areAllOperationsLoaded(initialAccount) && mostRecentStableOperation
|
|
41
|
+
? mostRecentStableOperation.extra.id || undefined
|
|
42
|
+
: undefined;
|
|
43
|
+
|
|
44
|
+
const apiAccountPromise = api.getAccountByAddress(address);
|
|
45
|
+
const blocksCountPromise = api.getBlockCount();
|
|
46
|
+
|
|
47
|
+
const [apiAccount, blockHeight] = await Promise.all([apiAccountPromise, blocksCountPromise]);
|
|
48
|
+
|
|
49
|
+
if (apiAccount.type === "empty") {
|
|
50
|
+
return {
|
|
51
|
+
id: accountId,
|
|
52
|
+
xpub: publicKey,
|
|
53
|
+
freshAddress: address,
|
|
54
|
+
blockHeight,
|
|
55
|
+
lastSyncDate: new Date(),
|
|
56
|
+
tezosResources: {
|
|
57
|
+
revealed: false,
|
|
58
|
+
counter: 0,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const fullySupported = apiAccount.type === "user";
|
|
64
|
+
|
|
65
|
+
const apiOperations = fullySupported ? await fetchAllTransactions(address, lastId) : [];
|
|
66
|
+
|
|
67
|
+
const { revealed, counter } = apiAccount;
|
|
68
|
+
|
|
69
|
+
const tezosResources = {
|
|
70
|
+
revealed,
|
|
71
|
+
counter,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const balance = new BigNumber(apiAccount.balance);
|
|
75
|
+
const subAccounts: TokenAccount[] = [];
|
|
76
|
+
|
|
77
|
+
const newOps = apiOperations
|
|
78
|
+
.map(txToOp({ address, accountId }))
|
|
79
|
+
.filter(Boolean) as unknown as TezosOperation[]; // force cast because `filter(Boolean)` remove undefined and null value
|
|
80
|
+
|
|
81
|
+
const operations = mergeOps(initialStableOperations, newOps);
|
|
82
|
+
|
|
83
|
+
const accountShape = {
|
|
84
|
+
id: accountId,
|
|
85
|
+
xpub: publicKey,
|
|
86
|
+
freshAddress: address,
|
|
87
|
+
operations,
|
|
88
|
+
operationsCount: operations.length,
|
|
89
|
+
balance,
|
|
90
|
+
subAccounts,
|
|
91
|
+
spendableBalance: balance,
|
|
92
|
+
blockHeight,
|
|
93
|
+
lastSyncDate: new Date(),
|
|
94
|
+
tezosResources,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return accountShape;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const sync = makeSync({ getAccountShape });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
|
-
import type { Transaction, TransactionRaw } from "
|
|
2
|
+
import type { Transaction, TransactionRaw } from "../types";
|
|
3
3
|
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
4
4
|
import {
|
|
5
5
|
fromTransactionCommonRaw,
|
|
@@ -58,9 +58,9 @@ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
|
58
58
|
fees: new BigNumber(networkInfo.fees),
|
|
59
59
|
},
|
|
60
60
|
fees: tr.fees ? new BigNumber(tr.fees) : null,
|
|
61
|
-
gasLimit: tr.gasLimit ? new BigNumber(tr.gasLimit) :
|
|
62
|
-
storageLimit: tr.storageLimit ? new BigNumber(tr.storageLimit) :
|
|
63
|
-
estimatedFees: tr.estimatedFees ? new BigNumber(tr.estimatedFees) :
|
|
61
|
+
gasLimit: tr.gasLimit ? new BigNumber(tr.gasLimit) : null,
|
|
62
|
+
storageLimit: tr.storageLimit ? new BigNumber(tr.storageLimit) : null,
|
|
63
|
+
estimatedFees: tr.estimatedFees ? new BigNumber(tr.estimatedFees) : null,
|
|
64
64
|
taquitoError: tr.taquitoError,
|
|
65
65
|
};
|
|
66
66
|
};
|
package/src/config.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import buildCoinConfig, {
|
|
2
|
-
type CoinConfig,
|
|
3
|
-
type CurrencyConfig,
|
|
4
|
-
} from "@ledgerhq/coin-framework/config";
|
|
5
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
1
|
+
import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
|
|
6
2
|
|
|
7
3
|
export type TezosConfig = {
|
|
8
4
|
baker: {
|
|
@@ -26,9 +22,6 @@ export type TezosConfig = {
|
|
|
26
22
|
|
|
27
23
|
export type TezosCoinConfig = CurrencyConfig & TezosConfig;
|
|
28
24
|
|
|
29
|
-
const coinConfig
|
|
30
|
-
setCoinConfig: (config: CoinConfig<TezosCoinConfig>) => void;
|
|
31
|
-
getCoinConfig: (currency?: CryptoCurrency) => TezosCoinConfig;
|
|
32
|
-
} = buildCoinConfig<TezosCoinConfig>();
|
|
25
|
+
const coinConfig = buildCoinConfig<TezosCoinConfig>();
|
|
33
26
|
|
|
34
27
|
export default coinConfig;
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { getRevealFee } from "@taquito/taquito";
|
|
|
3
3
|
import coinConfig from "../config";
|
|
4
4
|
import { UnsupportedTransactionMode } from "../types/errors";
|
|
5
5
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
6
|
-
import { createMockSigner } from "../utils";
|
|
7
6
|
|
|
8
7
|
export type TransactionFee = {
|
|
9
8
|
fees?: string;
|
|
@@ -38,13 +37,6 @@ export async function craftTransaction(
|
|
|
38
37
|
|
|
39
38
|
const tezosToolkit = getTezosToolkit();
|
|
40
39
|
|
|
41
|
-
// Configure signer for Taquito operations (same as in estimateFees)
|
|
42
|
-
if (publicKey) {
|
|
43
|
-
tezosToolkit.setProvider({
|
|
44
|
-
signer: createMockSigner(publicKey.publicKeyHash, publicKey.publicKey),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
40
|
const sourceData = await tezosToolkit.rpc.getContract(address);
|
|
49
41
|
const counter = account.counter ?? Number(sourceData.counter);
|
|
50
42
|
|
|
@@ -22,10 +22,7 @@ describe("estimateFees", () => {
|
|
|
22
22
|
},
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
-
it.each(
|
|
26
|
-
[accounts[0], "with xpub"],
|
|
27
|
-
[accounts[1], "without xpub"],
|
|
28
|
-
])("returns correct value %s", async (account, _description) => {
|
|
25
|
+
it.each(accounts)("returns correct value", async account => {
|
|
29
26
|
// Given
|
|
30
27
|
const transaction = {
|
|
31
28
|
mode: "send",
|
|
@@ -45,10 +42,7 @@ describe("estimateFees", () => {
|
|
|
45
42
|
});
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
it.each(
|
|
49
|
-
[accounts[0], "with xpub"],
|
|
50
|
-
[accounts[1], "without xpub"],
|
|
51
|
-
])("returns correct value when useAllAmount %s", async (account, _description) => {
|
|
45
|
+
it.each(accounts)("returns correct value when useAllAmount", async account => {
|
|
52
46
|
// Given
|
|
53
47
|
const transaction = {
|
|
54
48
|
mode: "send",
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
+
import { DerivationType } from "@taquito/ledger-signer";
|
|
2
|
+
import { compressPublicKey } from "@taquito/ledger-signer/dist/lib/utils";
|
|
1
3
|
import { COST_PER_BYTE, getRevealFee, ORIGINATION_SIZE, Estimate } from "@taquito/taquito";
|
|
2
|
-
import {
|
|
4
|
+
import { b58Encode, PrefixV2 } from "@taquito/utils";
|
|
3
5
|
import { log } from "@ledgerhq/logs";
|
|
4
6
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
5
7
|
import { TezosOperationMode } from "../types/model";
|
|
6
8
|
import { UnsupportedTransactionMode } from "../types/errors";
|
|
7
|
-
import {
|
|
8
|
-
createFallbackEstimation,
|
|
9
|
-
createMockSigner,
|
|
10
|
-
DUST_MARGIN_MUTEZ,
|
|
11
|
-
MIN_SUGGESTED_FEE_SMALL_TRANSFER,
|
|
12
|
-
OP_SIZE_XTZ_TRANSFER,
|
|
13
|
-
normalizePublicKeyForAddress,
|
|
14
|
-
} from "../utils";
|
|
15
9
|
|
|
16
10
|
export type CoreAccountInfo = {
|
|
17
11
|
address: string;
|
|
@@ -47,43 +41,54 @@ export async function estimateFees({
|
|
|
47
41
|
account: CoreAccountInfo;
|
|
48
42
|
transaction: CoreTransactionInfo;
|
|
49
43
|
}): Promise<EstimatedFees> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
44
|
+
let derivationType: DerivationType;
|
|
45
|
+
let prefix: PrefixV2;
|
|
46
|
+
if (account.address?.startsWith("tz1")) {
|
|
47
|
+
derivationType = DerivationType.ED25519;
|
|
48
|
+
prefix = PrefixV2.Ed25519PublicKey;
|
|
49
|
+
} else if (account.address?.startsWith("tz2")) {
|
|
50
|
+
derivationType = DerivationType.SECP256K1;
|
|
51
|
+
prefix = PrefixV2.Secp256k1PublicKey;
|
|
52
|
+
} else if (account.address?.startsWith("tz3")) {
|
|
53
|
+
derivationType = DerivationType.P256;
|
|
54
|
+
prefix = PrefixV2.P256PublicKey;
|
|
59
55
|
} else {
|
|
60
|
-
|
|
56
|
+
throw Error(`Failed detecting key derivation type from address ${account.address}`);
|
|
61
57
|
}
|
|
62
58
|
|
|
59
|
+
const encodedPubKey = b58Encode(
|
|
60
|
+
compressPublicKey(Buffer.from(account.xpub || "", "hex"), derivationType),
|
|
61
|
+
prefix,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const tezosToolkit = getTezosToolkit();
|
|
65
|
+
tezosToolkit.setProvider({
|
|
66
|
+
signer: {
|
|
67
|
+
publicKeyHash: async () => account.address,
|
|
68
|
+
publicKey: async () => encodedPubKey,
|
|
69
|
+
sign: () => Promise.reject(new Error("unsupported")),
|
|
70
|
+
secretKey: () => Promise.reject(new Error("unsupported")),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
63
74
|
const estimation: EstimatedFees = {
|
|
64
|
-
fees:
|
|
65
|
-
gasLimit:
|
|
66
|
-
storageLimit:
|
|
67
|
-
estimatedFees:
|
|
75
|
+
fees: BigInt(0),
|
|
76
|
+
gasLimit: BigInt(0),
|
|
77
|
+
storageLimit: BigInt(0),
|
|
78
|
+
estimatedFees: BigInt(0),
|
|
68
79
|
};
|
|
69
80
|
|
|
70
81
|
// For legacy compatibility
|
|
71
|
-
if (account.balance ===
|
|
72
|
-
return transaction.useAllAmount ? { ...estimation, amount:
|
|
82
|
+
if (account.balance === BigInt(0)) {
|
|
83
|
+
return transaction.useAllAmount ? { ...estimation, amount: BigInt(0) } : estimation;
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
let amount = transaction.amount;
|
|
76
|
-
if (transaction.useAllAmount
|
|
77
|
-
amount =
|
|
87
|
+
if (transaction.useAllAmount) {
|
|
88
|
+
amount = BigInt(1); // send max do a pre-estimation with minimum amount (taquito refuses 0)
|
|
78
89
|
}
|
|
79
90
|
|
|
80
91
|
try {
|
|
81
|
-
if (transaction.mode === "send" && !transaction.recipient) {
|
|
82
|
-
return {
|
|
83
|
-
...estimation,
|
|
84
|
-
...createFallbackEstimation(),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
92
|
let estimate: Estimate;
|
|
88
93
|
switch (transaction.mode) {
|
|
89
94
|
case "send":
|
|
@@ -91,7 +96,6 @@ export async function estimateFees({
|
|
|
91
96
|
mutez: true,
|
|
92
97
|
to: transaction.recipient,
|
|
93
98
|
amount: Number(amount),
|
|
94
|
-
source: account.address, // avoid requiring signer for estimation
|
|
95
99
|
storageLimit: ORIGINATION_SIZE, // https://github.com/TezTech/eztz/blob/master/PROTO_003_FEES.md for originating an account
|
|
96
100
|
});
|
|
97
101
|
break;
|
|
@@ -125,14 +129,16 @@ export async function estimateFees({
|
|
|
125
129
|
// NOTE: from https://github.com/ecadlabs/taquito/blob/a70c64c4b105381bb9f1d04c9c70e8ef26e9241c/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts#L33
|
|
126
130
|
// Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
|
|
127
131
|
// we need to increase the gasLimit and fee returned by the estimation
|
|
132
|
+
const gasBuffer = 500;
|
|
128
133
|
const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
|
|
129
134
|
const increasedFee = (gasBuffer: number, opSize: number) => {
|
|
130
135
|
return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
|
|
131
136
|
};
|
|
132
|
-
const incr = increasedFee(
|
|
137
|
+
const incr = increasedFee(gasBuffer, Number(estimate.opSize));
|
|
138
|
+
|
|
139
|
+
const maxMinusBuff = maxAmount - (gasBuffer - incr);
|
|
140
|
+
estimation.amount = maxMinusBuff > 0 ? BigInt(maxMinusBuff) : BigInt(0);
|
|
133
141
|
|
|
134
|
-
const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
|
|
135
|
-
estimation.amount = maxMinusBuff > 0 ? BigInt(maxMinusBuff) : 0n;
|
|
136
142
|
estimation.fees = BigInt(estimate.suggestedFeeMutez);
|
|
137
143
|
estimation.gasLimit = BigInt(estimate.gasLimit);
|
|
138
144
|
} else {
|
|
@@ -140,7 +146,6 @@ export async function estimateFees({
|
|
|
140
146
|
estimation.gasLimit = BigInt(estimate.gasLimit);
|
|
141
147
|
estimation.amount = transaction.amount;
|
|
142
148
|
}
|
|
143
|
-
|
|
144
149
|
estimation.storageLimit = BigInt(estimate.storageLimit);
|
|
145
150
|
estimation.estimatedFees = estimation.fees;
|
|
146
151
|
if (!account.revealed) {
|
|
@@ -152,109 +157,13 @@ export async function estimateFees({
|
|
|
152
157
|
estimation.taquitoError = (e as { id: string }).id;
|
|
153
158
|
log("taquito-error", "taquito got error " + e.id);
|
|
154
159
|
} else if ("status" in e) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
log(
|
|
161
|
-
"taquito-network-error",
|
|
162
|
-
"Recipient address not found (new account), using default fees",
|
|
163
|
-
{
|
|
164
|
-
transaction: transaction,
|
|
165
|
-
},
|
|
166
|
-
);
|
|
167
|
-
const fallback = createFallbackEstimation();
|
|
168
|
-
estimation.fees = fallback.fees;
|
|
169
|
-
estimation.gasLimit = fallback.gasLimit;
|
|
170
|
-
estimation.storageLimit = fallback.storageLimit;
|
|
171
|
-
estimation.estimatedFees = fallback.fees;
|
|
172
|
-
if (!account.revealed) {
|
|
173
|
-
estimation.estimatedFees =
|
|
174
|
-
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
175
|
-
}
|
|
176
|
-
// Handle useAllAmount also for send mode when estimation falls back
|
|
177
|
-
if (transaction.useAllAmount) {
|
|
178
|
-
// Approximate Taquito behavior for send-max using stable constants
|
|
179
|
-
const suggestedFee =
|
|
180
|
-
transaction.mode === "send"
|
|
181
|
-
? MIN_SUGGESTED_FEE_SMALL_TRANSFER
|
|
182
|
-
: Number(estimation.fees);
|
|
183
|
-
|
|
184
|
-
// For display consistency in tests, align fees to suggestedFee in send-max
|
|
185
|
-
if (transaction.mode === "send") {
|
|
186
|
-
estimation.fees = BigInt(suggestedFee);
|
|
187
|
-
estimation.estimatedFees = BigInt(suggestedFee);
|
|
188
|
-
if (!account.revealed) {
|
|
189
|
-
estimation.estimatedFees =
|
|
190
|
-
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE;
|
|
195
|
-
const totalFees =
|
|
196
|
-
suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0);
|
|
197
|
-
|
|
198
|
-
const revealFee = account.revealed ? 0 : getRevealFee(account.address);
|
|
199
|
-
const maxAmount = Number.parseInt(account.balance.toString()) - (totalFees + revealFee);
|
|
200
|
-
|
|
201
|
-
const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
|
|
202
|
-
const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ;
|
|
203
|
-
const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
|
|
204
|
-
estimation.amount = maxMinusBuff > 0 ? BigInt(Math.floor(maxMinusBuff)) : 0n;
|
|
205
|
-
} else {
|
|
206
|
-
// preserve input amount in fallback for readability/tests
|
|
207
|
-
estimation.amount = transaction.amount;
|
|
208
|
-
}
|
|
209
|
-
} else {
|
|
210
|
-
log("taquito-network-error", errorMessage, {
|
|
211
|
-
transaction: transaction,
|
|
212
|
-
});
|
|
213
|
-
throw e;
|
|
214
|
-
}
|
|
160
|
+
// in case of http 400, log & ignore (more case to handle)
|
|
161
|
+
log("taquito-network-error", String((e as unknown as { message: string }).message || ""), {
|
|
162
|
+
transaction: transaction,
|
|
163
|
+
});
|
|
164
|
+
throw e;
|
|
215
165
|
} else {
|
|
216
|
-
|
|
217
|
-
if (msg.includes("No signer has been configured")) {
|
|
218
|
-
const fallback = createFallbackEstimation();
|
|
219
|
-
estimation.fees = fallback.fees;
|
|
220
|
-
estimation.gasLimit = fallback.gasLimit;
|
|
221
|
-
estimation.storageLimit = fallback.storageLimit;
|
|
222
|
-
estimation.estimatedFees = fallback.estimatedFees;
|
|
223
|
-
if (!account.revealed) {
|
|
224
|
-
estimation.estimatedFees =
|
|
225
|
-
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
226
|
-
}
|
|
227
|
-
if (transaction.useAllAmount) {
|
|
228
|
-
const suggestedFee =
|
|
229
|
-
transaction.mode === "send"
|
|
230
|
-
? MIN_SUGGESTED_FEE_SMALL_TRANSFER
|
|
231
|
-
: Number(estimation.fees);
|
|
232
|
-
|
|
233
|
-
if (transaction.mode === "send") {
|
|
234
|
-
estimation.fees = BigInt(suggestedFee);
|
|
235
|
-
estimation.estimatedFees = BigInt(suggestedFee);
|
|
236
|
-
if (!account.revealed) {
|
|
237
|
-
estimation.estimatedFees =
|
|
238
|
-
estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE;
|
|
243
|
-
const totalFees =
|
|
244
|
-
suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0);
|
|
245
|
-
const revealFee = account.revealed ? 0 : getRevealFee(account.address);
|
|
246
|
-
const maxAmount = Number.parseInt(account.balance.toString()) - (totalFees + revealFee);
|
|
247
|
-
const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1;
|
|
248
|
-
const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ;
|
|
249
|
-
const maxMinusBuff = maxAmount - (DUST_MARGIN_MUTEZ - incr);
|
|
250
|
-
estimation.amount = maxMinusBuff > 0 ? BigInt(Math.floor(maxMinusBuff)) : 0n;
|
|
251
|
-
} else {
|
|
252
|
-
// preserve input amount in fallback for readability/tests
|
|
253
|
-
estimation.amount = transaction.amount;
|
|
254
|
-
}
|
|
255
|
-
} else {
|
|
256
|
-
throw e;
|
|
257
|
-
}
|
|
166
|
+
throw e;
|
|
258
167
|
}
|
|
259
168
|
}
|
|
260
169
|
return estimation;
|
package/src/logic/getBalance.ts
CHANGED
|
@@ -6,5 +6,5 @@ import api from "../network/tzkt";
|
|
|
6
6
|
*/
|
|
7
7
|
export async function getBalance(address: string): Promise<bigint> {
|
|
8
8
|
const apiAccount = await api.getAccountByAddress(address);
|
|
9
|
-
return apiAccount.type === "user" ? BigInt(apiAccount.balance) : -
|
|
9
|
+
return apiAccount.type === "user" ? BigInt(apiAccount.balance) : BigInt(-1);
|
|
10
10
|
}
|
package/src/logic/index.ts
CHANGED
|
@@ -7,5 +7,3 @@ export { estimateFees } from "./estimateFees";
|
|
|
7
7
|
export { getBalance } from "./getBalance";
|
|
8
8
|
export { lastBlock } from "./lastBlock";
|
|
9
9
|
export { listOperations } from "./listOperations";
|
|
10
|
-
export { validateIntent } from "./validateIntent";
|
|
11
|
-
export { getStakes } from "./getStakes";
|