@ledgerhq/coin-tron 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +14 -0
- package/lib/bridge/broadcast.js +3 -12
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +9 -12
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getEstimateFees.js +7 -17
- package/lib/bridge/getEstimateFees.js.map +1 -1
- package/lib/bridge/getTransactionStatus.js +18 -26
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/preload.js +3 -12
- package/lib/bridge/preload.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -13
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/serialization.js +8 -8
- package/lib/bridge/serialization.js.map +1 -1
- package/lib/bridge/signOperation.js +39 -53
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/synchronization.integ.test.js +10 -15
- package/lib/bridge/synchronization.integ.test.js.map +1 -1
- package/lib/bridge/synchronization.js +25 -23
- package/lib/bridge/synchronization.js.map +1 -1
- package/lib/bridge/transaction.js +20 -4
- package/lib/bridge/transaction.js.map +1 -1
- package/lib/logic/utils.test.js +21 -10
- package/lib/logic/utils.test.js.map +1 -1
- package/lib/network/format.js +4 -5
- package/lib/network/format.js.map +1 -1
- package/lib/network/index.integ.test.js +3 -12
- package/lib/network/index.integ.test.js.map +1 -1
- package/lib/network/index.js +296 -321
- package/lib/network/index.js.map +1 -1
- package/lib/network/index.test.js +4 -14
- package/lib/network/index.test.js.map +1 -1
- package/lib/signer/getAddress.js +4 -13
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/test/bridgeDatasetTest.js +33 -7
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/cli.js +7 -2
- package/lib/test/cli.js.map +1 -1
- package/lib-es/bridge/broadcast.js +3 -12
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +9 -12
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getEstimateFees.js +7 -17
- package/lib-es/bridge/getEstimateFees.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +18 -26
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/preload.js +3 -12
- package/lib-es/bridge/preload.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -13
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/serialization.js +8 -8
- package/lib-es/bridge/serialization.js.map +1 -1
- package/lib-es/bridge/signOperation.js +39 -53
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/synchronization.integ.test.js +10 -15
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -1
- package/lib-es/bridge/synchronization.js +25 -23
- package/lib-es/bridge/synchronization.js.map +1 -1
- package/lib-es/bridge/transaction.js +20 -4
- package/lib-es/bridge/transaction.js.map +1 -1
- package/lib-es/logic/utils.test.js +21 -10
- package/lib-es/logic/utils.test.js.map +1 -1
- package/lib-es/network/format.js +4 -5
- package/lib-es/network/format.js.map +1 -1
- package/lib-es/network/index.integ.test.js +3 -12
- package/lib-es/network/index.integ.test.js.map +1 -1
- package/lib-es/network/index.js +296 -321
- package/lib-es/network/index.js.map +1 -1
- package/lib-es/network/index.test.js +4 -14
- package/lib-es/network/index.test.js.map +1 -1
- package/lib-es/signer/getAddress.js +4 -13
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +33 -7
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/cli.js +7 -2
- package/lib-es/test/cli.js.map +1 -1
- package/package.json +4 -4
- package/tsconfig.json +0 -1
package/lib/network/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -36,74 +27,68 @@ const format_1 = require("./format");
|
|
|
36
27
|
const types_1 = require("./types");
|
|
37
28
|
const querystring_1 = require("querystring");
|
|
38
29
|
const getBaseApiUrl = () => (0, config_1.getCoinConfig)().explorer.url;
|
|
39
|
-
function post(endPoint, body) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
data: body,
|
|
45
|
-
});
|
|
46
|
-
// Ugly but trongrid send a 200 status event if there are errors
|
|
47
|
-
if ("Error" in data) {
|
|
48
|
-
(0, logs_1.log)("tron-error", (0, querystring_1.stringify)(data.Error), {
|
|
49
|
-
endPoint,
|
|
50
|
-
body,
|
|
51
|
-
});
|
|
52
|
-
throw new Error((0, querystring_1.stringify)(data.Error));
|
|
53
|
-
}
|
|
54
|
-
return data;
|
|
30
|
+
async function post(endPoint, body) {
|
|
31
|
+
const { data } = await (0, live_network_1.default)({
|
|
32
|
+
method: "POST",
|
|
33
|
+
url: `${getBaseApiUrl()}${endPoint}`,
|
|
34
|
+
data: body,
|
|
55
35
|
});
|
|
36
|
+
// Ugly but trongrid send a 200 status event if there are errors
|
|
37
|
+
if ("Error" in data) {
|
|
38
|
+
(0, logs_1.log)("tron-error", (0, querystring_1.stringify)(data.Error), {
|
|
39
|
+
endPoint,
|
|
40
|
+
body,
|
|
41
|
+
});
|
|
42
|
+
throw new Error((0, querystring_1.stringify)(data.Error));
|
|
43
|
+
}
|
|
44
|
+
return data;
|
|
56
45
|
}
|
|
57
|
-
function fetch(endPoint) {
|
|
58
|
-
return
|
|
59
|
-
return fetchWithBaseUrl(`${getBaseApiUrl()}${endPoint}`);
|
|
60
|
-
});
|
|
46
|
+
async function fetch(endPoint) {
|
|
47
|
+
return fetchWithBaseUrl(`${getBaseApiUrl()}${endPoint}`);
|
|
61
48
|
}
|
|
62
|
-
function fetchWithBaseUrl(url) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return data;
|
|
73
|
-
});
|
|
49
|
+
async function fetchWithBaseUrl(url) {
|
|
50
|
+
const { data } = await (0, live_network_1.default)({ url });
|
|
51
|
+
// Ugly but trongrid send a 200 status event if there are errors
|
|
52
|
+
if ("Error" in data) {
|
|
53
|
+
(0, logs_1.log)("tron-error", (0, querystring_1.stringify)(data.Error), {
|
|
54
|
+
url,
|
|
55
|
+
});
|
|
56
|
+
throw new Error((0, querystring_1.stringify)(data.Error));
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
74
59
|
}
|
|
75
|
-
const freezeTronTransaction = (account, transaction) =>
|
|
60
|
+
const freezeTronTransaction = async (account, transaction) => {
|
|
76
61
|
const txData = {
|
|
77
62
|
frozen_balance: transaction.amount.toNumber(),
|
|
78
63
|
resource: transaction.resource,
|
|
79
64
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
80
65
|
};
|
|
81
66
|
const url = `/wallet/freezebalancev2`;
|
|
82
|
-
const result =
|
|
67
|
+
const result = await post(url, txData);
|
|
83
68
|
return result;
|
|
84
|
-
}
|
|
69
|
+
};
|
|
85
70
|
exports.freezeTronTransaction = freezeTronTransaction;
|
|
86
|
-
const unfreezeTronTransaction = (account, transaction) =>
|
|
71
|
+
const unfreezeTronTransaction = async (account, transaction) => {
|
|
87
72
|
const txData = {
|
|
88
73
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
89
74
|
resource: transaction.resource,
|
|
90
75
|
unfreeze_balance: transaction.amount.toNumber(),
|
|
91
76
|
};
|
|
92
77
|
const url = `/wallet/unfreezebalancev2`;
|
|
93
|
-
const result =
|
|
78
|
+
const result = await post(url, txData);
|
|
94
79
|
return result;
|
|
95
|
-
}
|
|
80
|
+
};
|
|
96
81
|
exports.unfreezeTronTransaction = unfreezeTronTransaction;
|
|
97
|
-
const withdrawExpireUnfreezeTronTransaction = (account, _transaction) =>
|
|
82
|
+
const withdrawExpireUnfreezeTronTransaction = async (account, _transaction) => {
|
|
98
83
|
const txData = {
|
|
99
84
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
100
85
|
};
|
|
101
86
|
const url = `/wallet/withdrawexpireunfreeze`;
|
|
102
|
-
const result =
|
|
87
|
+
const result = await post(url, txData);
|
|
103
88
|
return result;
|
|
104
|
-
}
|
|
89
|
+
};
|
|
105
90
|
exports.withdrawExpireUnfreezeTronTransaction = withdrawExpireUnfreezeTronTransaction;
|
|
106
|
-
const unDelegateResourceTransaction = (account, transaction) =>
|
|
91
|
+
const unDelegateResourceTransaction = async (account, transaction) => {
|
|
107
92
|
const txData = {
|
|
108
93
|
balance: transaction.amount.toNumber(),
|
|
109
94
|
resource: transaction.resource,
|
|
@@ -111,43 +96,41 @@ const unDelegateResourceTransaction = (account, transaction) => __awaiter(void 0
|
|
|
111
96
|
receiver_address: (0, format_1.decode58Check)(transaction.recipient),
|
|
112
97
|
};
|
|
113
98
|
const url = `/wallet/undelegateresource`;
|
|
114
|
-
const result =
|
|
99
|
+
const result = await post(url, txData);
|
|
115
100
|
return result;
|
|
116
|
-
}
|
|
101
|
+
};
|
|
117
102
|
exports.unDelegateResourceTransaction = unDelegateResourceTransaction;
|
|
118
|
-
const legacyUnfreezeTronTransaction = (account, transaction) =>
|
|
103
|
+
const legacyUnfreezeTronTransaction = async (account, transaction) => {
|
|
119
104
|
const txData = {
|
|
120
105
|
resource: transaction.resource,
|
|
121
106
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
122
107
|
receiver_address: transaction.recipient ? (0, format_1.decode58Check)(transaction.recipient) : undefined,
|
|
123
108
|
};
|
|
124
109
|
const url = `/wallet/unfreezebalance`;
|
|
125
|
-
const result =
|
|
110
|
+
const result = await post(url, txData);
|
|
126
111
|
return result;
|
|
127
|
-
}
|
|
112
|
+
};
|
|
128
113
|
exports.legacyUnfreezeTronTransaction = legacyUnfreezeTronTransaction;
|
|
129
|
-
function getDelegatedResource(account, transaction, resource) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
toAddress: (0, format_1.decode58Check)(transaction.recipient),
|
|
135
|
-
});
|
|
136
|
-
const { frozen_balance_for_bandwidth, frozen_balance_for_energy } = delegatedResource.reduce((accum, cur) => {
|
|
137
|
-
if (cur.frozen_balance_for_bandwidth) {
|
|
138
|
-
accum.frozen_balance_for_bandwidth += cur.frozen_balance_for_bandwidth;
|
|
139
|
-
}
|
|
140
|
-
if (cur.frozen_balance_for_energy) {
|
|
141
|
-
accum.frozen_balance_for_energy += cur.frozen_balance_for_energy;
|
|
142
|
-
}
|
|
143
|
-
return accum;
|
|
144
|
-
}, { frozen_balance_for_bandwidth: 0, frozen_balance_for_energy: 0 });
|
|
145
|
-
const amount = resource === "BANDWIDTH" ? frozen_balance_for_bandwidth : frozen_balance_for_energy;
|
|
146
|
-
return new bignumber_js_1.BigNumber(amount);
|
|
114
|
+
async function getDelegatedResource(account, transaction, resource) {
|
|
115
|
+
const url = `/wallet/getdelegatedresourcev2`;
|
|
116
|
+
const { delegatedResource = [], } = await post(url, {
|
|
117
|
+
fromAddress: (0, format_1.decode58Check)(account.freshAddress),
|
|
118
|
+
toAddress: (0, format_1.decode58Check)(transaction.recipient),
|
|
147
119
|
});
|
|
120
|
+
const { frozen_balance_for_bandwidth, frozen_balance_for_energy } = delegatedResource.reduce((accum, cur) => {
|
|
121
|
+
if (cur.frozen_balance_for_bandwidth) {
|
|
122
|
+
accum.frozen_balance_for_bandwidth += cur.frozen_balance_for_bandwidth;
|
|
123
|
+
}
|
|
124
|
+
if (cur.frozen_balance_for_energy) {
|
|
125
|
+
accum.frozen_balance_for_energy += cur.frozen_balance_for_energy;
|
|
126
|
+
}
|
|
127
|
+
return accum;
|
|
128
|
+
}, { frozen_balance_for_bandwidth: 0, frozen_balance_for_energy: 0 });
|
|
129
|
+
const amount = resource === "BANDWIDTH" ? frozen_balance_for_bandwidth : frozen_balance_for_energy;
|
|
130
|
+
return new bignumber_js_1.BigNumber(amount);
|
|
148
131
|
}
|
|
149
132
|
// Send trx or trc10/trc20 tokens
|
|
150
|
-
const createTronTransaction = (account, transaction, subAccount) =>
|
|
133
|
+
const createTronTransaction = async (account, transaction, subAccount) => {
|
|
151
134
|
const [tokenType, tokenId] = subAccount && subAccount.type === "TokenAccount"
|
|
152
135
|
? (0, drop_1.default)(subAccount.token.id.split("/"), 1)
|
|
153
136
|
: [undefined, undefined];
|
|
@@ -163,7 +146,7 @@ const createTronTransaction = (account, transaction, subAccount) => __awaiter(vo
|
|
|
163
146
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
164
147
|
};
|
|
165
148
|
const url = `/wallet/triggersmartcontract`;
|
|
166
|
-
const { transaction: preparedTransaction } =
|
|
149
|
+
const { transaction: preparedTransaction } = await post(url, txData);
|
|
167
150
|
return extendTronTxExpirationTimeBy10mn(preparedTransaction);
|
|
168
151
|
}
|
|
169
152
|
else {
|
|
@@ -175,11 +158,11 @@ const createTronTransaction = (account, transaction, subAccount) => __awaiter(vo
|
|
|
175
158
|
asset_name: tokenId && Buffer.from(tokenId).toString("hex"),
|
|
176
159
|
};
|
|
177
160
|
const url = subAccount ? `/wallet/transferasset` : `/wallet/createtransaction`;
|
|
178
|
-
const preparedTransaction =
|
|
161
|
+
const preparedTransaction = await post(url, txData);
|
|
179
162
|
// for the ledger Vault we need to increase the expiration
|
|
180
163
|
return extendTronTxExpirationTimeBy10mn(preparedTransaction);
|
|
181
164
|
}
|
|
182
|
-
}
|
|
165
|
+
};
|
|
183
166
|
exports.createTronTransaction = createTronTransaction;
|
|
184
167
|
function extendTronTxExpirationTimeBy10mn(preparedTransaction) {
|
|
185
168
|
const VAULT_EXPIRATION_TIME = 600;
|
|
@@ -191,116 +174,104 @@ function extendTronTxExpirationTimeBy10mn(preparedTransaction) {
|
|
|
191
174
|
//FIXME: test it and rewrite it
|
|
192
175
|
return tronWeb.transactionBuilder.extendExpiration(preparedTransaction, VAULT_EXPIRATION_TIME);
|
|
193
176
|
}
|
|
194
|
-
const broadcastTron = (trxTransaction) =>
|
|
195
|
-
const result =
|
|
177
|
+
const broadcastTron = async (trxTransaction) => {
|
|
178
|
+
const result = await post(`/wallet/broadcasttransaction`, trxTransaction);
|
|
196
179
|
if (result.code === "TRANSACTION_EXPIRATION_ERROR") {
|
|
197
180
|
throw new errors_1.TronTransactionExpired();
|
|
198
181
|
}
|
|
199
182
|
return result;
|
|
200
|
-
}
|
|
183
|
+
};
|
|
201
184
|
exports.broadcastTron = broadcastTron;
|
|
202
|
-
function fetchTronAccount(addr) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
});
|
|
185
|
+
async function fetchTronAccount(addr) {
|
|
186
|
+
try {
|
|
187
|
+
const data = await fetch(`/v1/accounts/${addr}`);
|
|
188
|
+
return data.data;
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
return [];
|
|
192
|
+
}
|
|
212
193
|
}
|
|
213
|
-
function fetchCurrentBlockHeight() {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return data.block_header.raw_data.number;
|
|
217
|
-
});
|
|
194
|
+
async function fetchCurrentBlockHeight() {
|
|
195
|
+
const data = await fetch(`/wallet/getnowblock`);
|
|
196
|
+
return data.block_header.raw_data.number;
|
|
218
197
|
}
|
|
219
198
|
// For the moment, fetching transaction info is the only way to get fees from a transaction
|
|
220
|
-
function fetchTronTxDetail(txId) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
};
|
|
229
|
-
});
|
|
199
|
+
async function fetchTronTxDetail(txId) {
|
|
200
|
+
const { fee, blockNumber, withdraw_amount, unfreeze_amount } = await fetch(`/wallet/gettransactioninfobyid?value=${encodeURIComponent(txId)}`);
|
|
201
|
+
return {
|
|
202
|
+
fee,
|
|
203
|
+
blockNumber,
|
|
204
|
+
withdraw_amount,
|
|
205
|
+
unfreeze_amount,
|
|
206
|
+
};
|
|
230
207
|
}
|
|
231
|
-
function getAllTransactions(initialUrl, shouldFetchMoreTxs, getTxs) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return all;
|
|
241
|
-
});
|
|
208
|
+
async function getAllTransactions(initialUrl, shouldFetchMoreTxs, getTxs) {
|
|
209
|
+
let all = [];
|
|
210
|
+
let url = initialUrl;
|
|
211
|
+
while (url && shouldFetchMoreTxs(all)) {
|
|
212
|
+
const { nextUrl, results } = await getTxs(url);
|
|
213
|
+
url = nextUrl;
|
|
214
|
+
all = all.concat(results);
|
|
215
|
+
}
|
|
216
|
+
return all;
|
|
242
217
|
}
|
|
243
|
-
const getTransactions = (cacheTransactionInfoById) => (url) =>
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
const results = yield (0, live_promise_1.promiseAllBatched)(3, transactions.data || [], (tx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
218
|
+
const getTransactions = (cacheTransactionInfoById) => async (url) => {
|
|
219
|
+
const transactions = await fetchWithBaseUrl(url);
|
|
220
|
+
const nextUrl = transactions.meta.links?.next?.replace(/https:\/\/api(\.[a-z]*)?.trongrid.io/, getBaseApiUrl());
|
|
221
|
+
const results = await (0, live_promise_1.promiseAllBatched)(3, transactions.data || [], async (tx) => {
|
|
248
222
|
if ((0, types_1.isMalformedTransactionTronAPI)(tx)) {
|
|
249
223
|
return tx;
|
|
250
224
|
}
|
|
251
225
|
const txID = tx.txID;
|
|
252
|
-
const detail = cacheTransactionInfoById[txID] || (
|
|
226
|
+
const detail = cacheTransactionInfoById[txID] || (await fetchTronTxDetail(txID));
|
|
253
227
|
cacheTransactionInfoById[txID] = detail;
|
|
254
|
-
return
|
|
255
|
-
})
|
|
228
|
+
return { ...tx, detail };
|
|
229
|
+
});
|
|
256
230
|
return {
|
|
257
231
|
results,
|
|
258
232
|
nextUrl,
|
|
259
233
|
};
|
|
260
|
-
}
|
|
261
|
-
const getTrc20 = (url) =>
|
|
262
|
-
|
|
263
|
-
const transactions = yield fetchWithBaseUrl(url);
|
|
234
|
+
};
|
|
235
|
+
const getTrc20 = async (url) => {
|
|
236
|
+
const transactions = await fetchWithBaseUrl(url);
|
|
264
237
|
return {
|
|
265
238
|
results: transactions.data,
|
|
266
|
-
nextUrl:
|
|
239
|
+
nextUrl: transactions.meta.links?.next?.replace(/https:\/\/api(\.[a-z]*)?.trongrid.io/, getBaseApiUrl()),
|
|
267
240
|
};
|
|
268
|
-
}
|
|
269
|
-
function fetchTronAccountTxs(addr, shouldFetchMoreTxs, cacheTransactionInfoById) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return txInfos;
|
|
290
|
-
});
|
|
241
|
+
};
|
|
242
|
+
async function fetchTronAccountTxs(addr, shouldFetchMoreTxs, cacheTransactionInfoById) {
|
|
243
|
+
const entireTxs = (await getAllTransactions(`${getBaseApiUrl()}/v1/accounts/${addr}/transactions?limit=100`, shouldFetchMoreTxs, getTransactions(cacheTransactionInfoById)))
|
|
244
|
+
.filter((tx) => (0, types_1.isTransactionTronAPI)(tx))
|
|
245
|
+
.filter(tx => {
|
|
246
|
+
// custom smart contract tx has internal txs
|
|
247
|
+
const hasInternalTxs = tx.txID && tx.internal_transactions && tx.internal_transactions.length > 0;
|
|
248
|
+
// and also a duplicated malformed tx that we have to ignore
|
|
249
|
+
const isDuplicated = tx.tx_id;
|
|
250
|
+
const type = tx.raw_data.contract[0].type;
|
|
251
|
+
if (hasInternalTxs) {
|
|
252
|
+
// log once
|
|
253
|
+
(0, logs_1.log)("tron-error", `unsupported transaction ${tx.txID}`);
|
|
254
|
+
}
|
|
255
|
+
return !isDuplicated && !hasInternalTxs && type !== "TriggerSmartContract";
|
|
256
|
+
})
|
|
257
|
+
.map(tx => (0, format_1.formatTrongridTxResponse)(tx));
|
|
258
|
+
// we need to fetch and filter trc20 transactions from another endpoint
|
|
259
|
+
const entireTrc20Txs = (await getAllTransactions(`${getBaseApiUrl()}/v1/accounts/${addr}/transactions/trc20?get_detail=true`, shouldFetchMoreTxs, getTrc20)).map(tx => (0, format_1.formatTrongridTrc20TxResponse)(tx));
|
|
260
|
+
const txInfos = (0, compact_1.default)(entireTxs.concat(entireTrc20Txs)).sort((a, b) => b.date.getTime() - a.date.getTime());
|
|
261
|
+
return txInfos;
|
|
291
262
|
}
|
|
292
|
-
const getContractUserEnergyRatioConsumption = (address) =>
|
|
293
|
-
const result =
|
|
263
|
+
const getContractUserEnergyRatioConsumption = async (address) => {
|
|
264
|
+
const result = await (0, exports.fetchTronContract)(address);
|
|
294
265
|
if (result) {
|
|
295
266
|
const { consume_user_resource_percent } = result;
|
|
296
267
|
return consume_user_resource_percent;
|
|
297
268
|
}
|
|
298
269
|
return 0;
|
|
299
|
-
}
|
|
270
|
+
};
|
|
300
271
|
exports.getContractUserEnergyRatioConsumption = getContractUserEnergyRatioConsumption;
|
|
301
|
-
const fetchTronContract = (addr) =>
|
|
272
|
+
const fetchTronContract = async (addr) => {
|
|
302
273
|
try {
|
|
303
|
-
const data =
|
|
274
|
+
const data = await post(`/wallet/getcontract`, {
|
|
304
275
|
value: (0, format_1.decode58Check)(addr),
|
|
305
276
|
});
|
|
306
277
|
return Object.keys(data).length !== 0 ? data : undefined;
|
|
@@ -308,10 +279,10 @@ const fetchTronContract = (addr) => __awaiter(void 0, void 0, void 0, function*
|
|
|
308
279
|
catch (e) {
|
|
309
280
|
return undefined;
|
|
310
281
|
}
|
|
311
|
-
}
|
|
282
|
+
};
|
|
312
283
|
exports.fetchTronContract = fetchTronContract;
|
|
313
|
-
const getTronAccountNetwork = (address) =>
|
|
314
|
-
const result =
|
|
284
|
+
const getTronAccountNetwork = async (address) => {
|
|
285
|
+
const result = await fetch(`/wallet/getaccountresource?address=${encodeURIComponent((0, format_1.decode58Check)(address))}`);
|
|
315
286
|
const { freeNetUsed = 0, freeNetLimit = 0, NetUsed = 0, NetLimit = 0, EnergyUsed = 0, EnergyLimit = 0, } = result;
|
|
316
287
|
return {
|
|
317
288
|
family: "tron",
|
|
@@ -322,11 +293,11 @@ const getTronAccountNetwork = (address) => __awaiter(void 0, void 0, void 0, fun
|
|
|
322
293
|
energyUsed: new bignumber_js_1.BigNumber(EnergyUsed),
|
|
323
294
|
energyLimit: new bignumber_js_1.BigNumber(EnergyLimit),
|
|
324
295
|
};
|
|
325
|
-
}
|
|
296
|
+
};
|
|
326
297
|
exports.getTronAccountNetwork = getTronAccountNetwork;
|
|
327
|
-
const validateAddress = (address) =>
|
|
298
|
+
const validateAddress = async (address) => {
|
|
328
299
|
try {
|
|
329
|
-
const result =
|
|
300
|
+
const result = await post(`/wallet/validateaddress`, {
|
|
330
301
|
address: (0, format_1.decode58Check)(address),
|
|
331
302
|
});
|
|
332
303
|
return result.result || false;
|
|
@@ -338,68 +309,75 @@ const validateAddress = (address) => __awaiter(void 0, void 0, void 0, function*
|
|
|
338
309
|
});
|
|
339
310
|
return false;
|
|
340
311
|
}
|
|
341
|
-
}
|
|
312
|
+
};
|
|
342
313
|
exports.validateAddress = validateAddress;
|
|
343
314
|
// cache for account names (name is unchanged over time)
|
|
344
|
-
const accountNamesCache = (0, cache_1.makeLRUCache)((addr) =>
|
|
315
|
+
const accountNamesCache = (0, cache_1.makeLRUCache)(async (addr) => (0, exports.getAccountName)(addr), (addr) => addr, (0, cache_1.hours)(3, 300));
|
|
345
316
|
// cache for super representative brokerages (brokerage is unchanged over time)
|
|
346
|
-
const srBrokeragesCache = (0, cache_1.makeLRUCache)((addr) =>
|
|
347
|
-
const getAccountName = (addr) =>
|
|
348
|
-
const tronAcc =
|
|
317
|
+
const srBrokeragesCache = (0, cache_1.makeLRUCache)(async (addr) => (0, exports.getBrokerage)(addr), (addr) => addr, (0, cache_1.hours)(3, 300));
|
|
318
|
+
const getAccountName = async (addr) => {
|
|
319
|
+
const tronAcc = await fetchTronAccount(addr);
|
|
349
320
|
const acc = tronAcc[0];
|
|
350
321
|
const accountName = acc && acc.account_name ? (0, utils_1.hexToAscii)(acc.account_name) : undefined;
|
|
351
322
|
accountNamesCache.hydrate(addr, accountName); // put it in cache
|
|
352
323
|
return accountName;
|
|
353
|
-
}
|
|
324
|
+
};
|
|
354
325
|
exports.getAccountName = getAccountName;
|
|
355
|
-
const getBrokerage = (addr) =>
|
|
356
|
-
const { brokerage } =
|
|
326
|
+
const getBrokerage = async (addr) => {
|
|
327
|
+
const { brokerage } = await fetch(`/wallet/getBrokerage?address=${encodeURIComponent(addr)}`);
|
|
357
328
|
srBrokeragesCache.hydrate(addr, brokerage); // put it in cache
|
|
358
329
|
return brokerage;
|
|
359
|
-
}
|
|
330
|
+
};
|
|
360
331
|
exports.getBrokerage = getBrokerage;
|
|
361
|
-
const superRepresentativesCache = (0, cache_1.makeLRUCache)(() =>
|
|
362
|
-
const superRepresentatives =
|
|
332
|
+
const superRepresentativesCache = (0, cache_1.makeLRUCache)(async () => {
|
|
333
|
+
const superRepresentatives = await fetchSuperRepresentatives();
|
|
363
334
|
(0, logs_1.log)("tron/superRepresentatives", "loaded " + superRepresentatives.length + " super representatives");
|
|
364
335
|
return superRepresentatives;
|
|
365
|
-
}
|
|
366
|
-
const getTronSuperRepresentatives = () =>
|
|
367
|
-
return
|
|
368
|
-
}
|
|
336
|
+
}, () => "", (0, cache_1.hours)(1, 300));
|
|
337
|
+
const getTronSuperRepresentatives = async () => {
|
|
338
|
+
return await superRepresentativesCache();
|
|
339
|
+
};
|
|
369
340
|
exports.getTronSuperRepresentatives = getTronSuperRepresentatives;
|
|
370
341
|
const hydrateSuperRepresentatives = (list) => {
|
|
371
342
|
(0, logs_1.log)("tron/superRepresentatives", "hydrate " + list.length + " super representatives");
|
|
372
343
|
superRepresentativesCache.hydrate("", list);
|
|
373
344
|
};
|
|
374
345
|
exports.hydrateSuperRepresentatives = hydrateSuperRepresentatives;
|
|
375
|
-
const fetchSuperRepresentatives = () =>
|
|
376
|
-
const result =
|
|
346
|
+
const fetchSuperRepresentatives = async () => {
|
|
347
|
+
const result = await fetch(`/wallet/listwitnesses`);
|
|
377
348
|
const sorted = result.witnesses.sort((a, b) => b.voteCount - a.voteCount);
|
|
378
|
-
const superRepresentatives =
|
|
349
|
+
const superRepresentatives = await (0, live_promise_1.promiseAllBatched)(3, sorted, async (w) => {
|
|
379
350
|
const encodedAddress = (0, format_1.encode58Check)(w.address);
|
|
380
|
-
const accountName =
|
|
381
|
-
const brokerage =
|
|
382
|
-
return
|
|
383
|
-
|
|
351
|
+
const accountName = await accountNamesCache(encodedAddress);
|
|
352
|
+
const brokerage = await srBrokeragesCache(encodedAddress);
|
|
353
|
+
return {
|
|
354
|
+
...w,
|
|
355
|
+
address: encodedAddress,
|
|
356
|
+
name: accountName,
|
|
357
|
+
brokerage,
|
|
358
|
+
voteCount: w.voteCount || 0,
|
|
359
|
+
isJobs: w.isJobs || false,
|
|
360
|
+
};
|
|
361
|
+
});
|
|
384
362
|
(0, exports.hydrateSuperRepresentatives)(superRepresentatives); // put it in cache
|
|
385
363
|
return superRepresentatives;
|
|
386
|
-
}
|
|
387
|
-
const getNextVotingDate = () =>
|
|
388
|
-
const { num } =
|
|
364
|
+
};
|
|
365
|
+
const getNextVotingDate = async () => {
|
|
366
|
+
const { num } = await fetch(`/wallet/getnextmaintenancetime`);
|
|
389
367
|
return new Date(num);
|
|
390
|
-
}
|
|
368
|
+
};
|
|
391
369
|
exports.getNextVotingDate = getNextVotingDate;
|
|
392
|
-
const getTronSuperRepresentativeData = (max) =>
|
|
393
|
-
const list =
|
|
394
|
-
const nextVotingDate =
|
|
370
|
+
const getTronSuperRepresentativeData = async (max) => {
|
|
371
|
+
const list = await (0, exports.getTronSuperRepresentatives)();
|
|
372
|
+
const nextVotingDate = await (0, exports.getNextVotingDate)();
|
|
395
373
|
return {
|
|
396
374
|
list: max ? (0, take_1.default)(list, max) : list,
|
|
397
375
|
totalVotes: (0, sumBy_1.default)(list, "voteCount"),
|
|
398
376
|
nextVotingDate,
|
|
399
377
|
};
|
|
400
|
-
}
|
|
378
|
+
};
|
|
401
379
|
exports.getTronSuperRepresentativeData = getTronSuperRepresentativeData;
|
|
402
|
-
const voteTronSuperRepresentatives = (account, transaction) =>
|
|
380
|
+
const voteTronSuperRepresentatives = async (account, transaction) => {
|
|
403
381
|
const payload = {
|
|
404
382
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
405
383
|
votes: transaction.votes.map(v => ({
|
|
@@ -407,149 +385,146 @@ const voteTronSuperRepresentatives = (account, transaction) => __awaiter(void 0,
|
|
|
407
385
|
vote_count: v.voteCount,
|
|
408
386
|
})),
|
|
409
387
|
};
|
|
410
|
-
return
|
|
411
|
-
}
|
|
388
|
+
return await post(`/wallet/votewitnessaccount`, payload);
|
|
389
|
+
};
|
|
412
390
|
exports.voteTronSuperRepresentatives = voteTronSuperRepresentatives;
|
|
413
|
-
function getTronResources(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
391
|
+
async function getTronResources(acc, txs, cacheTransactionInfoById = {}) {
|
|
392
|
+
if (!acc) {
|
|
393
|
+
return utils_1.defaultTronResources;
|
|
394
|
+
}
|
|
395
|
+
const delegatedFrozenBandwidth = (0, get_1.default)(acc, "delegated_frozenV2_balance_for_bandwidth", undefined);
|
|
396
|
+
const delegatedFrozenEnergy = (0, get_1.default)(acc, "account_resource.delegated_frozenV2_balance_for_energy", undefined);
|
|
397
|
+
const frozenBalances = (0, get_1.default)(acc, "frozenV2", undefined);
|
|
398
|
+
const legacyFrozenBandwidth = (0, get_1.default)(acc, "frozen[0]", undefined);
|
|
399
|
+
const legacyFrozenEnergy = (0, get_1.default)(acc, "account_resource.frozen_balance_for_energy", undefined);
|
|
400
|
+
const legacyFrozen = {
|
|
401
|
+
bandwidth: legacyFrozenBandwidth
|
|
402
|
+
? {
|
|
403
|
+
amount: new bignumber_js_1.BigNumber(legacyFrozenBandwidth.frozen_balance),
|
|
404
|
+
expiredAt: new Date(legacyFrozenBandwidth.expire_time),
|
|
405
|
+
}
|
|
406
|
+
: undefined,
|
|
407
|
+
energy: legacyFrozenEnergy
|
|
408
|
+
? {
|
|
409
|
+
amount: new bignumber_js_1.BigNumber(legacyFrozenEnergy.frozen_balance),
|
|
410
|
+
expiredAt: new Date(legacyFrozenEnergy.expire_time),
|
|
411
|
+
}
|
|
412
|
+
: undefined,
|
|
413
|
+
};
|
|
414
|
+
const { frozenEnergy, frozenBandwidth } = frozenBalances.reduce((accum, cur) => {
|
|
415
|
+
const amount = new bignumber_js_1.BigNumber(cur?.amount ?? 0);
|
|
416
|
+
if (cur.type === "ENERGY") {
|
|
417
|
+
accum.frozenEnergy = accum.frozenEnergy.plus(amount);
|
|
417
418
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
}
|
|
435
|
-
: undefined,
|
|
436
|
-
};
|
|
437
|
-
const { frozenEnergy, frozenBandwidth } = frozenBalances.reduce((accum, cur) => {
|
|
438
|
-
var _a;
|
|
439
|
-
const amount = new bignumber_js_1.BigNumber((_a = cur === null || cur === void 0 ? void 0 : cur.amount) !== null && _a !== void 0 ? _a : 0);
|
|
440
|
-
if (cur.type === "ENERGY") {
|
|
441
|
-
accum.frozenEnergy = accum.frozenEnergy.plus(amount);
|
|
419
|
+
else if (cur.type === undefined) {
|
|
420
|
+
accum.frozenBandwidth = accum.frozenBandwidth.plus(amount);
|
|
421
|
+
}
|
|
422
|
+
return accum;
|
|
423
|
+
}, {
|
|
424
|
+
frozenEnergy: new bignumber_js_1.BigNumber(0),
|
|
425
|
+
frozenBandwidth: new bignumber_js_1.BigNumber(0),
|
|
426
|
+
});
|
|
427
|
+
const unFrozenBalances = (0, get_1.default)(acc, "unfrozenV2", undefined);
|
|
428
|
+
const unFrozen = unFrozenBalances
|
|
429
|
+
? unFrozenBalances.reduce((accum, cur) => {
|
|
430
|
+
if (cur && cur.type === "ENERGY") {
|
|
431
|
+
accum.energy.push({
|
|
432
|
+
amount: new bignumber_js_1.BigNumber(cur.unfreeze_amount),
|
|
433
|
+
expireTime: new Date(cur.unfreeze_expire_time),
|
|
434
|
+
});
|
|
442
435
|
}
|
|
443
|
-
else if (cur
|
|
444
|
-
accum.
|
|
436
|
+
else if (cur) {
|
|
437
|
+
accum.bandwidth.push({
|
|
438
|
+
amount: new bignumber_js_1.BigNumber(cur.unfreeze_amount),
|
|
439
|
+
expireTime: new Date(cur.unfreeze_expire_time),
|
|
440
|
+
});
|
|
445
441
|
}
|
|
446
442
|
return accum;
|
|
447
|
-
}, {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
// TODO: rely on the account object when trongrid will provide this info.
|
|
515
|
-
const getLastVotedDate = (txs) => {
|
|
516
|
-
const lastOp = txs.find(({ type }) => type === "VoteWitnessContract");
|
|
517
|
-
return lastOp ? lastOp.date : null;
|
|
518
|
-
};
|
|
519
|
-
const lastVotedDate = txs ? getLastVotedDate(txs) : undefined;
|
|
520
|
-
return {
|
|
521
|
-
energy,
|
|
522
|
-
bandwidth,
|
|
523
|
-
frozen,
|
|
524
|
-
unFrozen,
|
|
525
|
-
delegatedFrozen,
|
|
526
|
-
legacyFrozen,
|
|
527
|
-
votes,
|
|
528
|
-
tronPower,
|
|
529
|
-
unwithdrawnReward,
|
|
530
|
-
lastWithdrawnRewardDate,
|
|
531
|
-
lastVotedDate,
|
|
532
|
-
cacheTransactionInfoById,
|
|
533
|
-
};
|
|
534
|
-
});
|
|
443
|
+
}, { bandwidth: [], energy: [] })
|
|
444
|
+
: { bandwidth: [], energy: [] };
|
|
445
|
+
const encodedAddress = (0, format_1.encode58Check)(acc.address);
|
|
446
|
+
const tronNetworkInfo = await (0, exports.getTronAccountNetwork)(encodedAddress);
|
|
447
|
+
const unwithdrawnReward = await (0, exports.getUnwithdrawnReward)(encodedAddress);
|
|
448
|
+
const energy = tronNetworkInfo.energyLimit.minus(tronNetworkInfo.energyUsed);
|
|
449
|
+
const bandwidth = (0, utils_1.extractBandwidthInfo)(tronNetworkInfo);
|
|
450
|
+
const frozen = {
|
|
451
|
+
bandwidth: frozenBandwidth.isGreaterThan(0)
|
|
452
|
+
? {
|
|
453
|
+
amount: frozenBandwidth,
|
|
454
|
+
}
|
|
455
|
+
: undefined,
|
|
456
|
+
energy: frozenEnergy.isGreaterThan(0)
|
|
457
|
+
? {
|
|
458
|
+
amount: frozenEnergy,
|
|
459
|
+
}
|
|
460
|
+
: undefined,
|
|
461
|
+
};
|
|
462
|
+
const delegatedFrozen = {
|
|
463
|
+
bandwidth: delegatedFrozenBandwidth
|
|
464
|
+
? {
|
|
465
|
+
amount: new bignumber_js_1.BigNumber(delegatedFrozenBandwidth),
|
|
466
|
+
}
|
|
467
|
+
: undefined,
|
|
468
|
+
energy: delegatedFrozenEnergy
|
|
469
|
+
? {
|
|
470
|
+
amount: new bignumber_js_1.BigNumber(delegatedFrozenEnergy),
|
|
471
|
+
}
|
|
472
|
+
: undefined,
|
|
473
|
+
};
|
|
474
|
+
const tronPower = new bignumber_js_1.BigNumber((0, get_1.default)(frozen, "bandwidth.amount", 0))
|
|
475
|
+
.plus((0, get_1.default)(frozen, "energy.amount", 0))
|
|
476
|
+
.plus((0, get_1.default)(delegatedFrozen, "bandwidth.amount", 0))
|
|
477
|
+
.plus((0, get_1.default)(delegatedFrozen, "energy.amount", 0))
|
|
478
|
+
.plus((0, get_1.default)(legacyFrozen, "energy.amount", 0))
|
|
479
|
+
.plus((0, get_1.default)(legacyFrozen, "bandwidth.amount", 0))
|
|
480
|
+
.dividedBy(1000000)
|
|
481
|
+
.integerValue(bignumber_js_1.BigNumber.ROUND_FLOOR)
|
|
482
|
+
.toNumber();
|
|
483
|
+
const votes = (0, get_1.default)(acc, "votes", []).map((v) => ({
|
|
484
|
+
address: v.vote_address,
|
|
485
|
+
voteCount: v.vote_count,
|
|
486
|
+
}));
|
|
487
|
+
const lastWithdrawnRewardDate = acc.latest_withdraw_time
|
|
488
|
+
? new Date(acc.latest_withdraw_time)
|
|
489
|
+
: undefined;
|
|
490
|
+
// TODO: rely on the account object when trongrid will provide this info.
|
|
491
|
+
const getLastVotedDate = (txs) => {
|
|
492
|
+
const lastOp = txs.find(({ type }) => type === "VoteWitnessContract");
|
|
493
|
+
return lastOp ? lastOp.date : null;
|
|
494
|
+
};
|
|
495
|
+
const lastVotedDate = txs ? getLastVotedDate(txs) : undefined;
|
|
496
|
+
return {
|
|
497
|
+
energy,
|
|
498
|
+
bandwidth,
|
|
499
|
+
frozen,
|
|
500
|
+
unFrozen,
|
|
501
|
+
delegatedFrozen,
|
|
502
|
+
legacyFrozen,
|
|
503
|
+
votes,
|
|
504
|
+
tronPower,
|
|
505
|
+
unwithdrawnReward,
|
|
506
|
+
lastWithdrawnRewardDate,
|
|
507
|
+
lastVotedDate,
|
|
508
|
+
cacheTransactionInfoById,
|
|
509
|
+
};
|
|
535
510
|
}
|
|
536
|
-
const getUnwithdrawnReward = (addr) =>
|
|
511
|
+
const getUnwithdrawnReward = async (addr) => {
|
|
537
512
|
try {
|
|
538
|
-
const { reward = 0 } =
|
|
513
|
+
const { reward = 0 } = await fetch(`/wallet/getReward?address=${encodeURIComponent((0, format_1.decode58Check)(addr))}`);
|
|
539
514
|
return new bignumber_js_1.BigNumber(reward);
|
|
540
515
|
}
|
|
541
516
|
catch (e) {
|
|
542
517
|
return Promise.resolve(new bignumber_js_1.BigNumber(0));
|
|
543
518
|
}
|
|
544
|
-
}
|
|
519
|
+
};
|
|
545
520
|
exports.getUnwithdrawnReward = getUnwithdrawnReward;
|
|
546
|
-
const claimRewardTronTransaction = (account) =>
|
|
521
|
+
const claimRewardTronTransaction = async (account) => {
|
|
547
522
|
const url = `/wallet/withdrawbalance`;
|
|
548
523
|
const data = {
|
|
549
524
|
owner_address: (0, format_1.decode58Check)(account.freshAddress),
|
|
550
525
|
};
|
|
551
|
-
const result =
|
|
526
|
+
const result = await post(url, data);
|
|
552
527
|
return result;
|
|
553
|
-
}
|
|
528
|
+
};
|
|
554
529
|
exports.claimRewardTronTransaction = claimRewardTronTransaction;
|
|
555
530
|
//# sourceMappingURL=index.js.map
|