@ledgerhq/coin-tron 0.0.1
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/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +25 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/jest.integ.config.js +7 -0
- package/lib/bridge/broadcast.d.ts +7 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +26 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +101 -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 +19 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +20 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +65 -0
- package/lib/bridge/deviceTransactionConfig.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/getEstimateFees.d.ts +6 -0
- package/lib/bridge/getEstimateFees.d.ts.map +1 -0
- package/lib/bridge/getEstimateFees.js +52 -0
- package/lib/bridge/getEstimateFees.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 +218 -0
- package/lib/bridge/getTransactionStatus.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 +60 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/preload.d.ts +8 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +32 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +19 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serialization.d.ts +9 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +238 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +92 -0
- package/lib/bridge/signOperation.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 +3 -0
- package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.js +96 -0
- package/lib/bridge/synchronization.integ.test.js.map +1 -0
- package/lib/bridge/synchronization.js +216 -0
- package/lib/bridge/synchronization.js.map +1 -0
- package/lib/bridge/transaction.d.ts +15 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +61 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +10 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +17 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/logic/constants.d.ts +4 -0
- package/lib/logic/constants.d.ts.map +1 -0
- package/lib/logic/constants.js +7 -0
- package/lib/logic/constants.js.map +1 -0
- package/lib/logic/pagination.d.ts +3 -0
- package/lib/logic/pagination.d.ts.map +1 -0
- package/lib/logic/pagination.js +19 -0
- package/lib/logic/pagination.js.map +1 -0
- package/lib/logic/utils.d.ts +12 -0
- package/lib/logic/utils.d.ts.map +1 -0
- package/lib/logic/utils.js +177 -0
- package/lib/logic/utils.js.map +1 -0
- package/lib/network/format.d.ts +9 -0
- package/lib/network/format.d.ts.map +1 -0
- package/lib/network/format.js +127 -0
- package/lib/network/format.js.map +1 -0
- package/lib/network/index.d.ts +30 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.integ.test.d.ts +2 -0
- package/lib/network/index.integ.test.d.ts.map +1 -0
- package/lib/network/index.integ.test.js +38 -0
- package/lib/network/index.integ.test.js.map +1 -0
- package/lib/network/index.js +555 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/index.test.d.ts +2 -0
- package/lib/network/index.test.d.ts.map +1 -0
- package/lib/network/index.test.js +66 -0
- package/lib/network/index.test.js.map +1 -0
- package/lib/network/superRepresentativesData.mock.d.ts +69 -0
- package/lib/network/superRepresentativesData.mock.d.ts.map +1 -0
- package/lib/network/superRepresentativesData.mock.js +2208 -0
- package/lib/network/superRepresentativesData.mock.js.map +1 -0
- package/lib/network/types.d.ts +122 -0
- package/lib/network/types.d.ts.map +1 -0
- package/lib/network/types.fixture.d.ts +498 -0
- package/lib/network/types.fixture.d.ts.map +1 -0
- package/lib/network/types.fixture.js +4375 -0
- package/lib/network/types.fixture.js.map +1 -0
- package/lib/network/types.js +13 -0
- package/lib/network/types.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +19 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +6 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +11 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +4 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +103 -0
- package/lib/test/bot-deviceActions.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +433 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +1284 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +52 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +155 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/types/bridge.d.ts +245 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +16 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/errors.d.ts +49 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +21 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +21 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +10 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +7 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +24 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +94 -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 +14 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +20 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +63 -0
- package/lib-es/bridge/deviceTransactionConfig.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 +25 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getEstimateFees.d.ts +6 -0
- package/lib-es/bridge/getEstimateFees.d.ts.map +1 -0
- package/lib-es/bridge/getEstimateFees.js +47 -0
- package/lib-es/bridge/getEstimateFees.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 +213 -0
- package/lib-es/bridge/getTransactionStatus.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/preload.d.ts +8 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +27 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +15 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +9 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +229 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +85 -0
- package/lib-es/bridge/signOperation.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 +3 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.js +89 -0
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
- package/lib-es/bridge/synchronization.js +209 -0
- package/lib-es/bridge/synchronization.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +15 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +55 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +10 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +12 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/index.d.ts +3 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/logic/constants.d.ts +4 -0
- package/lib-es/logic/constants.d.ts.map +1 -0
- package/lib-es/logic/constants.js +4 -0
- package/lib-es/logic/constants.js.map +1 -0
- package/lib-es/logic/pagination.d.ts +3 -0
- package/lib-es/logic/pagination.d.ts.map +1 -0
- package/lib-es/logic/pagination.js +15 -0
- package/lib-es/logic/pagination.js.map +1 -0
- package/lib-es/logic/utils.d.ts +12 -0
- package/lib-es/logic/utils.d.ts.map +1 -0
- package/lib-es/logic/utils.js +167 -0
- package/lib-es/logic/utils.js.map +1 -0
- package/lib-es/network/format.d.ts +9 -0
- package/lib-es/network/format.d.ts.map +1 -0
- package/lib-es/network/format.js +117 -0
- package/lib-es/network/format.js.map +1 -0
- package/lib-es/network/index.d.ts +30 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.integ.test.d.ts +2 -0
- package/lib-es/network/index.integ.test.d.ts.map +1 -0
- package/lib-es/network/index.integ.test.js +36 -0
- package/lib-es/network/index.integ.test.js.map +1 -0
- package/lib-es/network/index.js +524 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/index.test.d.ts +2 -0
- package/lib-es/network/index.test.d.ts.map +1 -0
- package/lib-es/network/index.test.js +63 -0
- package/lib-es/network/index.test.js.map +1 -0
- package/lib-es/network/superRepresentativesData.mock.d.ts +69 -0
- package/lib-es/network/superRepresentativesData.mock.d.ts.map +1 -0
- package/lib-es/network/superRepresentativesData.mock.js +2206 -0
- package/lib-es/network/superRepresentativesData.mock.js.map +1 -0
- package/lib-es/network/types.d.ts +122 -0
- package/lib-es/network/types.d.ts.map +1 -0
- package/lib-es/network/types.fixture.d.ts +498 -0
- package/lib-es/network/types.fixture.d.ts.map +1 -0
- package/lib-es/network/types.fixture.js +4371 -0
- package/lib-es/network/types.fixture.js.map +1 -0
- package/lib-es/network/types.js +8 -0
- package/lib-es/network/types.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +17 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +6 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +6 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +4 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +100 -0
- package/lib-es/test/bot-deviceActions.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +428 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +1278 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +52 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +149 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/types/bridge.d.ts +245 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +11 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/errors.d.ts +49 -0
- package/lib-es/types/errors.d.ts.map +1 -0
- package/lib-es/types/errors.js +18 -0
- package/lib-es/types/errors.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +5 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +10 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +133 -0
- package/src/bridge/broadcast.ts +24 -0
- package/src/bridge/buildOptimisticOperation.ts +133 -0
- package/src/bridge/createTransaction.ts +16 -0
- package/src/bridge/deviceTransactionConfig.ts +99 -0
- package/src/bridge/estimateMaxSpendable.ts +32 -0
- package/src/bridge/getEstimateFees.ts +52 -0
- package/src/bridge/getTransactionStatus.ts +263 -0
- package/src/bridge/index.ts +78 -0
- package/src/bridge/preload.ts +24 -0
- package/src/bridge/prepareTransaction.ts +12 -0
- package/src/bridge/serialization.ts +288 -0
- package/src/bridge/signOperation.ts +123 -0
- package/src/bridge/synchronization.integ.test.ts +105 -0
- package/src/bridge/synchronization.ts +284 -0
- package/src/bridge/transaction.ts +84 -0
- package/src/config.ts +24 -0
- package/src/index.ts +3 -0
- package/src/logic/constants.ts +4 -0
- package/src/logic/pagination.ts +21 -0
- package/src/logic/utils.ts +231 -0
- package/src/network/format.ts +148 -0
- package/src/network/index.integ.test.ts +33 -0
- package/src/network/index.test.ts +61 -0
- package/src/network/index.ts +747 -0
- package/src/network/superRepresentativesData.mock.ts +2205 -0
- package/src/network/types.fixture.ts +4476 -0
- package/src/network/types.ts +147 -0
- package/src/signer/getAddress.ts +13 -0
- package/src/signer/index.ts +7 -0
- package/src/test/bot-deviceActions.ts +121 -0
- package/src/test/bot-specs.ts +457 -0
- package/src/test/bridgeDatasetTest.ts +1343 -0
- package/src/test/cli.ts +219 -0
- package/src/test/index.ts +6 -0
- package/src/types/bridge.ts +304 -0
- package/src/types/errors.ts +22 -0
- package/src/types/index.ts +4 -0
- package/src/types/signer.ts +9 -0
- package/tsconfig.json +14 -0
- package/types/tronweb/index.d.ts +5 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { TrongridTxType } from "../types";
|
|
2
|
+
|
|
3
|
+
export type TransactionResponseTronAPI<T> = {
|
|
4
|
+
data: T[];
|
|
5
|
+
success: boolean;
|
|
6
|
+
meta: {
|
|
7
|
+
at: number;
|
|
8
|
+
page_size: number;
|
|
9
|
+
links?: {
|
|
10
|
+
next: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//-- TRANSACTION
|
|
16
|
+
export type TransactionTronAPI<T = TransactionContract> = {
|
|
17
|
+
ret: Ret[];
|
|
18
|
+
signature: string[];
|
|
19
|
+
txID: string;
|
|
20
|
+
tx_id?: string; // Not found in request to TronGrid...
|
|
21
|
+
net_usage: number;
|
|
22
|
+
raw_data_hex: string;
|
|
23
|
+
net_fee: number;
|
|
24
|
+
energy_usage: number;
|
|
25
|
+
blockNumber?: number;
|
|
26
|
+
block_timestamp: number;
|
|
27
|
+
energy_fee: number;
|
|
28
|
+
energy_usage_total: number;
|
|
29
|
+
unfreeze_amount?: number;
|
|
30
|
+
withdraw_amount?: number;
|
|
31
|
+
raw_data: TransactionRawData<T>;
|
|
32
|
+
internal_transactions: any[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Ret = {
|
|
36
|
+
contractRet: string; // Better to have an exhaustive list: "STRING" + ?
|
|
37
|
+
fee?: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type TransactionRawData<T> = {
|
|
41
|
+
contract: Contract<T>[];
|
|
42
|
+
ref_block_bytes: string;
|
|
43
|
+
ref_block_hash: string;
|
|
44
|
+
expiration: number;
|
|
45
|
+
timestamp?: number;
|
|
46
|
+
fee_limit?: number;
|
|
47
|
+
data?: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type Contract<T> = {
|
|
51
|
+
parameter: {
|
|
52
|
+
value: T;
|
|
53
|
+
type_url: string;
|
|
54
|
+
};
|
|
55
|
+
type: TrongridTxType;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type Vote = {
|
|
59
|
+
vote_address: string;
|
|
60
|
+
vote_count: number;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
type TransactionContract = {
|
|
64
|
+
owner_address: string;
|
|
65
|
+
votes?: Vote[];
|
|
66
|
+
resource: any;
|
|
67
|
+
frozen_balance?: number;
|
|
68
|
+
amount?: number;
|
|
69
|
+
to_address?: string;
|
|
70
|
+
data?: string;
|
|
71
|
+
contract_address?: string;
|
|
72
|
+
asset_name?: string;
|
|
73
|
+
frozen_duration?: number;
|
|
74
|
+
resource_type?: "BANDWIDTH" | "ENERGY";
|
|
75
|
+
resource_value?: number;
|
|
76
|
+
quant?: number;
|
|
77
|
+
receiver_address?: string;
|
|
78
|
+
unfreeze_balance?: number;
|
|
79
|
+
balance?: number;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//-- Transaction details
|
|
83
|
+
export type TransactionInfoTronAPI = {
|
|
84
|
+
id: string;
|
|
85
|
+
fee: number;
|
|
86
|
+
blockNumber: number;
|
|
87
|
+
blockTimeStamp: number;
|
|
88
|
+
contractResult: string[];
|
|
89
|
+
receipt: {
|
|
90
|
+
net_usage?: number;
|
|
91
|
+
net_fee?: number;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function isTransactionTronAPI(tx: unknown): tx is TransactionTronAPI {
|
|
96
|
+
return (tx as TransactionTronAPI).txID !== undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//-- TRC20
|
|
100
|
+
export type Trc20API = {
|
|
101
|
+
transaction_id: string;
|
|
102
|
+
token_info: TokenInfo;
|
|
103
|
+
block_timestamp: number;
|
|
104
|
+
from: string;
|
|
105
|
+
to: string;
|
|
106
|
+
detail: TransactionTronAPI<Trc20Contract>;
|
|
107
|
+
type: string;
|
|
108
|
+
value?: string;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type TokenInfo = {
|
|
112
|
+
symbol: string;
|
|
113
|
+
address?: string;
|
|
114
|
+
decimals: number;
|
|
115
|
+
name: string;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
type Trc20Contract = {
|
|
119
|
+
data: string;
|
|
120
|
+
owner_address: string;
|
|
121
|
+
contract_address: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//-- Malformed?
|
|
125
|
+
export type MalformedTransactionTronAPI = {
|
|
126
|
+
internal_tx_id: string;
|
|
127
|
+
data: {
|
|
128
|
+
note: string;
|
|
129
|
+
rejected: boolean;
|
|
130
|
+
call_value: {
|
|
131
|
+
_: number;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
block_timestamp: number;
|
|
135
|
+
to_address: string;
|
|
136
|
+
tx_id: string;
|
|
137
|
+
from_address: string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export function isMalformedTransactionTronAPI(
|
|
141
|
+
tx: TransactionTronAPI | MalformedTransactionTronAPI,
|
|
142
|
+
): tx is MalformedTransactionTronAPI {
|
|
143
|
+
return (
|
|
144
|
+
(tx as MalformedTransactionTronAPI).internal_tx_id !== undefined ||
|
|
145
|
+
(tx as MalformedTransactionTronAPI).tx_id !== undefined
|
|
146
|
+
);
|
|
147
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
4
|
+
import { TronSigner } from "../types";
|
|
5
|
+
|
|
6
|
+
const getAddress = (signerContext: SignerContext<TronSigner>): GetAddressFn => {
|
|
7
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
8
|
+
const r = await signerContext(deviceId, signer => signer.getAddress(path, verify));
|
|
9
|
+
return { ...r, path };
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default getAddress;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { DeviceAction, DeviceActionArg } from "@ledgerhq/coin-framework/bot/types";
|
|
2
|
+
import {
|
|
3
|
+
deviceActionFlow,
|
|
4
|
+
formatDeviceAmount,
|
|
5
|
+
SpeculosButton,
|
|
6
|
+
} from "@ledgerhq/coin-framework/bot/specs";
|
|
7
|
+
import type { Transaction, Vote } from "../types";
|
|
8
|
+
import { Account } from "@ledgerhq/types-live";
|
|
9
|
+
|
|
10
|
+
function subAccount(subAccountId: string, account: Account) {
|
|
11
|
+
const sub = (account.subAccounts || []).find(a => a.id === subAccountId);
|
|
12
|
+
if (!sub || sub.type !== "TokenAccount")
|
|
13
|
+
throw new Error("expected sub account id " + subAccountId);
|
|
14
|
+
return sub;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const resourceExpected = ({ transaction: { resource } }: DeviceActionArg<Transaction, any>) =>
|
|
18
|
+
resource ? resource.slice(0, 1).toUpperCase() + resource.slice(1).toLowerCase() : "";
|
|
19
|
+
|
|
20
|
+
export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
21
|
+
steps: [
|
|
22
|
+
{
|
|
23
|
+
title: "Review",
|
|
24
|
+
button: SpeculosButton.RIGHT, // TODO define expectedValue
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: "Claim",
|
|
28
|
+
button: SpeculosButton.RIGHT,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
title: "Gain",
|
|
32
|
+
button: SpeculosButton.RIGHT,
|
|
33
|
+
expectedValue: arg => resourceExpected(arg),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "Resource",
|
|
37
|
+
button: SpeculosButton.RIGHT,
|
|
38
|
+
expectedValue: arg => resourceExpected(arg),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: "Amount",
|
|
42
|
+
button: SpeculosButton.RIGHT,
|
|
43
|
+
expectedValue: ({ account, status, transaction }) =>
|
|
44
|
+
formatDeviceAmount(
|
|
45
|
+
transaction.subAccountId
|
|
46
|
+
? subAccount(transaction.subAccountId, account).token
|
|
47
|
+
: account.currency,
|
|
48
|
+
status.amount,
|
|
49
|
+
{
|
|
50
|
+
hideCode: true,
|
|
51
|
+
},
|
|
52
|
+
),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: "Token",
|
|
56
|
+
button: SpeculosButton.RIGHT,
|
|
57
|
+
expectedValue: ({ account, transaction }) => {
|
|
58
|
+
const isTokenTransaction = Boolean(transaction.subAccountId);
|
|
59
|
+
if (isTokenTransaction) {
|
|
60
|
+
const token = subAccount(transaction.subAccountId!, account).token;
|
|
61
|
+
const [, tokenType, tokenId] = token.id.split("/");
|
|
62
|
+
if (tokenType === "trc10") {
|
|
63
|
+
return `${token.name.split(" ")[0]}[${tokenId}]`;
|
|
64
|
+
} else {
|
|
65
|
+
return token.ticker;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return "TRX";
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: "From Address",
|
|
73
|
+
button: SpeculosButton.RIGHT,
|
|
74
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
title: "Freeze To",
|
|
78
|
+
button: SpeculosButton.RIGHT,
|
|
79
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
title: "Delegated To",
|
|
83
|
+
button: SpeculosButton.RIGHT,
|
|
84
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
title: "To",
|
|
88
|
+
button: SpeculosButton.RIGHT,
|
|
89
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
title: "Sign",
|
|
93
|
+
button: SpeculosButton.BOTH,
|
|
94
|
+
final: true,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
fallback: ({ event, transaction }) => {
|
|
98
|
+
if (transaction.mode === "vote") {
|
|
99
|
+
for (const vote of transaction.votes) {
|
|
100
|
+
const title = `${vote.address.slice(0, 5)}...${vote.address.slice(
|
|
101
|
+
vote.address.length - 5,
|
|
102
|
+
)}`;
|
|
103
|
+
|
|
104
|
+
if (event.text === title) {
|
|
105
|
+
return voteAction(vote, title);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
function voteAction(
|
|
113
|
+
vote: Vote,
|
|
114
|
+
title: string,
|
|
115
|
+
): { title: string; button: SpeculosButton; expectedValue: () => string } {
|
|
116
|
+
return {
|
|
117
|
+
title,
|
|
118
|
+
button: SpeculosButton.RIGHT,
|
|
119
|
+
expectedValue: () => String(vote.voteCount),
|
|
120
|
+
};
|
|
121
|
+
}
|