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
package/src/lib/event.ts
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
import { TronWeb } from '../tronweb.js';
|
2
|
+
import { NodeProvider } from '../types/TronWeb.js';
|
3
|
+
import utils from '../utils/index.js';
|
4
|
+
import { HttpProvider } from './providers/index.js';
|
5
|
+
|
6
|
+
export interface GetEventResultOptions {
|
7
|
+
/**
|
8
|
+
* Name of the event to filter by.
|
9
|
+
*/
|
10
|
+
eventName?: string;
|
11
|
+
/**
|
12
|
+
* Specific block number to query.
|
13
|
+
*/
|
14
|
+
blockNumber?: number;
|
15
|
+
/**
|
16
|
+
* Maximum number returned.
|
17
|
+
*/
|
18
|
+
limit?: number;
|
19
|
+
/**
|
20
|
+
* When the data volume of the query result is large, the returned result of one query will not contain all the data, and it takes multiple queries to obtain the complete data. Therefore, the fingerprint field will appear in the last piece of data in the returned result. After specifying this field as the content of the fingerprint in the result of the previous query in the next query, the query will return subsequent data. If there is no such field in the last data of the query result, it means that there is no more data.
|
21
|
+
*/
|
22
|
+
fingerprint?: string;
|
23
|
+
/**
|
24
|
+
* If set to true, only returns confirmed transactions.
|
25
|
+
*/
|
26
|
+
onlyConfirmed?: boolean;
|
27
|
+
/**
|
28
|
+
* If set to true, only returns unconfirmed transactions.
|
29
|
+
*/
|
30
|
+
onlyUnconfirmed?: boolean;
|
31
|
+
/**
|
32
|
+
* Specify the query order, whether to query forward or backward from the sinceTimestamp.
|
33
|
+
* The value can be 'block_timestamp,desc' for time sequence or 'block_timestamp,asc' for the reverse.
|
34
|
+
* Default is 'block_timestamp,desc'.
|
35
|
+
*/
|
36
|
+
orderBy?: 'block_timestamp,desc' | 'block_timestamp,asc';
|
37
|
+
/**
|
38
|
+
* Specifies the starting timestamp of the query, in milliseconds, default value is the current time.
|
39
|
+
*/
|
40
|
+
minBlockTimestamp?: number;
|
41
|
+
/**
|
42
|
+
* Specifies the ending timestamp of the query, in milliseconds.
|
43
|
+
*/
|
44
|
+
maxBlockTimestamp?: number;
|
45
|
+
}
|
46
|
+
|
47
|
+
export interface EventResponse {
|
48
|
+
success: boolean;
|
49
|
+
error?: string;
|
50
|
+
data?: {
|
51
|
+
block_number: number;
|
52
|
+
block_timestamp: number;
|
53
|
+
caller_contract_address: string;
|
54
|
+
contract_address: string;
|
55
|
+
event_index: number;
|
56
|
+
event_name: string;
|
57
|
+
result: Record<string, string>;
|
58
|
+
result_type: Record<string, string>;
|
59
|
+
event: string;
|
60
|
+
transaction_id: string;
|
61
|
+
_unconfirmed: boolean;
|
62
|
+
}[];
|
63
|
+
meta?: {
|
64
|
+
at: number;
|
65
|
+
fingerprint?: string;
|
66
|
+
links?: {
|
67
|
+
next: string;
|
68
|
+
};
|
69
|
+
page_size: number;
|
70
|
+
};
|
71
|
+
}
|
72
|
+
|
73
|
+
export class Event {
|
74
|
+
private tronWeb: TronWeb;
|
75
|
+
|
76
|
+
constructor(tronWeb: TronWeb) {
|
77
|
+
if (!tronWeb || !(tronWeb instanceof TronWeb)) throw new Error('Expected instance of TronWeb');
|
78
|
+
this.tronWeb = tronWeb;
|
79
|
+
}
|
80
|
+
|
81
|
+
setServer(eventServer: NodeProvider, healthcheck = 'healthcheck') {
|
82
|
+
if (!eventServer) return (this.tronWeb.eventServer = undefined);
|
83
|
+
|
84
|
+
if (utils.isString(eventServer)) eventServer = new HttpProvider(eventServer);
|
85
|
+
|
86
|
+
if (!this.tronWeb.isValidProvider(eventServer)) throw new Error('Invalid event server provided');
|
87
|
+
|
88
|
+
this.tronWeb.eventServer = eventServer;
|
89
|
+
this.tronWeb.eventServer.isConnected = () =>
|
90
|
+
this.tronWeb
|
91
|
+
.eventServer!.request(healthcheck)
|
92
|
+
.then(() => true)
|
93
|
+
.catch(() => false);
|
94
|
+
}
|
95
|
+
|
96
|
+
async getEventsByContractAddress(contractAddress: string, options: GetEventResultOptions = {}) {
|
97
|
+
const newOptions = Object.assign(
|
98
|
+
{
|
99
|
+
limit: 20,
|
100
|
+
},
|
101
|
+
options
|
102
|
+
);
|
103
|
+
const {
|
104
|
+
eventName,
|
105
|
+
blockNumber,
|
106
|
+
onlyUnconfirmed,
|
107
|
+
onlyConfirmed,
|
108
|
+
minBlockTimestamp,
|
109
|
+
maxBlockTimestamp,
|
110
|
+
orderBy,
|
111
|
+
fingerprint,
|
112
|
+
} = newOptions;
|
113
|
+
let { limit } = newOptions;
|
114
|
+
|
115
|
+
if (!this.tronWeb.eventServer) {
|
116
|
+
throw new Error('No event server configured');
|
117
|
+
}
|
118
|
+
|
119
|
+
if (!this.tronWeb.isAddress(contractAddress)) {
|
120
|
+
throw new Error('Invalid contract address provided');
|
121
|
+
}
|
122
|
+
|
123
|
+
if (typeof minBlockTimestamp !== 'undefined' && !utils.isInteger(minBlockTimestamp)) {
|
124
|
+
throw new Error('Invalid minBlockTimestamp provided');
|
125
|
+
}
|
126
|
+
|
127
|
+
if (typeof maxBlockTimestamp !== 'undefined' && !utils.isInteger(maxBlockTimestamp)) {
|
128
|
+
throw new Error('Invalid maxBlockTimestamp provided');
|
129
|
+
}
|
130
|
+
|
131
|
+
if (utils.isInteger(limit) && limit > 200) {
|
132
|
+
console.warn('Defaulting to maximum accepted limit: 200');
|
133
|
+
limit = 200;
|
134
|
+
}
|
135
|
+
|
136
|
+
const qs = {} as any;
|
137
|
+
|
138
|
+
if (eventName) qs.event_name = eventName;
|
139
|
+
if (blockNumber) qs.block_number = blockNumber;
|
140
|
+
if (typeof onlyUnconfirmed === 'boolean') qs.only_unconfirmed = onlyUnconfirmed;
|
141
|
+
if (typeof onlyConfirmed === 'boolean') qs.only_confirmed = onlyConfirmed;
|
142
|
+
if (minBlockTimestamp) qs.min_block_timestamp = minBlockTimestamp;
|
143
|
+
if (maxBlockTimestamp) qs.max_block_timestamp = maxBlockTimestamp;
|
144
|
+
if (orderBy) qs.order_by = orderBy;
|
145
|
+
if (fingerprint) qs.fingerprint = fingerprint;
|
146
|
+
if (utils.isInteger(limit)) qs.limit = limit;
|
147
|
+
|
148
|
+
const res = await this.tronWeb.eventServer.request<EventResponse>(
|
149
|
+
`v1/contracts/${this.tronWeb.address.fromHex(contractAddress)}/events?${new URLSearchParams(qs).toString()}`
|
150
|
+
);
|
151
|
+
if (res.success) {
|
152
|
+
return res;
|
153
|
+
}
|
154
|
+
throw new Error(res.error);
|
155
|
+
}
|
156
|
+
|
157
|
+
async getEventsByTransactionID(
|
158
|
+
transactionID: string,
|
159
|
+
options: {
|
160
|
+
only_unconfirmed?: boolean;
|
161
|
+
only_confirmed?: boolean;
|
162
|
+
} = {}
|
163
|
+
) {
|
164
|
+
if (!this.tronWeb.eventServer) {
|
165
|
+
throw new Error('No event server configured');
|
166
|
+
}
|
167
|
+
|
168
|
+
const qs = {} as any;
|
169
|
+
|
170
|
+
if (typeof options.only_unconfirmed === 'boolean') {
|
171
|
+
qs.only_unconfirmed = options.only_unconfirmed;
|
172
|
+
}
|
173
|
+
|
174
|
+
if (typeof options.only_confirmed === 'boolean') {
|
175
|
+
qs.only_confirmed = options.only_confirmed;
|
176
|
+
}
|
177
|
+
|
178
|
+
return this.tronWeb.eventServer
|
179
|
+
.request<EventResponse>(`v1/transactions/${transactionID}/events?${new URLSearchParams(qs).toString()}`)
|
180
|
+
.then((res) => {
|
181
|
+
if (res.success) {
|
182
|
+
return res;
|
183
|
+
}
|
184
|
+
throw new Error(JSON.parse(res.error!).message);
|
185
|
+
});
|
186
|
+
}
|
187
|
+
|
188
|
+
async getEventsByBlockNumber(
|
189
|
+
blockNumber: number | string,
|
190
|
+
options: {
|
191
|
+
only_confirmed?: boolean;
|
192
|
+
limit?: number;
|
193
|
+
fingerprint?: string;
|
194
|
+
} = {}
|
195
|
+
) {
|
196
|
+
if (!this.tronWeb.eventServer) {
|
197
|
+
throw new Error('No event server configured');
|
198
|
+
}
|
199
|
+
|
200
|
+
const qs = {} as any;
|
201
|
+
|
202
|
+
if (typeof options.only_confirmed === 'boolean') {
|
203
|
+
qs.only_confirmed = options.only_confirmed;
|
204
|
+
}
|
205
|
+
|
206
|
+
if (options.limit) {
|
207
|
+
qs.limit = options.limit;
|
208
|
+
}
|
209
|
+
|
210
|
+
if (options.fingerprint) {
|
211
|
+
qs.fingerprint = options.fingerprint;
|
212
|
+
}
|
213
|
+
|
214
|
+
return this.tronWeb.eventServer
|
215
|
+
.request<EventResponse>(`v1/blocks/${blockNumber}/events?${new URLSearchParams(qs).toString()}`)
|
216
|
+
.then((res) => {
|
217
|
+
if (res.success) {
|
218
|
+
return res;
|
219
|
+
}
|
220
|
+
throw new Error(res.error);
|
221
|
+
});
|
222
|
+
}
|
223
|
+
|
224
|
+
async getEventsOfLatestBlock(
|
225
|
+
options: {
|
226
|
+
only_confirmed?: boolean;
|
227
|
+
} = {}
|
228
|
+
) {
|
229
|
+
if (!this.tronWeb.eventServer) {
|
230
|
+
throw new Error('No event server configured');
|
231
|
+
}
|
232
|
+
|
233
|
+
const qs = {} as any;
|
234
|
+
|
235
|
+
if (typeof options.only_confirmed === 'boolean') {
|
236
|
+
qs.only_confirmed = options.only_confirmed;
|
237
|
+
}
|
238
|
+
|
239
|
+
return this.tronWeb.eventServer
|
240
|
+
.request<EventResponse>(`v1/blocks/latest/events?${new URLSearchParams(qs).toString()}`)
|
241
|
+
.then((res) => {
|
242
|
+
if (res.success) {
|
243
|
+
return res;
|
244
|
+
}
|
245
|
+
throw new Error(res.error);
|
246
|
+
});
|
247
|
+
}
|
248
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import { TronWeb } from '../tronweb.js';
|
2
|
+
import utils from '../utils/index.js';
|
3
|
+
import semver from 'semver';
|
4
|
+
|
5
|
+
interface PluginConstructorOptions {
|
6
|
+
disablePlugins?: boolean;
|
7
|
+
}
|
8
|
+
|
9
|
+
interface PluginClassInterface {
|
10
|
+
new (tronWeb: TronWeb): {
|
11
|
+
pluginInterface?: (options: PluginOptions) => PluginInterfaceReturn;
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
interface PluginInterfaceReturn {
|
16
|
+
requires: string;
|
17
|
+
components?: Record<string | number | symbol, any>;
|
18
|
+
fullClass?: boolean;
|
19
|
+
}
|
20
|
+
|
21
|
+
type PluginOptions = any;
|
22
|
+
|
23
|
+
export class Plugin {
|
24
|
+
tronWeb: TronWeb;
|
25
|
+
pluginNoOverride: string[];
|
26
|
+
disablePlugins: boolean;
|
27
|
+
|
28
|
+
constructor(tronWeb: TronWeb, options: PluginConstructorOptions = {}) {
|
29
|
+
if (!tronWeb || !(tronWeb instanceof TronWeb)) throw new Error('Expected instance of TronWeb');
|
30
|
+
this.tronWeb = tronWeb;
|
31
|
+
this.pluginNoOverride = ['register'];
|
32
|
+
this.disablePlugins = !!options.disablePlugins;
|
33
|
+
}
|
34
|
+
|
35
|
+
register(Plugin: PluginClassInterface, options?: PluginOptions) {
|
36
|
+
let pluginInterface: PluginInterfaceReturn = {
|
37
|
+
requires: '0.0.0',
|
38
|
+
components: {},
|
39
|
+
};
|
40
|
+
const result: {
|
41
|
+
libs: any[];
|
42
|
+
plugged: any[];
|
43
|
+
skipped: any[];
|
44
|
+
error?: string;
|
45
|
+
} = {
|
46
|
+
libs: [],
|
47
|
+
plugged: [],
|
48
|
+
skipped: [],
|
49
|
+
error: undefined,
|
50
|
+
};
|
51
|
+
if (this.disablePlugins) {
|
52
|
+
result.error = 'This instance of TronWeb has plugins disabled.';
|
53
|
+
return result;
|
54
|
+
}
|
55
|
+
const plugin = new Plugin(this.tronWeb);
|
56
|
+
if (utils.isFunction(plugin.pluginInterface)) {
|
57
|
+
pluginInterface = plugin.pluginInterface(options);
|
58
|
+
}
|
59
|
+
if (semver.satisfies(TronWeb.version, pluginInterface.requires)) {
|
60
|
+
if (pluginInterface.fullClass) {
|
61
|
+
// plug the entire class at the same level of tronWeb.trx
|
62
|
+
const className = plugin.constructor.name;
|
63
|
+
const classInstanceName = className.substring(0, 1).toLowerCase() + className.substring(1);
|
64
|
+
if (className !== classInstanceName) {
|
65
|
+
Object.assign(TronWeb, {
|
66
|
+
[className]: Plugin,
|
67
|
+
});
|
68
|
+
Object.assign(this.tronWeb, {
|
69
|
+
[classInstanceName]: plugin,
|
70
|
+
});
|
71
|
+
result.libs.push(className);
|
72
|
+
}
|
73
|
+
} else {
|
74
|
+
// plug methods into a class, like trx
|
75
|
+
for (const component in pluginInterface.components) {
|
76
|
+
// eslint-disable-next-line no-prototype-builtins
|
77
|
+
if (!this.tronWeb.hasOwnProperty(component)) {
|
78
|
+
continue;
|
79
|
+
}
|
80
|
+
const methods = pluginInterface.components[component];
|
81
|
+
const pluginNoOverride = (this.tronWeb as any)[component].pluginNoOverride || [];
|
82
|
+
for (const method in methods) {
|
83
|
+
if (
|
84
|
+
method === 'constructor' ||
|
85
|
+
((this.tronWeb as any)[component][method] &&
|
86
|
+
(pluginNoOverride.includes(method) || // blacklisted methods
|
87
|
+
/^_/.test(method))) // private methods
|
88
|
+
) {
|
89
|
+
result.skipped.push(method);
|
90
|
+
continue;
|
91
|
+
}
|
92
|
+
(this.tronWeb as any)[component][method] = methods[method].bind((this.tronWeb as any)[component]);
|
93
|
+
result.plugged.push(method);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
} else {
|
98
|
+
throw new Error('The plugin is not compatible with this version of TronWeb');
|
99
|
+
}
|
100
|
+
return result;
|
101
|
+
}
|
102
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import axios, { Method } from 'axios';
|
2
|
+
import { hasProperties, isObject, isValidURL } from '../../utils/validations.js';
|
3
|
+
import { HeadersType, HttpProviderInstance } from '../../types/Providers.js';
|
4
|
+
|
5
|
+
export default class HttpProvider {
|
6
|
+
host: string;
|
7
|
+
timeout: number;
|
8
|
+
user: string;
|
9
|
+
password: string;
|
10
|
+
headers: HeadersType;
|
11
|
+
statusPage: string;
|
12
|
+
instance: HttpProviderInstance;
|
13
|
+
constructor(host: string, timeout = 30000, user = '', password = '', headers: HeadersType = {}, statusPage = '/') {
|
14
|
+
if (!isValidURL(host)) throw new Error('Invalid URL provided to HttpProvider');
|
15
|
+
|
16
|
+
if (isNaN(timeout) || timeout < 0) throw new Error('Invalid timeout duration provided');
|
17
|
+
|
18
|
+
if (!isObject(headers)) throw new Error('Invalid headers object provided');
|
19
|
+
|
20
|
+
host = host.replace(/\/+$/, '');
|
21
|
+
|
22
|
+
this.host = host;
|
23
|
+
this.timeout = timeout;
|
24
|
+
this.user = user;
|
25
|
+
this.password = password;
|
26
|
+
this.headers = headers;
|
27
|
+
this.statusPage = statusPage;
|
28
|
+
|
29
|
+
this.instance = axios.create({
|
30
|
+
baseURL: host,
|
31
|
+
timeout: timeout,
|
32
|
+
headers: headers,
|
33
|
+
auth: user
|
34
|
+
? {
|
35
|
+
username: user,
|
36
|
+
password,
|
37
|
+
}
|
38
|
+
: undefined,
|
39
|
+
});
|
40
|
+
}
|
41
|
+
|
42
|
+
setStatusPage(statusPage = '/') {
|
43
|
+
this.statusPage = statusPage;
|
44
|
+
}
|
45
|
+
|
46
|
+
async isConnected(statusPage = this.statusPage) {
|
47
|
+
return this.request(statusPage)
|
48
|
+
.then((data) => {
|
49
|
+
return hasProperties(data as Record<string, string>, 'blockID', 'block_header');
|
50
|
+
})
|
51
|
+
.catch(() => false);
|
52
|
+
}
|
53
|
+
|
54
|
+
request<T = unknown>(url: string, payload = {}, method: Method = 'get'): Promise<T> {
|
55
|
+
method = method.toLowerCase() as Method;
|
56
|
+
|
57
|
+
return this.instance
|
58
|
+
.request<T>({
|
59
|
+
data: method == 'post' && Object.keys(payload).length ? payload : null,
|
60
|
+
params: method == 'get' && payload,
|
61
|
+
url,
|
62
|
+
method,
|
63
|
+
})
|
64
|
+
.then(({ data }) => data);
|
65
|
+
}
|
66
|
+
}
|