tronwb 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/dist/TronWeb.js +3 -0
- package/dist/TronWeb.js.LICENSE.txt +12 -0
- package/dist/TronWeb.js.map +1 -0
- package/dist/TronWeb.node.js +2 -0
- package/dist/TronWeb.node.js.map +1 -0
- package/kj9btptx.cjs +1 -0
- package/lib/commonjs/index.d.ts +64 -0
- package/lib/commonjs/index.js +37 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.d.ts +127 -0
- package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.js +1771 -0
- package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.js.map +1 -0
- package/lib/commonjs/lib/TransactionBuilder/helper.d.ts +28 -0
- package/lib/commonjs/lib/TransactionBuilder/helper.js +122 -0
- package/lib/commonjs/lib/TransactionBuilder/helper.js.map +1 -0
- package/lib/commonjs/lib/contract/index.d.ts +29 -0
- package/lib/commonjs/lib/contract/index.js +124 -0
- package/lib/commonjs/lib/contract/index.js.map +1 -0
- package/lib/commonjs/lib/contract/method.d.ts +50 -0
- package/lib/commonjs/lib/contract/method.js +238 -0
- package/lib/commonjs/lib/contract/method.js.map +1 -0
- package/lib/commonjs/lib/event.d.ts +85 -0
- package/lib/commonjs/lib/event.js +137 -0
- package/lib/commonjs/lib/event.js.map +1 -0
- package/lib/commonjs/lib/plugin.d.ts +28 -0
- package/lib/commonjs/lib/plugin.js +84 -0
- package/lib/commonjs/lib/plugin.js.map +1 -0
- package/lib/commonjs/lib/providers/HttpProvider.d.ts +15 -0
- package/lib/commonjs/lib/providers/HttpProvider.js +63 -0
- package/lib/commonjs/lib/providers/HttpProvider.js.map +1 -0
- package/lib/commonjs/lib/providers/index.d.ts +6 -0
- package/lib/commonjs/lib/providers/index.js +8 -0
- package/lib/commonjs/lib/providers/index.js.map +1 -0
- package/lib/commonjs/lib/trx.d.ts +315 -0
- package/lib/commonjs/lib/trx.js +965 -0
- package/lib/commonjs/lib/trx.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/paramValidator/index.d.ts +19 -0
- package/lib/commonjs/paramValidator/index.js +110 -0
- package/lib/commonjs/paramValidator/index.js.map +1 -0
- package/lib/commonjs/protocol/core/Tron_pb.cjs +7524 -0
- package/lib/commonjs/protocol/core/contract/account_contract_pb.cjs +961 -0
- package/lib/commonjs/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
- package/lib/commonjs/protocol/core/contract/balance_contract_pb.cjs +3826 -0
- package/lib/commonjs/protocol/core/contract/common_pb.cjs +34 -0
- package/lib/commonjs/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
- package/lib/commonjs/protocol/core/contract/proposal_contract_pb.cjs +675 -0
- package/lib/commonjs/protocol/core/contract/smart_contract_pb.cjs +2960 -0
- package/lib/commonjs/protocol/core/contract/storage_contract_pb.cjs +848 -0
- package/lib/commonjs/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
- package/lib/commonjs/protocol/core/contract/witness_contract_pb.cjs +956 -0
- package/lib/commonjs/tronweb.d.ts +111 -0
- package/lib/commonjs/tronweb.js +365 -0
- package/lib/commonjs/tronweb.js.map +1 -0
- package/lib/commonjs/types/ABI.d.ts +59 -0
- package/lib/commonjs/types/ABI.js +3 -0
- package/lib/commonjs/types/ABI.js.map +1 -0
- package/lib/commonjs/types/APIResponse.d.ts +31 -0
- package/lib/commonjs/types/APIResponse.js +3 -0
- package/lib/commonjs/types/APIResponse.js.map +1 -0
- package/lib/commonjs/types/Contract.d.ts +287 -0
- package/lib/commonjs/types/Contract.js +63 -0
- package/lib/commonjs/types/Contract.js.map +1 -0
- package/lib/commonjs/types/Providers.d.ts +8 -0
- package/lib/commonjs/types/Providers.js +3 -0
- package/lib/commonjs/types/Providers.js.map +1 -0
- package/lib/commonjs/types/Transaction.d.ts +65 -0
- package/lib/commonjs/types/Transaction.js +3 -0
- package/lib/commonjs/types/Transaction.js.map +1 -0
- package/lib/commonjs/types/TransactionBuilder.d.ts +270 -0
- package/lib/commonjs/types/TransactionBuilder.js +3 -0
- package/lib/commonjs/types/TransactionBuilder.js.map +1 -0
- package/lib/commonjs/types/TronWeb.d.ts +20 -0
- package/lib/commonjs/types/TronWeb.js +3 -0
- package/lib/commonjs/types/TronWeb.js.map +1 -0
- package/lib/commonjs/types/Trx.d.ts +263 -0
- package/lib/commonjs/types/Trx.js +42 -0
- package/lib/commonjs/types/Trx.js.map +1 -0
- package/lib/commonjs/types/UtilsTypes.d.ts +23 -0
- package/lib/commonjs/types/UtilsTypes.js +3 -0
- package/lib/commonjs/types/UtilsTypes.js.map +1 -0
- package/lib/commonjs/types/index.d.ts +9 -0
- package/lib/commonjs/types/index.js +13 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/abi.d.ts +5 -0
- package/lib/commonjs/utils/abi.js +251 -0
- package/lib/commonjs/utils/abi.js.map +1 -0
- package/lib/commonjs/utils/accounts.d.ts +22 -0
- package/lib/commonjs/utils/accounts.js +51 -0
- package/lib/commonjs/utils/accounts.js.map +1 -0
- package/lib/commonjs/utils/address.d.ts +12 -0
- package/lib/commonjs/utils/address.js +91 -0
- package/lib/commonjs/utils/address.js.map +1 -0
- package/lib/commonjs/utils/base58.d.ts +3 -0
- package/lib/commonjs/utils/base58.js +68 -0
- package/lib/commonjs/utils/base58.js.map +1 -0
- package/lib/commonjs/utils/base64.d.ts +10 -0
- package/lib/commonjs/utils/base64.js +173 -0
- package/lib/commonjs/utils/base64.js.map +1 -0
- package/lib/commonjs/utils/bytes.d.ts +7 -0
- package/lib/commonjs/utils/bytes.js +61 -0
- package/lib/commonjs/utils/bytes.js.map +1 -0
- package/lib/commonjs/utils/code.d.ts +12 -0
- package/lib/commonjs/utils/code.js +166 -0
- package/lib/commonjs/utils/code.js.map +1 -0
- package/lib/commonjs/utils/crypto.d.ts +25 -0
- package/lib/commonjs/utils/crypto.js +222 -0
- package/lib/commonjs/utils/crypto.js.map +1 -0
- package/lib/commonjs/utils/ethersUtils.d.ts +14 -0
- package/lib/commonjs/utils/ethersUtils.js +39 -0
- package/lib/commonjs/utils/ethersUtils.js.map +1 -0
- package/lib/commonjs/utils/fragments.d.ts +465 -0
- package/lib/commonjs/utils/fragments.js +1342 -0
- package/lib/commonjs/utils/fragments.js.map +1 -0
- package/lib/commonjs/utils/help.d.ts +8 -0
- package/lib/commonjs/utils/help.js +61 -0
- package/lib/commonjs/utils/help.js.map +1 -0
- package/lib/commonjs/utils/index.d.ts +56 -0
- package/lib/commonjs/utils/index.js +43 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/interface.d.ts +381 -0
- package/lib/commonjs/utils/interface.js +1121 -0
- package/lib/commonjs/utils/interface.js.map +1 -0
- package/lib/commonjs/utils/message.d.ts +4 -0
- package/lib/commonjs/utils/message.js +38 -0
- package/lib/commonjs/utils/message.js.map +1 -0
- package/lib/commonjs/utils/transaction.d.ts +17 -0
- package/lib/commonjs/utils/transaction.js +678 -0
- package/lib/commonjs/utils/transaction.js.map +1 -0
- package/lib/commonjs/utils/typedData.d.ts +148 -0
- package/lib/commonjs/utils/typedData.js +498 -0
- package/lib/commonjs/utils/typedData.js.map +1 -0
- package/lib/commonjs/utils/validations.d.ts +22 -0
- package/lib/commonjs/utils/validations.js +128 -0
- package/lib/commonjs/utils/validations.js.map +1 -0
- package/lib/esm/index.d.ts +64 -0
- package/lib/esm/index.js +33 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/lib/TransactionBuilder/TransactionBuilder.d.ts +127 -0
- package/lib/esm/lib/TransactionBuilder/TransactionBuilder.js +1767 -0
- package/lib/esm/lib/TransactionBuilder/TransactionBuilder.js.map +1 -0
- package/lib/esm/lib/TransactionBuilder/helper.d.ts +28 -0
- package/lib/esm/lib/TransactionBuilder/helper.js +112 -0
- package/lib/esm/lib/TransactionBuilder/helper.js.map +1 -0
- package/lib/esm/lib/contract/index.d.ts +29 -0
- package/lib/esm/lib/contract/index.js +118 -0
- package/lib/esm/lib/contract/index.js.map +1 -0
- package/lib/esm/lib/contract/method.d.ts +50 -0
- package/lib/esm/lib/contract/method.js +233 -0
- package/lib/esm/lib/contract/method.js.map +1 -0
- package/lib/esm/lib/event.d.ts +85 -0
- package/lib/esm/lib/event.js +132 -0
- package/lib/esm/lib/event.js.map +1 -0
- package/lib/esm/lib/plugin.d.ts +28 -0
- package/lib/esm/lib/plugin.js +79 -0
- package/lib/esm/lib/plugin.js.map +1 -0
- package/lib/esm/lib/providers/HttpProvider.d.ts +15 -0
- package/lib/esm/lib/providers/HttpProvider.js +59 -0
- package/lib/esm/lib/providers/HttpProvider.js.map +1 -0
- package/lib/esm/lib/providers/index.d.ts +6 -0
- package/lib/esm/lib/providers/index.js +4 -0
- package/lib/esm/lib/providers/index.js.map +1 -0
- package/lib/esm/lib/trx.d.ts +315 -0
- package/lib/esm/lib/trx.js +960 -0
- package/lib/esm/lib/trx.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/paramValidator/index.d.ts +19 -0
- package/lib/esm/paramValidator/index.js +106 -0
- package/lib/esm/paramValidator/index.js.map +1 -0
- package/lib/esm/protocol/core/Tron_pb.cjs +7524 -0
- package/lib/esm/protocol/core/contract/account_contract_pb.cjs +961 -0
- package/lib/esm/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
- package/lib/esm/protocol/core/contract/balance_contract_pb.cjs +3826 -0
- package/lib/esm/protocol/core/contract/common_pb.cjs +34 -0
- package/lib/esm/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
- package/lib/esm/protocol/core/contract/proposal_contract_pb.cjs +675 -0
- package/lib/esm/protocol/core/contract/smart_contract_pb.cjs +2960 -0
- package/lib/esm/protocol/core/contract/storage_contract_pb.cjs +848 -0
- package/lib/esm/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
- package/lib/esm/protocol/core/contract/witness_contract_pb.cjs +956 -0
- package/lib/esm/tronweb.d.ts +111 -0
- package/lib/esm/tronweb.js +360 -0
- package/lib/esm/tronweb.js.map +1 -0
- package/lib/esm/types/ABI.d.ts +59 -0
- package/lib/esm/types/ABI.js +2 -0
- package/lib/esm/types/ABI.js.map +1 -0
- package/lib/esm/types/APIResponse.d.ts +31 -0
- package/lib/esm/types/APIResponse.js +2 -0
- package/lib/esm/types/APIResponse.js.map +1 -0
- package/lib/esm/types/Contract.d.ts +287 -0
- package/lib/esm/types/Contract.js +60 -0
- package/lib/esm/types/Contract.js.map +1 -0
- package/lib/esm/types/Providers.d.ts +8 -0
- package/lib/esm/types/Providers.js +2 -0
- package/lib/esm/types/Providers.js.map +1 -0
- package/lib/esm/types/Transaction.d.ts +65 -0
- package/lib/esm/types/Transaction.js +2 -0
- package/lib/esm/types/Transaction.js.map +1 -0
- package/lib/esm/types/TransactionBuilder.d.ts +270 -0
- package/lib/esm/types/TransactionBuilder.js +2 -0
- package/lib/esm/types/TransactionBuilder.js.map +1 -0
- package/lib/esm/types/TronWeb.d.ts +20 -0
- package/lib/esm/types/TronWeb.js +2 -0
- package/lib/esm/types/TronWeb.js.map +1 -0
- package/lib/esm/types/Trx.d.ts +263 -0
- package/lib/esm/types/Trx.js +39 -0
- package/lib/esm/types/Trx.js.map +1 -0
- package/lib/esm/types/UtilsTypes.d.ts +23 -0
- package/lib/esm/types/UtilsTypes.js +2 -0
- package/lib/esm/types/UtilsTypes.js.map +1 -0
- package/lib/esm/types/index.d.ts +9 -0
- package/lib/esm/types/index.js +10 -0
- package/lib/esm/types/index.js.map +1 -0
- package/lib/esm/utils/abi.d.ts +5 -0
- package/lib/esm/utils/abi.js +245 -0
- package/lib/esm/utils/abi.js.map +1 -0
- package/lib/esm/utils/accounts.d.ts +22 -0
- package/lib/esm/utils/accounts.js +46 -0
- package/lib/esm/utils/accounts.js.map +1 -0
- package/lib/esm/utils/address.d.ts +12 -0
- package/lib/esm/utils/address.js +82 -0
- package/lib/esm/utils/address.js.map +1 -0
- package/lib/esm/utils/base58.d.ts +3 -0
- package/lib/esm/utils/base58.js +64 -0
- package/lib/esm/utils/base58.js.map +1 -0
- package/lib/esm/utils/base64.d.ts +10 -0
- package/lib/esm/utils/base64.js +169 -0
- package/lib/esm/utils/base64.js.map +1 -0
- package/lib/esm/utils/bytes.d.ts +7 -0
- package/lib/esm/utils/bytes.js +53 -0
- package/lib/esm/utils/bytes.js.map +1 -0
- package/lib/esm/utils/code.d.ts +12 -0
- package/lib/esm/utils/code.js +149 -0
- package/lib/esm/utils/code.js.map +1 -0
- package/lib/esm/utils/crypto.d.ts +25 -0
- package/lib/esm/utils/crypto.js +198 -0
- package/lib/esm/utils/crypto.js.map +1 -0
- package/lib/esm/utils/ethersUtils.d.ts +14 -0
- package/lib/esm/utils/ethersUtils.js +17 -0
- package/lib/esm/utils/ethersUtils.js.map +1 -0
- package/lib/esm/utils/fragments.d.ts +465 -0
- package/lib/esm/utils/fragments.js +1330 -0
- package/lib/esm/utils/fragments.js.map +1 -0
- package/lib/esm/utils/help.d.ts +8 -0
- package/lib/esm/utils/help.js +51 -0
- package/lib/esm/utils/help.js.map +1 -0
- package/lib/esm/utils/index.d.ts +56 -0
- package/lib/esm/utils/index.js +40 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/esm/utils/interface.d.ts +381 -0
- package/lib/esm/utils/interface.js +1112 -0
- package/lib/esm/utils/interface.js.map +1 -0
- package/lib/esm/utils/message.d.ts +4 -0
- package/lib/esm/utils/message.js +32 -0
- package/lib/esm/utils/message.js.map +1 -0
- package/lib/esm/utils/transaction.d.ts +17 -0
- package/lib/esm/utils/transaction.js +669 -0
- package/lib/esm/utils/transaction.js.map +1 -0
- package/lib/esm/utils/typedData.d.ts +148 -0
- package/lib/esm/utils/typedData.js +493 -0
- package/lib/esm/utils/typedData.js.map +1 -0
- package/lib/esm/utils/validations.d.ts +22 -0
- package/lib/esm/utils/validations.js +108 -0
- package/lib/esm/utils/validations.js.map +1 -0
- package/package.json +110 -0
- package/src/index.ts +42 -0
- package/src/lib/TransactionBuilder/TransactionBuilder.ts +2272 -0
- package/src/lib/TransactionBuilder/helper.ts +139 -0
- package/src/lib/contract/index.ts +151 -0
- package/src/lib/contract/method.ts +336 -0
- package/src/lib/event.ts +248 -0
- package/src/lib/plugin.ts +102 -0
- package/src/lib/providers/HttpProvider.ts +66 -0
- package/src/lib/providers/index.ts +6 -0
- package/src/lib/trx.ts +1463 -0
- package/src/paramValidator/index.ts +136 -0
- package/src/protocol/core/Tron_pb.cjs +7524 -0
- package/src/protocol/core/contract/account_contract_pb.cjs +961 -0
- package/src/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
- package/src/protocol/core/contract/balance_contract_pb.cjs +3826 -0
- package/src/protocol/core/contract/common_pb.cjs +34 -0
- package/src/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
- package/src/protocol/core/contract/proposal_contract_pb.cjs +675 -0
- package/src/protocol/core/contract/smart_contract_pb.cjs +2960 -0
- package/src/protocol/core/contract/storage_contract_pb.cjs +848 -0
- package/src/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
- package/src/protocol/core/contract/witness_contract_pb.cjs +956 -0
- package/src/tronweb.ts +437 -0
- package/src/types/ABI.ts +82 -0
- package/src/types/APIResponse.ts +34 -0
- package/src/types/Contract.ts +352 -0
- package/src/types/Providers.ts +7 -0
- package/src/types/Transaction.ts +70 -0
- package/src/types/TransactionBuilder.ts +281 -0
- package/src/types/TronWeb.ts +23 -0
- package/src/types/Trx.ts +285 -0
- package/src/types/UtilsTypes.ts +25 -0
- package/src/types/index.ts +9 -0
- package/src/types/interface.d.ts +1 -0
- package/src/utils/abi.ts +257 -0
- package/src/utils/accounts.ts +60 -0
- package/src/utils/address.ts +89 -0
- package/src/utils/base58.ts +78 -0
- package/src/utils/base64.ts +200 -0
- package/src/utils/bytes.ts +68 -0
- package/src/utils/code.ts +172 -0
- package/src/utils/crypto.ts +264 -0
- package/src/utils/ethersUtils.ts +60 -0
- package/src/utils/fragments.ts +1738 -0
- package/src/utils/help.ts +59 -0
- package/src/utils/index.ts +42 -0
- package/src/utils/interface.ts +1362 -0
- package/src/utils/message.ts +38 -0
- package/src/utils/transaction.ts +991 -0
- package/src/utils/typedData.ts +688 -0
- package/src/utils/validations.ts +130 -0
@@ -0,0 +1,139 @@
|
|
1
|
+
import { TronWeb } from '../../tronweb.js';
|
2
|
+
import { Transaction, TransactionWrapper } from '../../types/Transaction.js';
|
3
|
+
import { txCheckWithArgs, txJsonToPb, txPbToTxID, txPbToRawDataHex } from '../../utils/transaction.js';
|
4
|
+
import { keccak256 } from '../../utils/ethersUtils.js';
|
5
|
+
import { BlockWithoutDetail } from '../../types/APIResponse.js';
|
6
|
+
import HttpProvider from '../providers/HttpProvider.js';
|
7
|
+
import { ContractParamter, ContractType } from '../../types/Contract.js';
|
8
|
+
import { TriggerConstantContractOptions } from '../../types/TransactionBuilder.js';
|
9
|
+
|
10
|
+
export function fromUtf8(value: string) {
|
11
|
+
return TronWeb.fromUtf8(value).replace(/^0x/, '');
|
12
|
+
}
|
13
|
+
|
14
|
+
export function deepCopyJson<T = unknown>(json: object): T {
|
15
|
+
return JSON.parse(JSON.stringify(json));
|
16
|
+
}
|
17
|
+
export function resultManager(transaction: TransactionWrapper, data: unknown, options: TriggerConstantContractOptions) {
|
18
|
+
if (transaction.Error) throw new Error(transaction.Error);
|
19
|
+
|
20
|
+
if (transaction.result && transaction.result.message) {
|
21
|
+
throw new Error(TronWeb.toUtf8(transaction.result.message));
|
22
|
+
}
|
23
|
+
const authResult = txCheckWithArgs(transaction, data, options);
|
24
|
+
if (authResult) {
|
25
|
+
return transaction;
|
26
|
+
}
|
27
|
+
throw new Error('Invalid transaction');
|
28
|
+
}
|
29
|
+
|
30
|
+
export function resultManagerTriggerSmartContract(
|
31
|
+
transaction: TransactionWrapper,
|
32
|
+
data: unknown,
|
33
|
+
options: TriggerConstantContractOptions
|
34
|
+
) {
|
35
|
+
if (transaction.Error) throw new Error(transaction.Error);
|
36
|
+
|
37
|
+
if (transaction.result && transaction.result.message) {
|
38
|
+
throw new Error(TronWeb.toUtf8(transaction.result.message));
|
39
|
+
}
|
40
|
+
|
41
|
+
if (!(options._isConstant || options.estimateEnergy)) {
|
42
|
+
const authResult = txCheckWithArgs(transaction.transaction, data, options);
|
43
|
+
if (authResult) {
|
44
|
+
return transaction;
|
45
|
+
}
|
46
|
+
throw new Error('Invalid transaction');
|
47
|
+
}
|
48
|
+
return transaction;
|
49
|
+
}
|
50
|
+
|
51
|
+
export function genContractAddress(ownerAddress: string, txID: string) {
|
52
|
+
return (
|
53
|
+
'41' +
|
54
|
+
keccak256(Buffer.from(txID + ownerAddress, 'hex'))
|
55
|
+
.toString()
|
56
|
+
.substring(2)
|
57
|
+
.slice(24)
|
58
|
+
);
|
59
|
+
}
|
60
|
+
|
61
|
+
export function getHeaderInfo(node: HttpProvider) {
|
62
|
+
return node.request<BlockWithoutDetail>('wallet/getblock', { detail: false }, 'post').then((data) => {
|
63
|
+
return {
|
64
|
+
ref_block_bytes: data.block_header.raw_data.number.toString(16).slice(-4).padStart(4, '0'),
|
65
|
+
ref_block_hash: data.blockID.slice(16, 32),
|
66
|
+
expiration: data.block_header.raw_data.timestamp + 60 * 1000,
|
67
|
+
timestamp: data.block_header.raw_data.timestamp,
|
68
|
+
};
|
69
|
+
});
|
70
|
+
}
|
71
|
+
|
72
|
+
function checkBlockHeader(options = {} as Partial<Transaction['raw_data']>): boolean {
|
73
|
+
if (
|
74
|
+
typeof options['ref_block_bytes'] === 'undefined' &&
|
75
|
+
typeof options['ref_block_hash'] === 'undefined' &&
|
76
|
+
typeof options['expiration'] === 'undefined' &&
|
77
|
+
typeof options['timestamp'] === 'undefined'
|
78
|
+
) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
if (typeof options['ref_block_bytes'] !== 'string') {
|
82
|
+
throw new Error('Invalid ref_block_bytes provided.');
|
83
|
+
}
|
84
|
+
if (typeof options['ref_block_hash'] !== 'string') {
|
85
|
+
throw new Error('Invalid ref_block_hash provided.');
|
86
|
+
}
|
87
|
+
if (typeof options['expiration'] !== 'number') {
|
88
|
+
throw new Error('Invalid expiration provided.');
|
89
|
+
}
|
90
|
+
if (typeof options['timestamp'] !== 'number') {
|
91
|
+
throw new Error('Invalid timestamp provided.');
|
92
|
+
}
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
|
96
|
+
export async function createTransaction<T extends ContractParamter>(
|
97
|
+
tronWeb: TronWeb,
|
98
|
+
type: ContractType,
|
99
|
+
value: T,
|
100
|
+
Permission_id?: number,
|
101
|
+
options = {} as Partial<Omit<Transaction['raw_data'], 'contract'>>
|
102
|
+
): Promise<Transaction<T>> {
|
103
|
+
const tx: Transaction<T> = {
|
104
|
+
visible: false,
|
105
|
+
txID: '',
|
106
|
+
raw_data_hex: '',
|
107
|
+
raw_data: {
|
108
|
+
contract: [
|
109
|
+
{
|
110
|
+
parameter: {
|
111
|
+
value,
|
112
|
+
type_url: `type.googleapis.com/protocol.${type}`,
|
113
|
+
},
|
114
|
+
type,
|
115
|
+
},
|
116
|
+
],
|
117
|
+
...(checkBlockHeader(options) ? ({} as Transaction['raw_data']) : await getHeaderInfo(tronWeb.fullNode)),
|
118
|
+
...options,
|
119
|
+
},
|
120
|
+
};
|
121
|
+
if (Permission_id) {
|
122
|
+
tx.raw_data.contract[0].Permission_id = Permission_id;
|
123
|
+
}
|
124
|
+
const pb = txJsonToPb(tx);
|
125
|
+
tx.txID = txPbToTxID(pb).replace(/^0x/, '');
|
126
|
+
tx.raw_data_hex = txPbToRawDataHex(pb).toLowerCase();
|
127
|
+
return tx;
|
128
|
+
}
|
129
|
+
|
130
|
+
export function getTransactionOptions(options: { blockHeader?: Partial<Transaction['raw_data']> } = {}) {
|
131
|
+
const ret = {} as Partial<Transaction['raw_data']>;
|
132
|
+
if (checkBlockHeader(options.blockHeader)) {
|
133
|
+
ret['ref_block_bytes'] = options.blockHeader!['ref_block_bytes'];
|
134
|
+
ret['ref_block_hash'] = options.blockHeader!['ref_block_hash'];
|
135
|
+
ret['expiration'] = options.blockHeader!['expiration'];
|
136
|
+
ret['timestamp'] = options.blockHeader!['timestamp'];
|
137
|
+
}
|
138
|
+
return ret;
|
139
|
+
}
|
@@ -0,0 +1,151 @@
|
|
1
|
+
import { TronWeb } from '../../tronweb.js';
|
2
|
+
import utils from '../../utils/index.js';
|
3
|
+
import { Method, AbiFragmentNoErrConstructor } from './method.js';
|
4
|
+
import type { ContractAbiInterface } from '../../types/ABI.js';
|
5
|
+
import { Address } from '../../types/Trx.js';
|
6
|
+
import { CreateSmartContractOptions } from '../../types/TransactionBuilder.js';
|
7
|
+
|
8
|
+
|
9
|
+
export class Contract {
|
10
|
+
tronWeb: TronWeb;
|
11
|
+
abi: ContractAbiInterface;
|
12
|
+
address: false | string;
|
13
|
+
eventListener: any;
|
14
|
+
bytecode?: false | string;
|
15
|
+
deployed?: boolean;
|
16
|
+
lastBlock?: false | number;
|
17
|
+
methods: Record<string | number | symbol, (...args: any) => ReturnType<Method['onMethod']>>;
|
18
|
+
methodInstances: Record<string | number | symbol, Method>;
|
19
|
+
props: any[];
|
20
|
+
[key: string | number | symbol]: any;
|
21
|
+
|
22
|
+
constructor(tronWeb: TronWeb, abi: ContractAbiInterface = [], address: Address) {
|
23
|
+
if (!tronWeb || !(tronWeb instanceof TronWeb)) throw new Error('Expected instance of TronWeb');
|
24
|
+
|
25
|
+
this.tronWeb = tronWeb;
|
26
|
+
|
27
|
+
this.address = address;
|
28
|
+
this.abi = abi;
|
29
|
+
|
30
|
+
this.eventListener = false;
|
31
|
+
this.bytecode = false;
|
32
|
+
this.deployed = false;
|
33
|
+
this.lastBlock = false;
|
34
|
+
|
35
|
+
this.methods = {};
|
36
|
+
this.methodInstances = {};
|
37
|
+
this.props = [];
|
38
|
+
|
39
|
+
if (utils.address.isAddress(address)) {
|
40
|
+
this.deployed = true;
|
41
|
+
} else {
|
42
|
+
this.address = false;
|
43
|
+
}
|
44
|
+
|
45
|
+
this.loadAbi(abi);
|
46
|
+
}
|
47
|
+
|
48
|
+
hasProperty(property: number | string | symbol) {
|
49
|
+
// eslint-disable-next-line no-prototype-builtins
|
50
|
+
return this.hasOwnProperty(property) || (this as any).__proto__.hasOwnProperty(property);
|
51
|
+
}
|
52
|
+
|
53
|
+
loadAbi(abi: ContractAbiInterface) {
|
54
|
+
this.abi = abi;
|
55
|
+
this.methods = {};
|
56
|
+
|
57
|
+
this.props.forEach((prop: string) => delete (this as any)[prop]);
|
58
|
+
|
59
|
+
abi.forEach((func) => {
|
60
|
+
// Don't build a method for constructor function. That's handled through contract create.
|
61
|
+
// Don't build a method for error function.
|
62
|
+
if (!func.type || /constructor|error/i.test(func.type)) return;
|
63
|
+
|
64
|
+
const method = new Method(this, func as AbiFragmentNoErrConstructor);
|
65
|
+
const methodCall = method.onMethod.bind(method);
|
66
|
+
|
67
|
+
const { name, functionSelector, signature } = method;
|
68
|
+
|
69
|
+
this.methods[name] = methodCall;
|
70
|
+
this.methods[functionSelector!] = methodCall;
|
71
|
+
this.methods[signature] = methodCall;
|
72
|
+
|
73
|
+
this.methodInstances[name] = method;
|
74
|
+
this.methodInstances[functionSelector!] = method;
|
75
|
+
this.methodInstances[signature] = method;
|
76
|
+
|
77
|
+
if (!this.hasProperty(name)) {
|
78
|
+
(this as any)[name] = methodCall;
|
79
|
+
this.props.push(name);
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!this.hasProperty(functionSelector!)) {
|
83
|
+
(this as any)[functionSelector!] = methodCall;
|
84
|
+
this.props.push(functionSelector);
|
85
|
+
}
|
86
|
+
|
87
|
+
if (!this.hasProperty(signature)) {
|
88
|
+
(this as any)[signature] = methodCall;
|
89
|
+
this.props.push(signature);
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
|
94
|
+
decodeInput(data: string) {
|
95
|
+
const methodName = data.substring(0, 8);
|
96
|
+
const inputData = data.substring(8);
|
97
|
+
|
98
|
+
if (!this.methodInstances[methodName]) throw new Error('Contract method ' + methodName + ' not found');
|
99
|
+
|
100
|
+
const methodInstance = this.methodInstances[methodName];
|
101
|
+
|
102
|
+
return {
|
103
|
+
name: methodInstance.name,
|
104
|
+
params: this.methodInstances[methodName].decodeInput(inputData),
|
105
|
+
};
|
106
|
+
}
|
107
|
+
|
108
|
+
async new(options: CreateSmartContractOptions, privateKey = this.tronWeb.defaultPrivateKey) {
|
109
|
+
const address = this.tronWeb.address.fromPrivateKey(privateKey as string);
|
110
|
+
const transaction = await this.tronWeb.transactionBuilder.createSmartContract(options, address as Address);
|
111
|
+
const signedTransaction = await this.tronWeb.trx.sign(transaction, privateKey);
|
112
|
+
const contract = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
|
113
|
+
|
114
|
+
if (contract.code) {
|
115
|
+
throw {
|
116
|
+
error: contract.code,
|
117
|
+
message: this.tronWeb.toUtf8(contract.message),
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
121
|
+
await utils.sleep(3000);
|
122
|
+
return this.at(signedTransaction.contract_address);
|
123
|
+
}
|
124
|
+
|
125
|
+
async at(contractAddress: Address) {
|
126
|
+
try {
|
127
|
+
const contract = await this.tronWeb.trx.getContract(contractAddress);
|
128
|
+
|
129
|
+
if (!contract.contract_address) {
|
130
|
+
throw new Error('Unknown error: ' + JSON.stringify(contract, null, 2));
|
131
|
+
}
|
132
|
+
|
133
|
+
this.address = contract.contract_address;
|
134
|
+
this.bytecode = contract.bytecode;
|
135
|
+
this.deployed = true;
|
136
|
+
|
137
|
+
this.loadAbi(contract.abi ? (contract.abi.entrys ? contract.abi.entrys : []) : []);
|
138
|
+
|
139
|
+
return this;
|
140
|
+
} catch (ex: any) {
|
141
|
+
if (ex.toString().includes('does not exist')) {
|
142
|
+
throw new Error('Contract has not been deployed on the network');
|
143
|
+
}
|
144
|
+
|
145
|
+
throw new Error(ex);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
export type { CallOptions, SendOptions, AbiFragmentNoErrConstructor } from './method.js';
|
151
|
+
export { Method } from './method.js';
|
@@ -0,0 +1,336 @@
|
|
1
|
+
/* eslint-disable no-control-regex */
|
2
|
+
import utils from '../../utils/index.js';
|
3
|
+
import { encodeParamsV2ByABI, decodeParamsV2ByABI } from '../../utils/abi.js';
|
4
|
+
import { TronWeb } from '../../tronweb.js';
|
5
|
+
import { Contract } from './index.js';
|
6
|
+
import { sha3 } from '../../utils/crypto.js';
|
7
|
+
|
8
|
+
export interface CallOptions {
|
9
|
+
feeLimit?: number;
|
10
|
+
callValue?: number;
|
11
|
+
callTokenValue?: number;
|
12
|
+
callTokenId?: number;
|
13
|
+
userFeePercentage?: number;
|
14
|
+
shouldPollResponse?: boolean;
|
15
|
+
from?: string | false;
|
16
|
+
rawParameter?: string;
|
17
|
+
_isConstant?: true;
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface SendOptions {
|
21
|
+
from?: string | false;
|
22
|
+
feeLimit?: number;
|
23
|
+
callValue?: number;
|
24
|
+
rawParameter?: string;
|
25
|
+
userFeePercentage?: number;
|
26
|
+
shouldPollResponse?: boolean;
|
27
|
+
pollTimes?: number;
|
28
|
+
rawResponse?: boolean;
|
29
|
+
keepTxID?: boolean;
|
30
|
+
}
|
31
|
+
|
32
|
+
import type {
|
33
|
+
FragmentTypes,
|
34
|
+
StateMutabilityTypes,
|
35
|
+
FunctionFragment,
|
36
|
+
FallbackFragment,
|
37
|
+
ReceiveFragment,
|
38
|
+
EventFragment,
|
39
|
+
AbiInputsType,
|
40
|
+
AbiOutputsType,
|
41
|
+
} from '../../types/ABI.js';
|
42
|
+
|
43
|
+
export type AbiFragmentNoErrConstructor = FunctionFragment | EventFragment | FallbackFragment | ReceiveFragment;
|
44
|
+
|
45
|
+
const getFunctionSelector = (abi: AbiFragmentNoErrConstructor) => {
|
46
|
+
if ('stateMutability' in abi) {
|
47
|
+
(abi.stateMutability as StateMutabilityTypes) = abi.stateMutability ? abi.stateMutability.toLowerCase() : 'nonpayable';
|
48
|
+
}
|
49
|
+
(abi.type as FragmentTypes) = abi.type ? abi.type.toLowerCase() : '';
|
50
|
+
if (abi.type === 'fallback' || abi.type === 'receive') return '0x';
|
51
|
+
const iface = new utils.ethersUtils.Interface([abi]);
|
52
|
+
let obj;
|
53
|
+
if (abi.type === 'event') {
|
54
|
+
obj = iface.getEvent(abi.name);
|
55
|
+
} else {
|
56
|
+
obj = iface.getFunction(abi.name);
|
57
|
+
}
|
58
|
+
if (obj) {
|
59
|
+
return obj.format('sighash');
|
60
|
+
}
|
61
|
+
throw new Error('unknown function');
|
62
|
+
};
|
63
|
+
|
64
|
+
const decodeOutput = (abi: AbiFragmentNoErrConstructor, output: string) => {
|
65
|
+
return decodeParamsV2ByABI(abi, output);
|
66
|
+
};
|
67
|
+
|
68
|
+
export class Method {
|
69
|
+
tronWeb: TronWeb;
|
70
|
+
contract: Contract;
|
71
|
+
abi: AbiFragmentNoErrConstructor;
|
72
|
+
name: string;
|
73
|
+
inputs: AbiInputsType;
|
74
|
+
outputs: AbiOutputsType;
|
75
|
+
functionSelector: string | null;
|
76
|
+
signature: string;
|
77
|
+
defaultOptions: {
|
78
|
+
feeLimit: number;
|
79
|
+
callValue: number;
|
80
|
+
userFeePercentage: number;
|
81
|
+
shouldPollResponse: boolean;
|
82
|
+
};
|
83
|
+
|
84
|
+
constructor(contract: Contract, abi: AbiFragmentNoErrConstructor) {
|
85
|
+
this.tronWeb = contract.tronWeb;
|
86
|
+
this.contract = contract;
|
87
|
+
|
88
|
+
this.abi = abi;
|
89
|
+
this.name = abi.name || abi.type;
|
90
|
+
|
91
|
+
this.inputs = abi.inputs || [];
|
92
|
+
|
93
|
+
this.outputs = [];
|
94
|
+
if ('outputs' in abi && abi.outputs) {
|
95
|
+
this.outputs = abi.outputs;
|
96
|
+
}
|
97
|
+
|
98
|
+
this.functionSelector = getFunctionSelector(abi);
|
99
|
+
this.signature = sha3(this.functionSelector, false).slice(0, 8);
|
100
|
+
|
101
|
+
this.defaultOptions = {
|
102
|
+
feeLimit: this.tronWeb.feeLimit,
|
103
|
+
callValue: 0,
|
104
|
+
userFeePercentage: 100,
|
105
|
+
shouldPollResponse: false, // Only used for sign()
|
106
|
+
};
|
107
|
+
}
|
108
|
+
|
109
|
+
decodeInput(data: string) {
|
110
|
+
const abi = JSON.parse(JSON.stringify(this.abi));
|
111
|
+
abi.outputs = abi.inputs;
|
112
|
+
return decodeOutput(abi, '0x' + data);
|
113
|
+
}
|
114
|
+
|
115
|
+
onMethod(...args: any[]) {
|
116
|
+
let rawParameter = '';
|
117
|
+
if (this.abi && !/event/i.test(this.abi.type)) {
|
118
|
+
rawParameter = encodeParamsV2ByABI(this.abi, args);
|
119
|
+
}
|
120
|
+
return {
|
121
|
+
call: async (options: CallOptions = {}) => {
|
122
|
+
options = {
|
123
|
+
...options,
|
124
|
+
rawParameter,
|
125
|
+
};
|
126
|
+
|
127
|
+
return await this._call([], [], options);
|
128
|
+
},
|
129
|
+
send: async (options: SendOptions = {}, privateKey = this.tronWeb.defaultPrivateKey) => {
|
130
|
+
options = {
|
131
|
+
...options,
|
132
|
+
rawParameter,
|
133
|
+
};
|
134
|
+
|
135
|
+
return await this._send([], [], options, privateKey);
|
136
|
+
},
|
137
|
+
};
|
138
|
+
}
|
139
|
+
|
140
|
+
async _call(types: [], args: [], options: CallOptions = {}) {
|
141
|
+
if (types.length !== args.length) {
|
142
|
+
throw new Error('Invalid argument count provided');
|
143
|
+
}
|
144
|
+
|
145
|
+
if (!this.contract.address) {
|
146
|
+
throw new Error('Smart contract is missing address');
|
147
|
+
}
|
148
|
+
|
149
|
+
if (!this.contract.deployed) {
|
150
|
+
throw new Error('Calling smart contracts requires you to load the contract first');
|
151
|
+
}
|
152
|
+
if ('stateMutability' in this.abi) {
|
153
|
+
const { stateMutability } = this.abi;
|
154
|
+
|
155
|
+
if (stateMutability && !['pure', 'view'].includes(stateMutability.toLowerCase())) {
|
156
|
+
throw new Error(`Methods with state mutability "${stateMutability}" must use send()`);
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
options = {
|
161
|
+
...this.defaultOptions,
|
162
|
+
from: this.tronWeb.defaultAddress.hex,
|
163
|
+
...options,
|
164
|
+
_isConstant: true,
|
165
|
+
};
|
166
|
+
|
167
|
+
const parameters = args.map((value, index) => ({
|
168
|
+
type: types[index],
|
169
|
+
value,
|
170
|
+
}));
|
171
|
+
|
172
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerSmartContract(
|
173
|
+
this.contract.address,
|
174
|
+
this.functionSelector!,
|
175
|
+
options,
|
176
|
+
parameters,
|
177
|
+
options.from ? this.tronWeb.address.toHex(options.from) : undefined
|
178
|
+
);
|
179
|
+
|
180
|
+
if (!utils.hasProperty(transaction, 'constant_result')) {
|
181
|
+
throw new Error('Failed to execute');
|
182
|
+
}
|
183
|
+
|
184
|
+
const len = transaction.constant_result![0].length;
|
185
|
+
if (len === 0 || len % 64 === 8) {
|
186
|
+
let msg = 'The call has been reverted or has thrown an error.';
|
187
|
+
if (len !== 0) {
|
188
|
+
msg += ' Error message: ';
|
189
|
+
let msg2 = '';
|
190
|
+
const chunk = transaction.constant_result![0].substring(8);
|
191
|
+
for (let i = 0; i < len - 8; i += 64) {
|
192
|
+
msg2 += this.tronWeb.toUtf8(chunk.substring(i, i + 64));
|
193
|
+
}
|
194
|
+
msg += msg2
|
195
|
+
.replace(/(\u0000|\u000b|\f)+/g, ' ')
|
196
|
+
.replace(/ +/g, ' ')
|
197
|
+
.replace(/\s+$/g, '');
|
198
|
+
}
|
199
|
+
throw new Error(msg);
|
200
|
+
}
|
201
|
+
|
202
|
+
let output = decodeOutput(this.abi, '0x' + transaction.constant_result![0]);
|
203
|
+
|
204
|
+
if (output.length === 1 && Object.keys(output).length === 1) {
|
205
|
+
output = output[0];
|
206
|
+
}
|
207
|
+
return output;
|
208
|
+
}
|
209
|
+
|
210
|
+
async _send(types: [], args: [], options: SendOptions = {}, privateKey = this.tronWeb.defaultPrivateKey) {
|
211
|
+
if (types.length !== args.length) {
|
212
|
+
throw new Error('Invalid argument count provided');
|
213
|
+
}
|
214
|
+
|
215
|
+
if (!this.contract.address) {
|
216
|
+
throw new Error('Smart contract is missing address');
|
217
|
+
}
|
218
|
+
|
219
|
+
if (!this.contract.deployed) {
|
220
|
+
throw new Error('Calling smart contracts requires you to load the contract first');
|
221
|
+
}
|
222
|
+
|
223
|
+
const { stateMutability } = this.abi as { stateMutability: StateMutabilityTypes };
|
224
|
+
|
225
|
+
if (['pure', 'view'].includes(stateMutability.toLowerCase())) {
|
226
|
+
throw new Error(`Methods with state mutability "${stateMutability}" must use call()`);
|
227
|
+
}
|
228
|
+
|
229
|
+
// If a function isn't payable, dont provide a callValue.
|
230
|
+
if (!['payable'].includes(stateMutability.toLowerCase())) {
|
231
|
+
options.callValue = 0;
|
232
|
+
}
|
233
|
+
|
234
|
+
options = {
|
235
|
+
...this.defaultOptions,
|
236
|
+
from: this.tronWeb.defaultAddress.hex,
|
237
|
+
...options,
|
238
|
+
};
|
239
|
+
|
240
|
+
const parameters = args.map((value, index) => ({
|
241
|
+
type: types[index],
|
242
|
+
value,
|
243
|
+
}));
|
244
|
+
|
245
|
+
const address = privateKey ? this.tronWeb.address.fromPrivateKey(privateKey) : this.tronWeb.defaultAddress.base58;
|
246
|
+
const transaction = await this.tronWeb.transactionBuilder.triggerSmartContract(
|
247
|
+
this.contract.address,
|
248
|
+
this.functionSelector!,
|
249
|
+
options,
|
250
|
+
parameters,
|
251
|
+
this.tronWeb.address.toHex(address as string)
|
252
|
+
);
|
253
|
+
|
254
|
+
if (!transaction.result || !transaction.result.result) {
|
255
|
+
throw new Error('Unknown error: ' + JSON.stringify(transaction, null, 2));
|
256
|
+
}
|
257
|
+
|
258
|
+
// If privateKey is false, this won't be signed here. We assume sign functionality will be replaced.
|
259
|
+
const signedTransaction = await this.tronWeb.trx.sign(transaction.transaction, privateKey);
|
260
|
+
|
261
|
+
if (!signedTransaction.signature) {
|
262
|
+
if (!privateKey) {
|
263
|
+
throw new Error('Transaction was not signed properly');
|
264
|
+
}
|
265
|
+
|
266
|
+
throw new Error('Invalid private key provided');
|
267
|
+
}
|
268
|
+
|
269
|
+
const broadcast = await this.tronWeb.trx.sendRawTransaction(signedTransaction);
|
270
|
+
|
271
|
+
if (broadcast.code) {
|
272
|
+
const err = {
|
273
|
+
error: broadcast.code,
|
274
|
+
message: broadcast.code as unknown as string,
|
275
|
+
};
|
276
|
+
if (broadcast.message) err.message = this.tronWeb.toUtf8(broadcast.message);
|
277
|
+
const error = new Error(err.message);
|
278
|
+
(error as any).error = broadcast.code;
|
279
|
+
throw error;
|
280
|
+
}
|
281
|
+
|
282
|
+
if (!options.shouldPollResponse) {
|
283
|
+
return signedTransaction.txID;
|
284
|
+
}
|
285
|
+
|
286
|
+
const checkResult: (index: number) => any = async (index) => {
|
287
|
+
if (index === (options.pollTimes || 20)) {
|
288
|
+
const error: any = new Error('Cannot find result in solidity node');
|
289
|
+
error.error = 'Cannot find result in solidity node';
|
290
|
+
error.transaction = signedTransaction;
|
291
|
+
throw error;
|
292
|
+
}
|
293
|
+
|
294
|
+
const output = await this.tronWeb.trx.getTransactionInfo(signedTransaction.txID);
|
295
|
+
|
296
|
+
if (!Object.keys(output).length) {
|
297
|
+
await new Promise((r) => setTimeout(r, 3000));
|
298
|
+
return checkResult(index + 1);
|
299
|
+
}
|
300
|
+
|
301
|
+
if (output.result && output.result === 'FAILED') {
|
302
|
+
const error: any = new Error(this.tronWeb.toUtf8(output.resMessage));
|
303
|
+
error.error = this.tronWeb.toUtf8(output.resMessage);
|
304
|
+
error.transaction = signedTransaction;
|
305
|
+
error.output = output;
|
306
|
+
throw error;
|
307
|
+
}
|
308
|
+
|
309
|
+
if (!utils.hasProperty(output, 'contractResult')) {
|
310
|
+
const error: any = new Error('Failed to execute: ' + JSON.stringify(output, null, 2));
|
311
|
+
error.error = 'Failed to execute: ' + JSON.stringify(output, null, 2);
|
312
|
+
error.transaction = signedTransaction;
|
313
|
+
error.output = output;
|
314
|
+
throw error;
|
315
|
+
}
|
316
|
+
|
317
|
+
if (options.rawResponse) {
|
318
|
+
return output;
|
319
|
+
}
|
320
|
+
|
321
|
+
let decoded = decodeOutput(this.abi, '0x' + output.contractResult[0]);
|
322
|
+
|
323
|
+
if (decoded.length === 1 && Object.keys(decoded).length === 1) {
|
324
|
+
decoded = decoded[0];
|
325
|
+
}
|
326
|
+
|
327
|
+
if (options.keepTxID) {
|
328
|
+
return [signedTransaction.txID, decoded];
|
329
|
+
}
|
330
|
+
|
331
|
+
return decoded;
|
332
|
+
};
|
333
|
+
|
334
|
+
return checkResult(0);
|
335
|
+
}
|
336
|
+
}
|