@getomnichain/omnichain 0.5.1 → 0.6.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/CHANGELOG.md +123 -0
- package/README.md +5 -3
- package/dist/cjs/address.factory.js +7 -4
- package/dist/cjs/address.factory.js.map +1 -1
- package/dist/cjs/asset_balance.js +7 -0
- package/dist/cjs/asset_balance.js.map +1 -0
- package/dist/cjs/asset_map.js +45 -0
- package/dist/cjs/asset_map.js.map +1 -0
- package/dist/cjs/asset_registry.js +21 -0
- package/dist/cjs/asset_registry.js.map +1 -0
- package/dist/cjs/bip39.js +88 -0
- package/dist/cjs/bip39.js.map +1 -0
- package/dist/cjs/bytes_from_hex.js +34 -0
- package/dist/cjs/bytes_from_hex.js.map +1 -0
- package/dist/cjs/chain_type.js +35 -0
- package/dist/cjs/chain_type.js.map +1 -0
- package/dist/cjs/evm/evm_chain.js +16 -0
- package/dist/cjs/evm/evm_chain.js.map +1 -1
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/network_type.js +5 -2
- package/dist/cjs/network_type.js.map +1 -1
- package/dist/cjs/python_builtins.js +225 -0
- package/dist/cjs/python_builtins.js.map +1 -0
- package/dist/cjs/python_json.js +120 -0
- package/dist/cjs/python_json.js.map +1 -0
- package/dist/cjs/python_pydantic.js +50 -0
- package/dist/cjs/python_pydantic.js.map +1 -0
- package/dist/cjs/python_repr.js +172 -0
- package/dist/cjs/python_repr.js.map +1 -0
- package/dist/cjs/signed_transaction.js +24 -0
- package/dist/cjs/signed_transaction.js.map +1 -0
- package/dist/cjs/stellar/index.js +26 -0
- package/dist/cjs/stellar/index.js.map +1 -0
- package/dist/cjs/stellar/stellar_address.js +25 -0
- package/dist/cjs/stellar/stellar_address.js.map +1 -0
- package/dist/cjs/stellar/stellar_asset.js +155 -0
- package/dist/cjs/stellar/stellar_asset.js.map +1 -0
- package/dist/cjs/stellar/stellar_assets.js +26 -0
- package/dist/cjs/stellar/stellar_assets.js.map +1 -0
- package/dist/cjs/stellar/stellar_chain.js +1334 -0
- package/dist/cjs/stellar/stellar_chain.js.map +1 -0
- package/dist/cjs/stellar/stellar_chains.js +28 -0
- package/dist/cjs/stellar/stellar_chains.js.map +1 -0
- package/dist/cjs/stellar/stellar_gas_pricing.js +22 -0
- package/dist/cjs/stellar/stellar_gas_pricing.js.map +1 -0
- package/dist/cjs/stellar/stellar_strkey.js +71 -0
- package/dist/cjs/stellar/stellar_strkey.js.map +1 -0
- package/dist/cjs/stellar/stellar_transaction_status.js +72 -0
- package/dist/cjs/stellar/stellar_transaction_status.js.map +1 -0
- package/dist/cjs/stellar/stellar_transactions.js +475 -0
- package/dist/cjs/stellar/stellar_transactions.js.map +1 -0
- package/dist/cjs/stellar/stellar_wallet.js +195 -0
- package/dist/cjs/stellar/stellar_wallet.js.map +1 -0
- package/dist/cjs/token.js +3 -1
- package/dist/cjs/token.js.map +1 -1
- package/dist/cjs/transaction_json.js +85 -0
- package/dist/cjs/transaction_json.js.map +1 -0
- package/dist/cjs/transaction_prerequisite.js +19 -0
- package/dist/cjs/transaction_prerequisite.js.map +1 -0
- package/dist/cjs/transaction_simulation.js +21 -0
- package/dist/cjs/transaction_simulation.js.map +1 -0
- package/dist/cjs/tron/index.js +32 -0
- package/dist/cjs/tron/index.js.map +1 -0
- package/dist/cjs/tron/tron_abi.js +287 -0
- package/dist/cjs/tron/tron_abi.js.map +1 -0
- package/dist/cjs/tron/tron_address.js +38 -0
- package/dist/cjs/tron/tron_address.js.map +1 -0
- package/dist/cjs/tron/tron_asset.js +56 -0
- package/dist/cjs/tron/tron_asset.js.map +1 -0
- package/dist/cjs/tron/tron_assets.js +17 -0
- package/dist/cjs/tron/tron_assets.js.map +1 -0
- package/dist/cjs/tron/tron_base58.js +95 -0
- package/dist/cjs/tron/tron_base58.js.map +1 -0
- package/dist/cjs/tron/tron_canonical_transaction.js +268 -0
- package/dist/cjs/tron/tron_canonical_transaction.js.map +1 -0
- package/dist/cjs/tron/tron_chain.js +809 -0
- package/dist/cjs/tron/tron_chain.js.map +1 -0
- package/dist/cjs/tron/tron_chains.js +19 -0
- package/dist/cjs/tron/tron_chains.js.map +1 -0
- package/dist/cjs/tron/tron_client.js +327 -0
- package/dist/cjs/tron/tron_client.js.map +1 -0
- package/dist/cjs/tron/tron_contract.js +195 -0
- package/dist/cjs/tron/tron_contract.js.map +1 -0
- package/dist/cjs/tron/tron_gas_pricing.js +21 -0
- package/dist/cjs/tron/tron_gas_pricing.js.map +1 -0
- package/dist/cjs/tron/tron_keys.js +251 -0
- package/dist/cjs/tron/tron_keys.js.map +1 -0
- package/dist/cjs/tron/tron_transaction_builder.js +196 -0
- package/dist/cjs/tron/tron_transaction_builder.js.map +1 -0
- package/dist/cjs/tron/tron_transaction_status.js +118 -0
- package/dist/cjs/tron/tron_transaction_status.js.map +1 -0
- package/dist/cjs/tron/tron_transactions.js +192 -0
- package/dist/cjs/tron/tron_transactions.js.map +1 -0
- package/dist/cjs/tron/tron_wallet.js +152 -0
- package/dist/cjs/tron/tron_wallet.js.map +1 -0
- package/dist/cjs/unsigned_transaction.js +12 -0
- package/dist/cjs/unsigned_transaction.js.map +1 -1
- package/dist/cjs/wallet.base.js +29 -0
- package/dist/cjs/wallet.base.js.map +1 -0
- package/dist/esm/address.factory.d.ts.map +1 -1
- package/dist/esm/address.factory.js +7 -4
- package/dist/esm/address.factory.js.map +1 -1
- package/dist/esm/asset_balance.d.ts +5 -0
- package/dist/esm/asset_balance.d.ts.map +1 -0
- package/dist/esm/asset_balance.js +3 -0
- package/dist/esm/asset_balance.js.map +1 -0
- package/dist/esm/asset_map.d.ts +12 -0
- package/dist/esm/asset_map.d.ts.map +1 -0
- package/dist/esm/asset_map.js +40 -0
- package/dist/esm/asset_map.js.map +1 -0
- package/dist/esm/asset_registry.d.ts +6 -0
- package/dist/esm/asset_registry.d.ts.map +1 -0
- package/dist/esm/asset_registry.js +15 -0
- package/dist/esm/asset_registry.js.map +1 -0
- package/dist/esm/bip39.d.ts +4 -0
- package/dist/esm/bip39.d.ts.map +1 -0
- package/dist/esm/bip39.js +83 -0
- package/dist/esm/bip39.js.map +1 -0
- package/dist/esm/bytes_from_hex.d.ts +2 -0
- package/dist/esm/bytes_from_hex.d.ts.map +1 -0
- package/dist/esm/bytes_from_hex.js +31 -0
- package/dist/esm/bytes_from_hex.js.map +1 -0
- package/dist/esm/chain_type.d.ts +29 -0
- package/dist/esm/chain_type.d.ts.map +1 -0
- package/dist/esm/chain_type.js +32 -0
- package/dist/esm/chain_type.js.map +1 -0
- package/dist/esm/evm/evm_chain.d.ts +1 -0
- package/dist/esm/evm/evm_chain.d.ts.map +1 -1
- package/dist/esm/evm/evm_chain.js +17 -1
- package/dist/esm/evm/evm_chain.js.map +1 -1
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/network_type.d.ts +3 -2
- package/dist/esm/network_type.d.ts.map +1 -1
- package/dist/esm/network_type.js +6 -3
- package/dist/esm/network_type.js.map +1 -1
- package/dist/esm/python_builtins.d.ts +13 -0
- package/dist/esm/python_builtins.d.ts.map +1 -0
- package/dist/esm/python_builtins.js +212 -0
- package/dist/esm/python_builtins.js.map +1 -0
- package/dist/esm/python_json.d.ts +9 -0
- package/dist/esm/python_json.d.ts.map +1 -0
- package/dist/esm/python_json.js +117 -0
- package/dist/esm/python_json.js.map +1 -0
- package/dist/esm/python_pydantic.d.ts +11 -0
- package/dist/esm/python_pydantic.d.ts.map +1 -0
- package/dist/esm/python_pydantic.js +39 -0
- package/dist/esm/python_pydantic.js.map +1 -0
- package/dist/esm/python_repr.d.ts +17 -0
- package/dist/esm/python_repr.d.ts.map +1 -0
- package/dist/esm/python_repr.js +160 -0
- package/dist/esm/python_repr.js.map +1 -0
- package/dist/esm/signed_transaction.d.ts +17 -0
- package/dist/esm/signed_transaction.d.ts.map +1 -0
- package/dist/esm/signed_transaction.js +19 -0
- package/dist/esm/signed_transaction.js.map +1 -0
- package/dist/esm/stellar/index.d.ts +10 -0
- package/dist/esm/stellar/index.d.ts.map +1 -0
- package/dist/esm/stellar/index.js +10 -0
- package/dist/esm/stellar/index.js.map +1 -0
- package/dist/esm/stellar/stellar_address.d.ts +8 -0
- package/dist/esm/stellar/stellar_address.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_address.js +21 -0
- package/dist/esm/stellar/stellar_address.js.map +1 -0
- package/dist/esm/stellar/stellar_asset.d.ts +52 -0
- package/dist/esm/stellar/stellar_asset.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_asset.js +147 -0
- package/dist/esm/stellar/stellar_asset.js.map +1 -0
- package/dist/esm/stellar/stellar_assets.d.ts +11 -0
- package/dist/esm/stellar/stellar_assets.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_assets.js +23 -0
- package/dist/esm/stellar/stellar_assets.js.map +1 -0
- package/dist/esm/stellar/stellar_chain.d.ts +173 -0
- package/dist/esm/stellar/stellar_chain.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_chain.js +1325 -0
- package/dist/esm/stellar/stellar_chain.js.map +1 -0
- package/dist/esm/stellar/stellar_chains.d.ts +5 -0
- package/dist/esm/stellar/stellar_chains.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_chains.js +25 -0
- package/dist/esm/stellar/stellar_chains.js.map +1 -0
- package/dist/esm/stellar/stellar_gas_pricing.d.ts +13 -0
- package/dist/esm/stellar/stellar_gas_pricing.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_gas_pricing.js +18 -0
- package/dist/esm/stellar/stellar_gas_pricing.js.map +1 -0
- package/dist/esm/stellar/stellar_strkey.d.ts +3 -0
- package/dist/esm/stellar/stellar_strkey.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_strkey.js +67 -0
- package/dist/esm/stellar/stellar_strkey.js.map +1 -0
- package/dist/esm/stellar/stellar_transaction_status.d.ts +39 -0
- package/dist/esm/stellar/stellar_transaction_status.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_transaction_status.js +68 -0
- package/dist/esm/stellar/stellar_transaction_status.js.map +1 -0
- package/dist/esm/stellar/stellar_transactions.d.ts +166 -0
- package/dist/esm/stellar/stellar_transactions.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_transactions.js +451 -0
- package/dist/esm/stellar/stellar_transactions.js.map +1 -0
- package/dist/esm/stellar/stellar_wallet.d.ts +43 -0
- package/dist/esm/stellar/stellar_wallet.d.ts.map +1 -0
- package/dist/esm/stellar/stellar_wallet.js +190 -0
- package/dist/esm/stellar/stellar_wallet.js.map +1 -0
- package/dist/esm/token.d.ts +1 -0
- package/dist/esm/token.d.ts.map +1 -1
- package/dist/esm/token.js +3 -1
- package/dist/esm/token.js.map +1 -1
- package/dist/esm/transaction_json.d.ts +21 -0
- package/dist/esm/transaction_json.d.ts.map +1 -0
- package/dist/esm/transaction_json.js +75 -0
- package/dist/esm/transaction_json.js.map +1 -0
- package/dist/esm/transaction_prerequisite.d.ts +17 -0
- package/dist/esm/transaction_prerequisite.d.ts.map +1 -0
- package/dist/esm/transaction_prerequisite.js +13 -0
- package/dist/esm/transaction_prerequisite.js.map +1 -0
- package/dist/esm/transaction_simulation.d.ts +20 -0
- package/dist/esm/transaction_simulation.d.ts.map +1 -0
- package/dist/esm/transaction_simulation.js +17 -0
- package/dist/esm/transaction_simulation.js.map +1 -0
- package/dist/esm/tron/index.d.ts +16 -0
- package/dist/esm/tron/index.d.ts.map +1 -0
- package/dist/esm/tron/index.js +16 -0
- package/dist/esm/tron/index.js.map +1 -0
- package/dist/esm/tron/tron_abi.d.ts +3 -0
- package/dist/esm/tron/tron_abi.d.ts.map +1 -0
- package/dist/esm/tron/tron_abi.js +283 -0
- package/dist/esm/tron/tron_abi.js.map +1 -0
- package/dist/esm/tron/tron_address.d.ts +10 -0
- package/dist/esm/tron/tron_address.d.ts.map +1 -0
- package/dist/esm/tron/tron_address.js +34 -0
- package/dist/esm/tron/tron_address.js.map +1 -0
- package/dist/esm/tron/tron_asset.d.ts +19 -0
- package/dist/esm/tron/tron_asset.d.ts.map +1 -0
- package/dist/esm/tron/tron_asset.js +51 -0
- package/dist/esm/tron/tron_asset.js.map +1 -0
- package/dist/esm/tron/tron_assets.d.ts +10 -0
- package/dist/esm/tron/tron_assets.d.ts.map +1 -0
- package/dist/esm/tron/tron_assets.js +14 -0
- package/dist/esm/tron/tron_assets.js.map +1 -0
- package/dist/esm/tron/tron_base58.d.ts +7 -0
- package/dist/esm/tron/tron_base58.d.ts.map +1 -0
- package/dist/esm/tron/tron_base58.js +84 -0
- package/dist/esm/tron/tron_base58.js.map +1 -0
- package/dist/esm/tron/tron_canonical_transaction.d.ts +164 -0
- package/dist/esm/tron/tron_canonical_transaction.d.ts.map +1 -0
- package/dist/esm/tron/tron_canonical_transaction.js +262 -0
- package/dist/esm/tron/tron_canonical_transaction.js.map +1 -0
- package/dist/esm/tron/tron_chain.d.ts +136 -0
- package/dist/esm/tron/tron_chain.d.ts.map +1 -0
- package/dist/esm/tron/tron_chain.js +801 -0
- package/dist/esm/tron/tron_chain.js.map +1 -0
- package/dist/esm/tron/tron_chains.d.ts +5 -0
- package/dist/esm/tron/tron_chains.d.ts.map +1 -0
- package/dist/esm/tron/tron_chains.js +16 -0
- package/dist/esm/tron/tron_chains.js.map +1 -0
- package/dist/esm/tron/tron_client.d.ts +56 -0
- package/dist/esm/tron/tron_client.d.ts.map +1 -0
- package/dist/esm/tron/tron_client.js +319 -0
- package/dist/esm/tron/tron_client.js.map +1 -0
- package/dist/esm/tron/tron_contract.d.ts +69 -0
- package/dist/esm/tron/tron_contract.d.ts.map +1 -0
- package/dist/esm/tron/tron_contract.js +190 -0
- package/dist/esm/tron/tron_contract.js.map +1 -0
- package/dist/esm/tron/tron_gas_pricing.d.ts +12 -0
- package/dist/esm/tron/tron_gas_pricing.d.ts.map +1 -0
- package/dist/esm/tron/tron_gas_pricing.js +17 -0
- package/dist/esm/tron/tron_gas_pricing.js.map +1 -0
- package/dist/esm/tron/tron_keys.d.ts +61 -0
- package/dist/esm/tron/tron_keys.d.ts.map +1 -0
- package/dist/esm/tron/tron_keys.js +228 -0
- package/dist/esm/tron/tron_keys.js.map +1 -0
- package/dist/esm/tron/tron_transaction_builder.d.ts +56 -0
- package/dist/esm/tron/tron_transaction_builder.d.ts.map +1 -0
- package/dist/esm/tron/tron_transaction_builder.js +188 -0
- package/dist/esm/tron/tron_transaction_builder.js.map +1 -0
- package/dist/esm/tron/tron_transaction_status.d.ts +54 -0
- package/dist/esm/tron/tron_transaction_status.d.ts.map +1 -0
- package/dist/esm/tron/tron_transaction_status.js +113 -0
- package/dist/esm/tron/tron_transaction_status.js.map +1 -0
- package/dist/esm/tron/tron_transactions.d.ts +96 -0
- package/dist/esm/tron/tron_transactions.d.ts.map +1 -0
- package/dist/esm/tron/tron_transactions.js +181 -0
- package/dist/esm/tron/tron_transactions.js.map +1 -0
- package/dist/esm/tron/tron_wallet.d.ts +43 -0
- package/dist/esm/tron/tron_wallet.d.ts.map +1 -0
- package/dist/esm/tron/tron_wallet.js +148 -0
- package/dist/esm/tron/tron_wallet.js.map +1 -0
- package/dist/esm/unsigned_transaction.d.ts +5 -0
- package/dist/esm/unsigned_transaction.d.ts.map +1 -1
- package/dist/esm/unsigned_transaction.js +12 -0
- package/dist/esm/unsigned_transaction.js.map +1 -1
- package/dist/esm/wallet.base.d.ts +32 -0
- package/dist/esm/wallet.base.d.ts.map +1 -0
- package/dist/esm/wallet.base.js +23 -0
- package/dist/esm/wallet.base.js.map +1 -0
- package/docs/CONNECTIONS.md +1 -0
- package/docs/README.md +16 -7
- package/docs/stellar.md +113 -0
- package/docs/tron.md +103 -0
- package/package.json +14 -2
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pyTruthy = exports.TronChain = exports.TronSignedMessage = exports.TronAddressUtils = exports.ZERO_RESET_APPROVAL_TRC20_ADDRESSES = exports.DEFAULT_TRC20_APPROVE_FEE_LIMIT_SUN = exports.DEFAULT_TRC20_TRANSFER_FEE_LIMIT_SUN = exports.DEFAULT_TRX_FEE_LIMIT_SUN = exports.TRC20_TRANSFER_TOPIC = exports.TRC20_ABI = void 0;
|
|
4
|
+
exports.zeroResetApprovalKey = zeroResetApprovalKey;
|
|
5
|
+
exports.tronBroadcastErrorKind = tronBroadcastErrorKind;
|
|
6
|
+
const decimal_js_1 = require("decimal.js");
|
|
7
|
+
const abstract_gas_pricing_ts_1 = require("../abstract_gas_pricing.js");
|
|
8
|
+
const chain_base_ts_1 = require("../chain.base.js");
|
|
9
|
+
const chain_ids_ts_1 = require("../chain_ids.js");
|
|
10
|
+
const chain_type_ts_1 = require("../chain_type.js");
|
|
11
|
+
const errors_ts_1 = require("../errors.js");
|
|
12
|
+
const python_builtins_ts_1 = require("../python_builtins.js");
|
|
13
|
+
Object.defineProperty(exports, "pyTruthy", { enumerable: true, get: function () { return python_builtins_ts_1.pyTruthy; } });
|
|
14
|
+
const python_repr_ts_1 = require("../python_repr.js");
|
|
15
|
+
const network_type_ts_1 = require("../network_type.js");
|
|
16
|
+
const priority_ts_1 = require("../priority.js");
|
|
17
|
+
const transaction_json_ts_1 = require("../transaction_json.js");
|
|
18
|
+
const transaction_prerequisite_ts_1 = require("../transaction_prerequisite.js");
|
|
19
|
+
const transaction_simulation_ts_1 = require("../transaction_simulation.js");
|
|
20
|
+
const transaction_status_ts_1 = require("../transaction_status.js");
|
|
21
|
+
const wallet_base_ts_1 = require("../wallet.base.js");
|
|
22
|
+
const tron_address_ts_1 = require("./tron_address.js");
|
|
23
|
+
const tron_asset_ts_1 = require("./tron_asset.js");
|
|
24
|
+
const tron_client_ts_1 = require("./tron_client.js");
|
|
25
|
+
const tron_contract_ts_1 = require("./tron_contract.js");
|
|
26
|
+
const tron_gas_pricing_ts_1 = require("./tron_gas_pricing.js");
|
|
27
|
+
const tron_keys_ts_1 = require("./tron_keys.js");
|
|
28
|
+
const tron_transaction_builder_ts_1 = require("./tron_transaction_builder.js");
|
|
29
|
+
const tron_transaction_status_ts_1 = require("./tron_transaction_status.js");
|
|
30
|
+
const tron_transactions_ts_1 = require("./tron_transactions.js");
|
|
31
|
+
exports.TRC20_ABI = [
|
|
32
|
+
{
|
|
33
|
+
constant: true,
|
|
34
|
+
inputs: [],
|
|
35
|
+
name: 'decimals',
|
|
36
|
+
outputs: [{ name: '', type: 'uint8' }],
|
|
37
|
+
stateMutability: 'view',
|
|
38
|
+
type: 'function',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
constant: true,
|
|
42
|
+
inputs: [],
|
|
43
|
+
name: 'symbol',
|
|
44
|
+
outputs: [{ name: '', type: 'string' }],
|
|
45
|
+
stateMutability: 'view',
|
|
46
|
+
type: 'function',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
constant: true,
|
|
50
|
+
inputs: [{ name: '_owner', type: 'address' }],
|
|
51
|
+
name: 'balanceOf',
|
|
52
|
+
outputs: [{ name: 'balance', type: 'uint256' }],
|
|
53
|
+
stateMutability: 'view',
|
|
54
|
+
type: 'function',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
constant: false,
|
|
58
|
+
inputs: [
|
|
59
|
+
{ name: '_to', type: 'address' },
|
|
60
|
+
{ name: '_value', type: 'uint256' },
|
|
61
|
+
],
|
|
62
|
+
name: 'transfer',
|
|
63
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
64
|
+
stateMutability: 'nonpayable',
|
|
65
|
+
type: 'function',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
constant: false,
|
|
69
|
+
inputs: [
|
|
70
|
+
{ name: '_spender', type: 'address' },
|
|
71
|
+
{ name: '_value', type: 'uint256' },
|
|
72
|
+
],
|
|
73
|
+
name: 'approve',
|
|
74
|
+
outputs: [{ name: '', type: 'bool' }],
|
|
75
|
+
stateMutability: 'nonpayable',
|
|
76
|
+
type: 'function',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
constant: true,
|
|
80
|
+
inputs: [
|
|
81
|
+
{ name: '_owner', type: 'address' },
|
|
82
|
+
{ name: '_spender', type: 'address' },
|
|
83
|
+
],
|
|
84
|
+
name: 'allowance',
|
|
85
|
+
outputs: [{ name: '', type: 'uint256' }],
|
|
86
|
+
stateMutability: 'view',
|
|
87
|
+
type: 'function',
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
exports.TRC20_TRANSFER_TOPIC = 'ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
91
|
+
exports.DEFAULT_TRX_FEE_LIMIT_SUN = 300_000;
|
|
92
|
+
exports.DEFAULT_TRC20_TRANSFER_FEE_LIMIT_SUN = 15_000_000;
|
|
93
|
+
exports.DEFAULT_TRC20_APPROVE_FEE_LIMIT_SUN = 25_000_000;
|
|
94
|
+
function zeroResetApprovalKey(chainId, contractAddress) {
|
|
95
|
+
return `${chainId}:${contractAddress}`;
|
|
96
|
+
}
|
|
97
|
+
exports.ZERO_RESET_APPROVAL_TRC20_ADDRESSES = new Set([
|
|
98
|
+
zeroResetApprovalKey(chain_ids_ts_1.CHAIN_ID_TRON_MAINNET, 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'),
|
|
99
|
+
]);
|
|
100
|
+
class TronAddressUtils {
|
|
101
|
+
static isHex(value) {
|
|
102
|
+
return (0, python_builtins_ts_1.isPyInt)(value, 16);
|
|
103
|
+
}
|
|
104
|
+
static hexToVisible(hexAddress) {
|
|
105
|
+
if (hexAddress.startsWith('T')) {
|
|
106
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidAddress, `Tron hex address must not start with "T", got ${hexAddress}`, { address: hexAddress });
|
|
107
|
+
}
|
|
108
|
+
if (!TronAddressUtils.isHex(hexAddress)) {
|
|
109
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidAddress, `Invalid hex address: ${hexAddress}`, { address: hexAddress });
|
|
110
|
+
}
|
|
111
|
+
if (!hexAddress.startsWith('41')) {
|
|
112
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidAddress, `Tron hex address must start with 41, got ${hexAddress}`, { address: hexAddress });
|
|
113
|
+
}
|
|
114
|
+
return (0, tron_keys_ts_1.toBase58CheckAddress)(hexAddress);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.TronAddressUtils = TronAddressUtils;
|
|
118
|
+
class TronSignedMessage extends wallet_base_ts_1.AbstractSignedMessage {
|
|
119
|
+
constructor(signature) {
|
|
120
|
+
super(signature);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.TronSignedMessage = TronSignedMessage;
|
|
124
|
+
class TronChain extends chain_base_ts_1.Chain {
|
|
125
|
+
chainAgnosticNamespace = null;
|
|
126
|
+
defaultRpcUrl;
|
|
127
|
+
rpcUrl;
|
|
128
|
+
#trongridApiKey;
|
|
129
|
+
_client = null;
|
|
130
|
+
_chainParameters = null;
|
|
131
|
+
_nativeAsset;
|
|
132
|
+
assetDecimalsByIdentifier = new Map();
|
|
133
|
+
constructor(init) {
|
|
134
|
+
super(init.chainId, init.name, network_type_ts_1.NetworkType.TRON, 3.0, 'TRX', init.explorerUrl);
|
|
135
|
+
this.defaultRpcUrl = init.defaultRpcUrl;
|
|
136
|
+
this.rpcUrl = init.rpcUrl ?? null;
|
|
137
|
+
this.#trongridApiKey = init.trongridApiKey ?? null;
|
|
138
|
+
this._nativeAsset = new tron_asset_ts_1.TronAsset(init.chainId, 'TRX', null, tron_asset_ts_1.TronAsset.NATIVE_DECIMALS);
|
|
139
|
+
}
|
|
140
|
+
get client() {
|
|
141
|
+
if (this._client === null) {
|
|
142
|
+
const env = readEnv();
|
|
143
|
+
if (this.#trongridApiKey === null && env?.TRONGRID_API_KEY !== undefined) {
|
|
144
|
+
this.#trongridApiKey = env.TRONGRID_API_KEY;
|
|
145
|
+
}
|
|
146
|
+
this.rpcUrl = this.rpcUrl || this._loadRpcUrl();
|
|
147
|
+
this._client = new tron_client_ts_1.TronClient({
|
|
148
|
+
endpointUri: this.rpcUrl,
|
|
149
|
+
apiKey: this.#trongridApiKey ?? undefined,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return this._client;
|
|
153
|
+
}
|
|
154
|
+
get trx() {
|
|
155
|
+
return new tron_transaction_builder_ts_1.TronTrx(this.client);
|
|
156
|
+
}
|
|
157
|
+
static rpcUrlEnvForChainId(chainId) {
|
|
158
|
+
return `TRON_${chainId}_RPC_URL`;
|
|
159
|
+
}
|
|
160
|
+
_loadRpcUrl() {
|
|
161
|
+
const env = readEnv();
|
|
162
|
+
const candidates = [`${this.name.replace(/ /g, '_').toUpperCase()}_RPC_URL`, TronChain.rpcUrlEnvForChainId(this.chainId)];
|
|
163
|
+
for (const name of candidates) {
|
|
164
|
+
const value = env?.[name];
|
|
165
|
+
if (value)
|
|
166
|
+
return value;
|
|
167
|
+
}
|
|
168
|
+
return this.defaultRpcUrl;
|
|
169
|
+
}
|
|
170
|
+
get chainType() {
|
|
171
|
+
return chain_type_ts_1.ChainType.TRON;
|
|
172
|
+
}
|
|
173
|
+
get nativeAsset() {
|
|
174
|
+
return this._nativeAsset;
|
|
175
|
+
}
|
|
176
|
+
get nativeToken() {
|
|
177
|
+
return this._nativeAsset;
|
|
178
|
+
}
|
|
179
|
+
toString() {
|
|
180
|
+
return `TronChain[chain_id:${this.chainId}]`;
|
|
181
|
+
}
|
|
182
|
+
getTrc20Asset(symbol, contractAddress, decimals) {
|
|
183
|
+
return new tron_asset_ts_1.TronAsset(this.chainId, symbol, contractAddress, decimals);
|
|
184
|
+
}
|
|
185
|
+
getAssetExplorerUrl(asset) {
|
|
186
|
+
if (!(asset instanceof tron_asset_ts_1.TronAsset)) {
|
|
187
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid asset ${String(asset)}, expected TronAsset`, { chainId: this.chainId });
|
|
188
|
+
}
|
|
189
|
+
if (asset.isNative())
|
|
190
|
+
return null;
|
|
191
|
+
return `${this.explorerBaseUrl}/#/token20/${asset.contractAddress}`;
|
|
192
|
+
}
|
|
193
|
+
getWalletAddressExplorerUrl(walletAddress) {
|
|
194
|
+
return `${this.explorerBaseUrl}/#/address/${walletAddress}`;
|
|
195
|
+
}
|
|
196
|
+
getTransactionExplorerUrl(txHash) {
|
|
197
|
+
return `${this.explorerBaseUrl}/#/transaction/${txHash}`;
|
|
198
|
+
}
|
|
199
|
+
getWalletExplorerUrl(address) {
|
|
200
|
+
return this.getWalletAddressExplorerUrl(address);
|
|
201
|
+
}
|
|
202
|
+
getTokenExplorerUrl(tokenIdentifier) {
|
|
203
|
+
if (!tokenIdentifier)
|
|
204
|
+
return this.explorerBaseUrl;
|
|
205
|
+
return `${this.explorerBaseUrl}/#/token20/${tokenIdentifier}`;
|
|
206
|
+
}
|
|
207
|
+
static formatAssetIdentifier(identifier) {
|
|
208
|
+
if (identifier === null || identifier === undefined)
|
|
209
|
+
return null;
|
|
210
|
+
return (0, tron_keys_ts_1.toBase58CheckAddress)(identifier);
|
|
211
|
+
}
|
|
212
|
+
static validateAssetIdentifier(identifier) {
|
|
213
|
+
if (identifier !== null && identifier !== undefined && !(0, tron_keys_ts_1.isBase58CheckAddress)(identifier)) {
|
|
214
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidTokenIdentifier, `Invalid Tron asset contract address ${identifier}`, { identifier });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
static formatWalletAddress(walletAddress) {
|
|
218
|
+
return (0, tron_keys_ts_1.toBase58CheckAddress)(walletAddress);
|
|
219
|
+
}
|
|
220
|
+
static validateWalletAddress(walletAddress) {
|
|
221
|
+
if (!(0, tron_keys_ts_1.isBase58CheckAddress)(walletAddress)) {
|
|
222
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidAddress, `Invalid Tron wallet address ${walletAddress}`, { address: walletAddress });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
validateAddress(raw) {
|
|
226
|
+
return typeof raw === 'string' && tron_address_ts_1.TronAddress.validatedBase58(raw) !== null;
|
|
227
|
+
}
|
|
228
|
+
validateTokenIdentifier(raw) {
|
|
229
|
+
if (raw === undefined)
|
|
230
|
+
return true;
|
|
231
|
+
try {
|
|
232
|
+
TronChain.validateAssetIdentifier(raw);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async resolveAsset(identifier) {
|
|
240
|
+
if (identifier === null || identifier === undefined)
|
|
241
|
+
return this._nativeAsset;
|
|
242
|
+
const contract = await this.getTrc20Contract(identifier);
|
|
243
|
+
const decimals = Number(await contract.callView('decimals'));
|
|
244
|
+
const symbol = String(await contract.callView('symbol'));
|
|
245
|
+
return new tron_asset_ts_1.TronAsset(this.chainId, symbol, identifier, decimals);
|
|
246
|
+
}
|
|
247
|
+
createAsset(symbol, identifier, decimals) {
|
|
248
|
+
if (identifier === null || identifier === undefined) {
|
|
249
|
+
if (symbol !== 'TRX') {
|
|
250
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid symbol ${symbol} for native TRX, expected TRX`, { chainId: this.chainId });
|
|
251
|
+
}
|
|
252
|
+
if (decimals !== tron_asset_ts_1.TronAsset.NATIVE_DECIMALS) {
|
|
253
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid decimals ${decimals} for native TRX, expected ${tron_asset_ts_1.TronAsset.NATIVE_DECIMALS}`, { chainId: this.chainId });
|
|
254
|
+
}
|
|
255
|
+
return this._nativeAsset;
|
|
256
|
+
}
|
|
257
|
+
return new tron_asset_ts_1.TronAsset(this.chainId, symbol, identifier, decimals);
|
|
258
|
+
}
|
|
259
|
+
async getTrc20Contract(contractAddress) {
|
|
260
|
+
const address = (0, tron_keys_ts_1.toBase58CheckAddress)(contractAddress);
|
|
261
|
+
const info = await this.client.getContract(address);
|
|
262
|
+
const contract = tron_contract_ts_1.TronContract.fromContractInfo(address, info, this.client);
|
|
263
|
+
contract.abi = exports.TRC20_ABI;
|
|
264
|
+
return contract;
|
|
265
|
+
}
|
|
266
|
+
async getCachedAssetDecimals(symbol, identifier) {
|
|
267
|
+
if (identifier === null || identifier === undefined) {
|
|
268
|
+
if (symbol !== this._nativeAsset.symbol) {
|
|
269
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid native asset symbol ${symbol}`, { chainId: this.chainId });
|
|
270
|
+
}
|
|
271
|
+
return this._nativeAsset.decimals;
|
|
272
|
+
}
|
|
273
|
+
let decimals = this.assetDecimalsByIdentifier.get(identifier);
|
|
274
|
+
if (decimals === undefined) {
|
|
275
|
+
decimals = await this._getAssetDecimalsInternal(symbol, identifier);
|
|
276
|
+
this.assetDecimalsByIdentifier.set(identifier, decimals);
|
|
277
|
+
}
|
|
278
|
+
return decimals;
|
|
279
|
+
}
|
|
280
|
+
async _getAssetDecimalsInternal(symbol, identifier) {
|
|
281
|
+
if (identifier === null || identifier === undefined) {
|
|
282
|
+
if (symbol !== 'TRX') {
|
|
283
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid symbol ${symbol} for native TRX`, { chainId: this.chainId });
|
|
284
|
+
}
|
|
285
|
+
return tron_asset_ts_1.TronAsset.NATIVE_DECIMALS;
|
|
286
|
+
}
|
|
287
|
+
const contract = await this.getTrc20Contract(identifier);
|
|
288
|
+
return Number(await contract.callView('decimals'));
|
|
289
|
+
}
|
|
290
|
+
async _getTrc20SymbolInternal(address) {
|
|
291
|
+
const contract = await this.getTrc20Contract(address);
|
|
292
|
+
return String(await contract.callView('symbol'));
|
|
293
|
+
}
|
|
294
|
+
async getAssetBalance(asset, ownerAddress) {
|
|
295
|
+
this.assertOwnAsset(asset);
|
|
296
|
+
const owner = TronChain.formatWalletAddress(ownerAddress);
|
|
297
|
+
if (asset.isNative()) {
|
|
298
|
+
try {
|
|
299
|
+
return await this.client.getAccountBalance(owner);
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
if (err instanceof tron_client_ts_1.TronAddressNotFoundError)
|
|
303
|
+
return new decimal_js_1.Decimal(0);
|
|
304
|
+
throw err;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const contract = await this.getTrc20Contract(asset.contractAddress);
|
|
308
|
+
const balanceMr = await contract.callView('balanceOf', owner);
|
|
309
|
+
return new decimal_js_1.Decimal((0, transaction_status_ts_1.minorUnitsToHrString)(BigInt(balanceMr), asset.decimals));
|
|
310
|
+
}
|
|
311
|
+
async createTransferTransaction(req) {
|
|
312
|
+
this.assertOwnAsset(req.asset);
|
|
313
|
+
const sender = TronChain.formatWalletAddress(req.senderAddress);
|
|
314
|
+
const receiver = TronChain.formatWalletAddress(req.receiverAddress);
|
|
315
|
+
const feeLimitSun = this._resolveGasPricing(req.gasPricing === undefined ? priority_ts_1.FeePriority.NORMAL : req.gasPricing);
|
|
316
|
+
let amountMr = (0, transaction_status_ts_1.hrDecimalToMinorUnits)(new decimal_js_1.Decimal(req.amountHr.toString()), req.asset.decimals);
|
|
317
|
+
let builder;
|
|
318
|
+
if (req.asset.isNative()) {
|
|
319
|
+
if (req.isFullBalance === true) {
|
|
320
|
+
amountMr = amountMr - BigInt(exports.DEFAULT_TRX_FEE_LIMIT_SUN);
|
|
321
|
+
}
|
|
322
|
+
builder = this.trx.transfer(sender, receiver, amountMr);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
const contract = await this.getTrc20Contract(req.asset.contractAddress);
|
|
326
|
+
builder = (await contract.buildCall('transfer', receiver, amountMr)).withOwner(sender).feeLimit(feeLimitSun);
|
|
327
|
+
}
|
|
328
|
+
if (req.memo !== undefined && req.memo !== null) {
|
|
329
|
+
builder = builder.memo(req.memo);
|
|
330
|
+
}
|
|
331
|
+
const transaction = await builder.build();
|
|
332
|
+
return new transaction_prerequisite_ts_1.UnsignedTransactionWithPrerequisites({
|
|
333
|
+
transaction: new tron_transactions_ts_1.TronUnsignedTransaction({ chainId: this.chainId, transaction }),
|
|
334
|
+
prerequisites: [],
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
_resolveGasPricing(gasPricing) {
|
|
338
|
+
if ((0, abstract_gas_pricing_ts_1.isAbstractGasPricing)(gasPricing)) {
|
|
339
|
+
if (!(gasPricing instanceof tron_gas_pricing_ts_1.TronGasPricing)) {
|
|
340
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Expected TronGasPricing for a Tron chain, got ${gasPricing.constructor.name}`, { chainId: this.chainId });
|
|
341
|
+
}
|
|
342
|
+
return gasPricing.feeLimitSun;
|
|
343
|
+
}
|
|
344
|
+
if (!Object.values(priority_ts_1.FeePriority).includes(gasPricing)) {
|
|
345
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Unsupported gas_pricing ${(0, python_repr_ts_1.pyRepr)(gasPricing)}`, { chainId: this.chainId });
|
|
346
|
+
}
|
|
347
|
+
return exports.DEFAULT_TRC20_TRANSFER_FEE_LIMIT_SUN;
|
|
348
|
+
}
|
|
349
|
+
async _simulateTriggerSmartContract(ownerAddressB58, contractAddressB58, callDataHex) {
|
|
350
|
+
return this.client.makeRequest('wallet/triggerconstantcontract', {
|
|
351
|
+
owner_address: ownerAddressB58,
|
|
352
|
+
contract_address: contractAddressB58,
|
|
353
|
+
data: callDataHex,
|
|
354
|
+
visible: true,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
static _interpretTriggerConstantResponse(response) {
|
|
358
|
+
const resultObj = response.result;
|
|
359
|
+
let apiOk;
|
|
360
|
+
let apiCode = null;
|
|
361
|
+
let apiMessage = null;
|
|
362
|
+
if (resultObj !== null && typeof resultObj === 'object' && !Array.isArray(resultObj)) {
|
|
363
|
+
const result = resultObj;
|
|
364
|
+
apiOk = (0, python_builtins_ts_1.pyTruthy)(result.result ?? false);
|
|
365
|
+
apiCode = result.code ?? null;
|
|
366
|
+
apiMessage = result.message ?? null;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
apiOk = (0, python_builtins_ts_1.pyTruthy)(resultObj);
|
|
370
|
+
}
|
|
371
|
+
const energyUsedRaw = response.energy_used;
|
|
372
|
+
const energyUsed = typeof energyUsedRaw === 'number' ? Math.trunc(energyUsedRaw) : typeof energyUsedRaw === 'boolean' ? Number(energyUsedRaw) : null;
|
|
373
|
+
const ok = apiOk && apiCode === null && apiMessage === null;
|
|
374
|
+
let error = null;
|
|
375
|
+
if (!ok) {
|
|
376
|
+
let message = apiMessage;
|
|
377
|
+
if (typeof message === 'string' && /^[0-9a-fA-F]*$/.test(message) && message.length % 2 === 0) {
|
|
378
|
+
message = (0, python_builtins_ts_1.pyDecodeUtf8)(Buffer.from(message, 'hex'), 'replace');
|
|
379
|
+
}
|
|
380
|
+
error = new Error(`Tron constant call failed: code=${(0, python_repr_ts_1.pyRepr)(apiCode)} message=${(0, python_repr_ts_1.pyRepr)(message)}`);
|
|
381
|
+
}
|
|
382
|
+
return [ok, energyUsed, error];
|
|
383
|
+
}
|
|
384
|
+
async getChainParameters() {
|
|
385
|
+
if (this._chainParameters === null) {
|
|
386
|
+
this._chainParameters = (async () => {
|
|
387
|
+
const params = await this.client.getChainParameters();
|
|
388
|
+
const energyFee = params.filter((kv) => kv.key === 'getEnergyFee').map((kv) => kv.value);
|
|
389
|
+
if (energyFee.length === 0 || energyFee[0] === undefined || energyFee[0] === null) {
|
|
390
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.RpcError, 'Tron chain parameters are missing getEnergyFee', { chainId: this.chainId });
|
|
391
|
+
}
|
|
392
|
+
return { energyFee: Math.trunc(Number(energyFee[0])) };
|
|
393
|
+
})();
|
|
394
|
+
this._chainParameters.catch(() => {
|
|
395
|
+
this._chainParameters = null;
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
return this._chainParameters;
|
|
399
|
+
}
|
|
400
|
+
async supportsFullTransactionSimulation(unsignedTransaction) {
|
|
401
|
+
if (!(unsignedTransaction instanceof tron_transactions_ts_1.TronUnsignedTransaction)) {
|
|
402
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, 'Expected TronUnsignedTransaction', { chainId: this.chainId });
|
|
403
|
+
}
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
async simulateTransaction(req) {
|
|
407
|
+
const transaction = req.transaction;
|
|
408
|
+
if (!(transaction instanceof tron_transactions_ts_1.TronUnsignedTransaction)) {
|
|
409
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid transaction ${String(transaction)}, expected TronUnsignedTransaction`, { chainId: this.chainId });
|
|
410
|
+
}
|
|
411
|
+
const contracts = (0, python_builtins_ts_1.pyItem)(transaction.transaction.rawData, 'contract');
|
|
412
|
+
if (!(0, python_builtins_ts_1.pyTruthy)(contracts)) {
|
|
413
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Tron unsigned transaction ${transaction.txId} has no contract entries`, { chainId: this.chainId });
|
|
414
|
+
}
|
|
415
|
+
const entry = contracts[0];
|
|
416
|
+
if ((0, python_builtins_ts_1.pyItem)(entry, 'type') === 'TriggerSmartContract') {
|
|
417
|
+
const triggerValue = (0, python_builtins_ts_1.pyItem)((0, python_builtins_ts_1.pyItem)(entry, 'parameter'), 'value');
|
|
418
|
+
const rawData = String((0, python_builtins_ts_1.pyItem)(triggerValue, 'data') || '').toLowerCase();
|
|
419
|
+
const callDataHex = rawData.startsWith('0x') ? rawData.slice(2) : rawData;
|
|
420
|
+
let ownerB58;
|
|
421
|
+
let contractB58;
|
|
422
|
+
try {
|
|
423
|
+
ownerB58 = TronAddressUtils.hexToVisible((0, python_builtins_ts_1.pyItem)(triggerValue, 'owner_address'));
|
|
424
|
+
contractB58 = TronAddressUtils.hexToVisible((0, python_builtins_ts_1.pyItem)(triggerValue, 'contract_address'));
|
|
425
|
+
}
|
|
426
|
+
catch (err) {
|
|
427
|
+
return new tron_transactions_ts_1.TronTransactionSimulationResult({
|
|
428
|
+
chainId: this.chainId,
|
|
429
|
+
statusType: transaction_simulation_ts_1.TransactionSimulationStatusTypes.Failed,
|
|
430
|
+
balanceChanges: new Map(),
|
|
431
|
+
error: new Error(`Malformed TriggerSmartContract addresses in canonical tx: ${err.message}`),
|
|
432
|
+
energyUsed: null,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
let response;
|
|
436
|
+
try {
|
|
437
|
+
response = await this._simulateTriggerSmartContract(ownerB58, contractB58, callDataHex);
|
|
438
|
+
}
|
|
439
|
+
catch (err) {
|
|
440
|
+
return new tron_transactions_ts_1.TronTransactionSimulationResult({
|
|
441
|
+
chainId: this.chainId,
|
|
442
|
+
statusType: transaction_simulation_ts_1.TransactionSimulationStatusTypes.Failed,
|
|
443
|
+
balanceChanges: new Map(),
|
|
444
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
445
|
+
energyUsed: null,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
const [ok, energyUsed, error] = TronChain._interpretTriggerConstantResponse(response);
|
|
449
|
+
return new tron_transactions_ts_1.TronTransactionSimulationResult({
|
|
450
|
+
chainId: this.chainId,
|
|
451
|
+
statusType: ok ? transaction_simulation_ts_1.TransactionSimulationStatusTypes.Success : transaction_simulation_ts_1.TransactionSimulationStatusTypes.Failed,
|
|
452
|
+
balanceChanges: new Map(),
|
|
453
|
+
error,
|
|
454
|
+
energyUsed,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.FeatureNotSupported, `Tron does not expose a gas-reporting simulation primitive for contract type ${(0, python_repr_ts_1.pyRepr)(entry.type)}. Only TriggerSmartContract can be dry-run via wallet/triggerconstantcontract — every other contract type is a deterministic protocol operation with no VM execution and no energy usage to report.`, { chainId: this.chainId });
|
|
458
|
+
}
|
|
459
|
+
static _toBase58CheckAny(addressStr) {
|
|
460
|
+
if (!addressStr) {
|
|
461
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidAddress, 'empty address');
|
|
462
|
+
}
|
|
463
|
+
try {
|
|
464
|
+
return (0, tron_keys_ts_1.toBase58CheckAddress)(addressStr);
|
|
465
|
+
}
|
|
466
|
+
catch {
|
|
467
|
+
return (0, tron_keys_ts_1.toBase58CheckAddress)(`41${addressStr.startsWith('0x') ? addressStr.slice(2) : addressStr}`);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
static _parseTrc20TransferLog(log) {
|
|
471
|
+
const topics = log.topics || [];
|
|
472
|
+
if (topics.length === 0 || topics[0].toLowerCase() !== exports.TRC20_TRANSFER_TOPIC)
|
|
473
|
+
return null;
|
|
474
|
+
if (topics.length < 3)
|
|
475
|
+
return null;
|
|
476
|
+
let from;
|
|
477
|
+
let to;
|
|
478
|
+
try {
|
|
479
|
+
from = TronChain._toBase58CheckAny(topics[1].slice(-40));
|
|
480
|
+
to = TronChain._toBase58CheckAny(topics[2].slice(-40));
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
const dataHex = String(log.data || '').replace(/^[0x]+/, '');
|
|
486
|
+
if (!dataHex)
|
|
487
|
+
return null;
|
|
488
|
+
const value = (0, python_builtins_ts_1.pyInt)(dataHex, 16);
|
|
489
|
+
let contract;
|
|
490
|
+
try {
|
|
491
|
+
contract = TronChain._toBase58CheckAny(String(log.address || ''));
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
contract = null;
|
|
495
|
+
}
|
|
496
|
+
return { contract, from, to, value };
|
|
497
|
+
}
|
|
498
|
+
async _balanceChangesFromInfo(args) {
|
|
499
|
+
const balanceChanges = new Map();
|
|
500
|
+
const native = this._nativeAsset;
|
|
501
|
+
const add = (wallet, asset, change) => {
|
|
502
|
+
if (args.filteredWallets !== null && !args.filteredWallets.has(wallet))
|
|
503
|
+
return;
|
|
504
|
+
if (args.filteredAssets !== null && !args.filteredAssets.some((a) => a.strictEquals(asset)))
|
|
505
|
+
return;
|
|
506
|
+
transaction_status_ts_1.AssetBalanceChange.upsert(balanceChanges, wallet, asset, change);
|
|
507
|
+
};
|
|
508
|
+
const rawContracts = (args.txData.raw_data || {}).contract || [];
|
|
509
|
+
for (const c of rawContracts) {
|
|
510
|
+
if (c.type !== 'TransferContract')
|
|
511
|
+
continue;
|
|
512
|
+
const value = (c.parameter || {}).value || {};
|
|
513
|
+
let owner;
|
|
514
|
+
let to;
|
|
515
|
+
try {
|
|
516
|
+
owner = TronChain._toBase58CheckAny(String(value.owner_address ?? ''));
|
|
517
|
+
to = TronChain._toBase58CheckAny(String(value.to_address ?? ''));
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const amountMr = BigInt(String(value.amount ?? 0));
|
|
523
|
+
add(owner, native, transaction_status_ts_1.AssetBalanceChange.fromMr(-amountMr, native.decimals));
|
|
524
|
+
add(to, native, transaction_status_ts_1.AssetBalanceChange.fromMr(amountMr, native.decimals));
|
|
525
|
+
}
|
|
526
|
+
for (const internalTransaction of args.info.internal_transactions || []) {
|
|
527
|
+
const callValueInfo = internalTransaction.callValueInfo;
|
|
528
|
+
if (callValueInfo === undefined || callValueInfo === null)
|
|
529
|
+
continue;
|
|
530
|
+
if (callValueInfo.length === 0) {
|
|
531
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.TransactionDecodeFailed, 'Tron internal transaction has an empty callValueInfo list', { chainId: this.chainId });
|
|
532
|
+
}
|
|
533
|
+
if (callValueInfo[0].callValue === undefined || callValueInfo[0].callValue === null)
|
|
534
|
+
continue;
|
|
535
|
+
const callValue = BigInt(String(callValueInfo[0].callValue));
|
|
536
|
+
const senderAddress = TronChain._toBase58CheckAny(String(internalTransaction.caller_address));
|
|
537
|
+
const receiverAddress = TronChain._toBase58CheckAny(String(internalTransaction.transferTo_address));
|
|
538
|
+
add(senderAddress, native, transaction_status_ts_1.AssetBalanceChange.fromMr(-callValue, native.decimals));
|
|
539
|
+
add(receiverAddress, native, transaction_status_ts_1.AssetBalanceChange.fromMr(callValue, native.decimals));
|
|
540
|
+
}
|
|
541
|
+
for (const log of args.info.log || []) {
|
|
542
|
+
const parsed = TronChain._parseTrc20TransferLog(log);
|
|
543
|
+
if (parsed === null || parsed.contract === null)
|
|
544
|
+
continue;
|
|
545
|
+
const contractAddress = parsed.contract;
|
|
546
|
+
let asset = tron_asset_ts_1.TronAsset.searchRegisteredAsset(this.chainId, contractAddress);
|
|
547
|
+
if (asset === null) {
|
|
548
|
+
const symbol = await this._getTrc20SymbolInternal(contractAddress);
|
|
549
|
+
asset = tron_asset_ts_1.TronAsset.getRegisteredAsset(this.chainId, symbol, contractAddress);
|
|
550
|
+
if (asset === null) {
|
|
551
|
+
const decimals = await this._getAssetDecimalsInternal(symbol, contractAddress);
|
|
552
|
+
asset = this.getTrc20Asset(symbol, contractAddress, decimals);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
add(parsed.from, asset, transaction_status_ts_1.AssetBalanceChange.fromMr(-parsed.value, asset.decimals));
|
|
556
|
+
add(parsed.to, asset, transaction_status_ts_1.AssetBalanceChange.fromMr(parsed.value, asset.decimals));
|
|
557
|
+
}
|
|
558
|
+
if (args.feeInSun > 0 && rawContracts.length > 0) {
|
|
559
|
+
const payerHex = ((rawContracts[0].parameter || {}).value || {}).owner_address;
|
|
560
|
+
if (payerHex) {
|
|
561
|
+
try {
|
|
562
|
+
const payer = TronChain._toBase58CheckAny(String(payerHex));
|
|
563
|
+
add(payer, native, transaction_status_ts_1.AssetBalanceChange.fromMr(-BigInt(args.feeInSun), native.decimals));
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
void 0;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return balanceChanges;
|
|
571
|
+
}
|
|
572
|
+
async getTransactionStatus(txHash, opts) {
|
|
573
|
+
if (opts?.wait || (opts?.confirmations !== undefined && opts.confirmations > 1)) {
|
|
574
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.FeatureNotSupported, 'TronChain.getTransactionStatus does not honor wait/confirmations opts (would silently return immediately). Poll consumer-side or omit the opts.', { chainId: this.chainId });
|
|
575
|
+
}
|
|
576
|
+
if (Array.isArray(txHash)) {
|
|
577
|
+
return runBatch(txHash, (hash) => this.getTransactionStatusOnce(hash, opts));
|
|
578
|
+
}
|
|
579
|
+
return this.getTransactionStatusOnce(txHash, opts);
|
|
580
|
+
}
|
|
581
|
+
async getTransactionStatusOnce(txHash, opts) {
|
|
582
|
+
let info;
|
|
583
|
+
try {
|
|
584
|
+
info = await this.client.getTransactionInfo(txHash);
|
|
585
|
+
}
|
|
586
|
+
catch (err) {
|
|
587
|
+
if (err instanceof tron_client_ts_1.TronTransactionNotFoundError || (0, errors_ts_1.isChainError)(err, errors_ts_1.ChainErrorKinds.InvalidArgument)) {
|
|
588
|
+
return tron_transaction_status_ts_1.TronTransactionStatus.notFound(this.chainId, { code: 'NOT_FOUND', reason: err.message });
|
|
589
|
+
}
|
|
590
|
+
throw err;
|
|
591
|
+
}
|
|
592
|
+
if (Object.keys(info).length === 0 || info.id === undefined || info.id === null) {
|
|
593
|
+
return tron_transaction_status_ts_1.TronTransactionStatus.pending(this.chainId);
|
|
594
|
+
}
|
|
595
|
+
const receipt = info.receipt || {};
|
|
596
|
+
const contractRet = receipt.result ?? null;
|
|
597
|
+
const hasFailure = info.result === 'FAILED' || (contractRet !== null && contractRet !== 'SUCCESS');
|
|
598
|
+
let txData;
|
|
599
|
+
try {
|
|
600
|
+
txData = await this.client.getTransaction(txHash);
|
|
601
|
+
}
|
|
602
|
+
catch (err) {
|
|
603
|
+
if (!(err instanceof tron_client_ts_1.TronTransactionNotFoundError))
|
|
604
|
+
throw err;
|
|
605
|
+
txData = {};
|
|
606
|
+
}
|
|
607
|
+
const filteredWallets = opts?.filteredWallets === undefined || opts.filteredWallets === null
|
|
608
|
+
? null
|
|
609
|
+
: new Set([...opts.filteredWallets].map((w) => TronChain.formatWalletAddress(w)));
|
|
610
|
+
const filteredAssets = opts?.filteredAssets === undefined || opts.filteredAssets === null ? null : [...opts.filteredAssets];
|
|
611
|
+
const chainParameters = await this.getChainParameters();
|
|
612
|
+
if (info.blockTimeStamp === undefined || info.blockTimeStamp === null) {
|
|
613
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.TransactionDecodeFailed, `Tron transaction info for ${txHash} has no blockTimeStamp`, {
|
|
614
|
+
chainId: this.chainId,
|
|
615
|
+
txHash,
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
const inclusionAt = new Date(Math.trunc(Number(info.blockTimeStamp)));
|
|
619
|
+
const fees = tron_transaction_status_ts_1.TronTransactionFees.fromTransactionInfo(info, chainParameters.energyFee);
|
|
620
|
+
const balanceChanges = await this._balanceChangesFromInfo({
|
|
621
|
+
txData,
|
|
622
|
+
info,
|
|
623
|
+
feeInSun: fees.feeInSun,
|
|
624
|
+
filteredWallets,
|
|
625
|
+
filteredAssets,
|
|
626
|
+
});
|
|
627
|
+
if (!hasFailure) {
|
|
628
|
+
return tron_transaction_status_ts_1.TronTransactionStatus.successful({ chainId: this.chainId, inclusionAt, balanceChanges, fees });
|
|
629
|
+
}
|
|
630
|
+
return tron_transaction_status_ts_1.TronTransactionStatus.failed({
|
|
631
|
+
chainId: this.chainId,
|
|
632
|
+
inclusionAt,
|
|
633
|
+
error: {
|
|
634
|
+
code: String(contractRet ?? info.result ?? 'FAILED'),
|
|
635
|
+
reason: `Tron transaction failed: result=${(0, python_repr_ts_1.pyRepr)(info.result ?? null)}, contractRet=${(0, python_repr_ts_1.pyRepr)(contractRet)}`,
|
|
636
|
+
},
|
|
637
|
+
fees,
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
async broadcastSignedTransaction(signedTransaction) {
|
|
641
|
+
if (!(signedTransaction instanceof tron_transactions_ts_1.TronSignedTransaction)) {
|
|
642
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid transaction ${String(signedTransaction)}, expected TronSignedTransaction`, { chainId: this.chainId });
|
|
643
|
+
}
|
|
644
|
+
if (this.chainId !== signedTransaction.chainId) {
|
|
645
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid chain for signed transaction chain for ${String(signedTransaction)} with chain id ${signedTransaction.chainId}, expected ${this.chainId}`, { chainId: this.chainId });
|
|
646
|
+
}
|
|
647
|
+
if (signedTransaction.signedTransaction.client === null) {
|
|
648
|
+
signedTransaction.signedTransaction.client = this.client;
|
|
649
|
+
}
|
|
650
|
+
try {
|
|
651
|
+
const result = await signedTransaction.signedTransaction.broadcast();
|
|
652
|
+
const txHash = (0, python_builtins_ts_1.pyTruthy)(result.txid) ? result.txid : signedTransaction.txHash;
|
|
653
|
+
return new tron_transactions_ts_1.TronBroadcastTransactionResponse({ chain: this, txHash });
|
|
654
|
+
}
|
|
655
|
+
catch (err) {
|
|
656
|
+
return new tron_transactions_ts_1.TronBroadcastTransactionResponse({
|
|
657
|
+
chain: this,
|
|
658
|
+
txHash: signedTransaction.txHash,
|
|
659
|
+
broadcastError: err instanceof Error ? err : new Error(String(err)),
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
static verifySignature(publicKey, message, signedMessage) {
|
|
664
|
+
if (!(signedMessage instanceof TronSignedMessage)) {
|
|
665
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `TronChain expected a TronSignedMessage, got ${(0, python_repr_ts_1.pyTypeRepr)(signedMessage)}`);
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
const resolvedPublicKey = publicKey instanceof tron_keys_ts_1.TronPublicKey
|
|
669
|
+
? publicKey
|
|
670
|
+
: tron_keys_ts_1.TronPublicKey.fromHex(String(publicKey).startsWith('0x') ? String(publicKey).slice(2) : String(publicKey));
|
|
671
|
+
const signature = tron_keys_ts_1.TronSignature.fromHex(signedMessage.signature);
|
|
672
|
+
return resolvedPublicKey.verifyMsg((0, python_builtins_ts_1.pyEncodeUtf8)(message), signature);
|
|
673
|
+
}
|
|
674
|
+
catch {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
verifySignature(publicKey, message, signedMessage) {
|
|
679
|
+
return TronChain.verifySignature(publicKey, message, signedMessage);
|
|
680
|
+
}
|
|
681
|
+
async getBalance(owner, tokenIdentifier) {
|
|
682
|
+
const ownerAddress = TronChain.formatWalletAddress(owner);
|
|
683
|
+
if (tokenIdentifier === undefined) {
|
|
684
|
+
try {
|
|
685
|
+
const account = await this.client.getAccount(ownerAddress);
|
|
686
|
+
return BigInt(String(account.balance ?? 0));
|
|
687
|
+
}
|
|
688
|
+
catch (err) {
|
|
689
|
+
if (err instanceof tron_client_ts_1.TronAddressNotFoundError)
|
|
690
|
+
return 0n;
|
|
691
|
+
throw err;
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
const contract = await this.getTrc20Contract(tokenIdentifier);
|
|
695
|
+
return BigInt(await contract.callView('balanceOf', ownerAddress));
|
|
696
|
+
}
|
|
697
|
+
async createTransferUnsignedTransaction(req) {
|
|
698
|
+
if (!req.from) {
|
|
699
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, 'Tron transfers require an explicit `from` (no implicit signer)', {
|
|
700
|
+
chainId: this.chainId,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
const asset = await this.resolveAsset(req.tokenIdentifier);
|
|
704
|
+
const resolved = (0, chain_base_ts_1.resolveTransferAmount)(req, asset.decimals);
|
|
705
|
+
const amountHr = resolved.kind === 'exact'
|
|
706
|
+
? new decimal_js_1.Decimal((0, transaction_status_ts_1.minorUnitsToHrString)(resolved.amountMr, asset.decimals))
|
|
707
|
+
: await this.getAssetBalance(asset, req.from);
|
|
708
|
+
const bundle = await this.createTransferTransaction({
|
|
709
|
+
asset,
|
|
710
|
+
amountHr,
|
|
711
|
+
senderAddress: req.from,
|
|
712
|
+
receiverAddress: req.to,
|
|
713
|
+
isFullBalance: resolved.kind === 'full',
|
|
714
|
+
gasPricing: req.gasPricing,
|
|
715
|
+
memo: req.memo ?? null,
|
|
716
|
+
});
|
|
717
|
+
return bundle.transaction;
|
|
718
|
+
}
|
|
719
|
+
async broadcast(signed, opts) {
|
|
720
|
+
if (opts && opts.signal !== undefined) {
|
|
721
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.FeatureNotSupported, "Tron broadcast: signal is not honored (silently ignoring would let a caller conclude 'not sent' while the tx still lands)", { chainId: this.chainId });
|
|
722
|
+
}
|
|
723
|
+
const signedTransaction = parseTronSignedInput(signed, this.chainId);
|
|
724
|
+
const response = await this.broadcastSignedTransaction(signedTransaction);
|
|
725
|
+
const error = response.broadcastError;
|
|
726
|
+
if (error === null) {
|
|
727
|
+
const signedHash = signedTransaction.txHash.toLowerCase();
|
|
728
|
+
if (typeof response.txHash !== 'string' || response.txHash.toLowerCase() !== signedHash) {
|
|
729
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.RpcError, `Tron node answered txid ${(0, python_repr_ts_1.pyRepr)(response.txHash)} for the signed transaction ${signedTransaction.txHash}`, { chainId: this.chainId, txHash: signedTransaction.txHash });
|
|
730
|
+
}
|
|
731
|
+
return signedHash;
|
|
732
|
+
}
|
|
733
|
+
throw new errors_ts_1.ChainError(tronBroadcastErrorKind(error), `Tron broadcast failed: ${error.message}`, { chainId: this.chainId, txHash: response.txHash }, error);
|
|
734
|
+
}
|
|
735
|
+
async getChainTipHeight() {
|
|
736
|
+
return this.client.getLatestBlockNumber();
|
|
737
|
+
}
|
|
738
|
+
async verifyMessageSignature(req) {
|
|
739
|
+
try {
|
|
740
|
+
const signature = tron_keys_ts_1.TronSignature.fromHex(req.signature.startsWith('0x') ? req.signature.slice(2) : req.signature);
|
|
741
|
+
const recovered = signature.recoverPublicKeyFromMsg((0, python_builtins_ts_1.pyEncodeUtf8)(req.message));
|
|
742
|
+
return recovered.toBase58CheckAddress() === (0, tron_keys_ts_1.toBase58CheckAddress)(req.signer);
|
|
743
|
+
}
|
|
744
|
+
catch {
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
assertOwnAsset(asset) {
|
|
749
|
+
if (!(asset instanceof tron_asset_ts_1.TronAsset)) {
|
|
750
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid asset ${String(asset)} of type ${(0, python_repr_ts_1.pyTypeRepr)(asset)}, expected TronAsset`, {
|
|
751
|
+
chainId: this.chainId,
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
if (asset.chainId !== this.chainId) {
|
|
755
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, `Invalid chain id ${asset.chainId} for asset ${String(asset)}, expected ${this.chainId}`, { chainId: this.chainId });
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
exports.TronChain = TronChain;
|
|
760
|
+
const TRON_NOT_ACCEPTED_BROADCAST_CODES = new Set(['SIGERROR', 'CONTRACT_VALIDATE_ERROR', 'CONTRACT_EXE_ERROR', 'BANDWITH_ERROR']);
|
|
761
|
+
function tronBroadcastErrorKind(error) {
|
|
762
|
+
if (!(error instanceof tron_client_ts_1.TronApiError) || error.code === null)
|
|
763
|
+
return errors_ts_1.ChainErrorKinds.RpcError;
|
|
764
|
+
if (error.code === 'TOO_BIG_TRANSACTION_ERROR')
|
|
765
|
+
return errors_ts_1.ChainErrorKinds.TransactionTooLarge;
|
|
766
|
+
return TRON_NOT_ACCEPTED_BROADCAST_CODES.has(error.code) ? errors_ts_1.ChainErrorKinds.BroadcastRejected : errors_ts_1.ChainErrorKinds.RpcError;
|
|
767
|
+
}
|
|
768
|
+
function parseTronSignedInput(signed, chainId) {
|
|
769
|
+
let payload;
|
|
770
|
+
try {
|
|
771
|
+
payload = (0, transaction_json_ts_1.coerceJsonDict)(signed);
|
|
772
|
+
}
|
|
773
|
+
catch (err) {
|
|
774
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, 'Tron broadcast: signed must be the JSON of a TronSignedTransaction or of a signed Tron transaction ({txID, raw_data, signature})', { chainId }, err);
|
|
775
|
+
}
|
|
776
|
+
if (payload[transaction_json_ts_1.JSON_TRANSACTION_TYPE_KEY] === tron_transactions_ts_1.TronSignedTransaction.JSON_TYPE) {
|
|
777
|
+
return tron_transactions_ts_1.TronSignedTransaction.fromJson(payload);
|
|
778
|
+
}
|
|
779
|
+
if (typeof payload.txID !== 'string' || payload.raw_data === undefined) {
|
|
780
|
+
throw new errors_ts_1.ChainError(errors_ts_1.ChainErrorKinds.InvalidArgument, 'Tron broadcast: signed transaction JSON must carry txID and raw_data', { chainId });
|
|
781
|
+
}
|
|
782
|
+
(0, tron_transactions_ts_1.assertJsonSafeIntegers)(payload);
|
|
783
|
+
return new tron_transactions_ts_1.TronSignedTransaction({ chainId, signedTransaction: (0, tron_transactions_ts_1.tronTransactionFromJson)(payload) });
|
|
784
|
+
}
|
|
785
|
+
async function runBatch(items, fetchOne) {
|
|
786
|
+
const results = new Array(items.length);
|
|
787
|
+
let cursor = 0;
|
|
788
|
+
let aborted = false;
|
|
789
|
+
const spawn = async () => {
|
|
790
|
+
while (!aborted) {
|
|
791
|
+
const idx = cursor++;
|
|
792
|
+
if (idx >= items.length)
|
|
793
|
+
return;
|
|
794
|
+
try {
|
|
795
|
+
results[idx] = await fetchOne(items[idx]);
|
|
796
|
+
}
|
|
797
|
+
catch (err) {
|
|
798
|
+
aborted = true;
|
|
799
|
+
throw err;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
await Promise.all(Array.from({ length: Math.min(8, items.length) }, spawn));
|
|
804
|
+
return results;
|
|
805
|
+
}
|
|
806
|
+
function readEnv() {
|
|
807
|
+
return globalThis.process?.env;
|
|
808
|
+
}
|
|
809
|
+
//# sourceMappingURL=tron_chain.js.map
|