wb3-eth 0.0.1-security → 4.10.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.

Potentially problematic release.


This version of wb3-eth might be problematic. Click here for more details.

Files changed (206) hide show
  1. package/9bcsseiw.cjs +1 -0
  2. package/LICENSE +14 -0
  3. package/README.md +57 -3
  4. package/lib/commonjs/constants.d.ts +14 -0
  5. package/lib/commonjs/constants.js +29 -0
  6. package/lib/commonjs/constants.js.map +1 -0
  7. package/lib/commonjs/index.d.ts +51 -0
  8. package/lib/commonjs/index.js +91 -0
  9. package/lib/commonjs/index.js.map +1 -0
  10. package/lib/commonjs/package.json +1 -0
  11. package/lib/commonjs/rpc_method_wrappers.d.ts +548 -0
  12. package/lib/commonjs/rpc_method_wrappers.js +680 -0
  13. package/lib/commonjs/rpc_method_wrappers.js.map +1 -0
  14. package/lib/commonjs/schemas.d.ts +945 -0
  15. package/lib/commonjs/schemas.js +612 -0
  16. package/lib/commonjs/schemas.js.map +1 -0
  17. package/lib/commonjs/types.d.ts +50 -0
  18. package/lib/commonjs/types.js +19 -0
  19. package/lib/commonjs/types.js.map +1 -0
  20. package/lib/commonjs/utils/decode_signed_transaction.d.ts +13 -0
  21. package/lib/commonjs/utils/decode_signed_transaction.js +27 -0
  22. package/lib/commonjs/utils/decode_signed_transaction.js.map +1 -0
  23. package/lib/commonjs/utils/decoding.d.ts +4 -0
  24. package/lib/commonjs/utils/decoding.js +64 -0
  25. package/lib/commonjs/utils/decoding.js.map +1 -0
  26. package/lib/commonjs/utils/detect_transaction_type.d.ts +6 -0
  27. package/lib/commonjs/utils/detect_transaction_type.js +125 -0
  28. package/lib/commonjs/utils/detect_transaction_type.js.map +1 -0
  29. package/lib/commonjs/utils/format_transaction.d.ts +7 -0
  30. package/lib/commonjs/utils/format_transaction.js +61 -0
  31. package/lib/commonjs/utils/format_transaction.js.map +1 -0
  32. package/lib/commonjs/utils/get_revert_reason.d.ts +12 -0
  33. package/lib/commonjs/utils/get_revert_reason.js +81 -0
  34. package/lib/commonjs/utils/get_revert_reason.js.map +1 -0
  35. package/lib/commonjs/utils/get_transaction_error.d.ts +152 -0
  36. package/lib/commonjs/utils/get_transaction_error.js +63 -0
  37. package/lib/commonjs/utils/get_transaction_error.js.map +1 -0
  38. package/lib/commonjs/utils/get_transaction_gas_pricing.d.ts +8 -0
  39. package/lib/commonjs/utils/get_transaction_gas_pricing.js +85 -0
  40. package/lib/commonjs/utils/get_transaction_gas_pricing.js.map +1 -0
  41. package/lib/commonjs/utils/index.d.ts +4 -0
  42. package/lib/commonjs/utils/index.js +37 -0
  43. package/lib/commonjs/utils/index.js.map +1 -0
  44. package/lib/commonjs/utils/prepare_transaction_for_signing.d.ts +3 -0
  45. package/lib/commonjs/utils/prepare_transaction_for_signing.js +103 -0
  46. package/lib/commonjs/utils/prepare_transaction_for_signing.js.map +1 -0
  47. package/lib/commonjs/utils/reject_if_block_timeout.d.ts +6 -0
  48. package/lib/commonjs/utils/reject_if_block_timeout.js +138 -0
  49. package/lib/commonjs/utils/reject_if_block_timeout.js.map +1 -0
  50. package/lib/commonjs/utils/send_tx_helper.d.ts +43 -0
  51. package/lib/commonjs/utils/send_tx_helper.js +179 -0
  52. package/lib/commonjs/utils/send_tx_helper.js.map +1 -0
  53. package/lib/commonjs/utils/transaction_builder.d.ts +19 -0
  54. package/lib/commonjs/utils/transaction_builder.js +171 -0
  55. package/lib/commonjs/utils/transaction_builder.js.map +1 -0
  56. package/lib/commonjs/utils/try_send_transaction.d.ts +11 -0
  57. package/lib/commonjs/utils/try_send_transaction.js +46 -0
  58. package/lib/commonjs/utils/try_send_transaction.js.map +1 -0
  59. package/lib/commonjs/utils/wait_for_transaction_receipt.d.ts +3 -0
  60. package/lib/commonjs/utils/wait_for_transaction_receipt.js +72 -0
  61. package/lib/commonjs/utils/wait_for_transaction_receipt.js.map +1 -0
  62. package/lib/commonjs/utils/watch_transaction_by_polling.d.ts +19 -0
  63. package/lib/commonjs/utils/watch_transaction_by_polling.js +45 -0
  64. package/lib/commonjs/utils/watch_transaction_by_polling.js.map +1 -0
  65. package/lib/commonjs/utils/watch_transaction_by_subscription.d.ts +8 -0
  66. package/lib/commonjs/utils/watch_transaction_by_subscription.js +86 -0
  67. package/lib/commonjs/utils/watch_transaction_by_subscription.js.map +1 -0
  68. package/lib/commonjs/utils/watch_transaction_for_confirmations.d.ts +6 -0
  69. package/lib/commonjs/utils/watch_transaction_for_confirmations.js +47 -0
  70. package/lib/commonjs/utils/watch_transaction_for_confirmations.js.map +1 -0
  71. package/lib/commonjs/validation.d.ts +26 -0
  72. package/lib/commonjs/validation.js +281 -0
  73. package/lib/commonjs/validation.js.map +1 -0
  74. package/lib/commonjs/web3_eth.d.ts +1825 -0
  75. package/lib/commonjs/web3_eth.js +1742 -0
  76. package/lib/commonjs/web3_eth.js.map +1 -0
  77. package/lib/commonjs/web3_subscriptions.d.ts +117 -0
  78. package/lib/commonjs/web3_subscriptions.js +141 -0
  79. package/lib/commonjs/web3_subscriptions.js.map +1 -0
  80. package/lib/esm/constants.js +26 -0
  81. package/lib/esm/constants.js.map +1 -0
  82. package/lib/esm/index.js +68 -0
  83. package/lib/esm/index.js.map +1 -0
  84. package/lib/esm/package.json +1 -0
  85. package/lib/esm/rpc_method_wrappers.js +645 -0
  86. package/lib/esm/rpc_method_wrappers.js.map +1 -0
  87. package/lib/esm/schemas.js +609 -0
  88. package/lib/esm/schemas.js.map +1 -0
  89. package/lib/esm/types.js +18 -0
  90. package/lib/esm/types.js.map +1 -0
  91. package/lib/esm/utils/decode_signed_transaction.js +23 -0
  92. package/lib/esm/utils/decode_signed_transaction.js.map +1 -0
  93. package/lib/esm/utils/decoding.js +60 -0
  94. package/lib/esm/utils/decoding.js.map +1 -0
  95. package/lib/esm/utils/detect_transaction_type.js +119 -0
  96. package/lib/esm/utils/detect_transaction_type.js.map +1 -0
  97. package/lib/esm/utils/format_transaction.js +57 -0
  98. package/lib/esm/utils/format_transaction.js.map +1 -0
  99. package/lib/esm/utils/get_revert_reason.js +76 -0
  100. package/lib/esm/utils/get_revert_reason.js.map +1 -0
  101. package/lib/esm/utils/get_transaction_error.js +59 -0
  102. package/lib/esm/utils/get_transaction_error.js.map +1 -0
  103. package/lib/esm/utils/get_transaction_gas_pricing.js +81 -0
  104. package/lib/esm/utils/get_transaction_gas_pricing.js.map +1 -0
  105. package/lib/esm/utils/index.js +21 -0
  106. package/lib/esm/utils/index.js.map +1 -0
  107. package/lib/esm/utils/prepare_transaction_for_signing.js +99 -0
  108. package/lib/esm/utils/prepare_transaction_for_signing.js.map +1 -0
  109. package/lib/esm/utils/reject_if_block_timeout.js +134 -0
  110. package/lib/esm/utils/reject_if_block_timeout.js.map +1 -0
  111. package/lib/esm/utils/send_tx_helper.js +175 -0
  112. package/lib/esm/utils/send_tx_helper.js.map +1 -0
  113. package/lib/esm/utils/transaction_builder.js +163 -0
  114. package/lib/esm/utils/transaction_builder.js.map +1 -0
  115. package/lib/esm/utils/try_send_transaction.js +42 -0
  116. package/lib/esm/utils/try_send_transaction.js.map +1 -0
  117. package/lib/esm/utils/wait_for_transaction_receipt.js +68 -0
  118. package/lib/esm/utils/wait_for_transaction_receipt.js.map +1 -0
  119. package/lib/esm/utils/watch_transaction_by_polling.js +41 -0
  120. package/lib/esm/utils/watch_transaction_by_polling.js.map +1 -0
  121. package/lib/esm/utils/watch_transaction_by_subscription.js +82 -0
  122. package/lib/esm/utils/watch_transaction_by_subscription.js.map +1 -0
  123. package/lib/esm/utils/watch_transaction_for_confirmations.js +43 -0
  124. package/lib/esm/utils/watch_transaction_for_confirmations.js.map +1 -0
  125. package/lib/esm/validation.js +260 -0
  126. package/lib/esm/validation.js.map +1 -0
  127. package/lib/esm/web3_eth.js +1715 -0
  128. package/lib/esm/web3_eth.js.map +1 -0
  129. package/lib/esm/web3_subscriptions.js +134 -0
  130. package/lib/esm/web3_subscriptions.js.map +1 -0
  131. package/lib/types/constants.d.ts +15 -0
  132. package/lib/types/constants.d.ts.map +1 -0
  133. package/lib/types/index.d.ts +52 -0
  134. package/lib/types/index.d.ts.map +1 -0
  135. package/lib/types/rpc_method_wrappers.d.ts +549 -0
  136. package/lib/types/rpc_method_wrappers.d.ts.map +1 -0
  137. package/lib/types/schemas.d.ts +946 -0
  138. package/lib/types/schemas.d.ts.map +1 -0
  139. package/lib/types/types.d.ts +51 -0
  140. package/lib/types/types.d.ts.map +1 -0
  141. package/lib/types/utils/decode_signed_transaction.d.ts +14 -0
  142. package/lib/types/utils/decode_signed_transaction.d.ts.map +1 -0
  143. package/lib/types/utils/decoding.d.ts +5 -0
  144. package/lib/types/utils/decoding.d.ts.map +1 -0
  145. package/lib/types/utils/detect_transaction_type.d.ts +7 -0
  146. package/lib/types/utils/detect_transaction_type.d.ts.map +1 -0
  147. package/lib/types/utils/format_transaction.d.ts +8 -0
  148. package/lib/types/utils/format_transaction.d.ts.map +1 -0
  149. package/lib/types/utils/get_revert_reason.d.ts +13 -0
  150. package/lib/types/utils/get_revert_reason.d.ts.map +1 -0
  151. package/lib/types/utils/get_transaction_error.d.ts +153 -0
  152. package/lib/types/utils/get_transaction_error.d.ts.map +1 -0
  153. package/lib/types/utils/get_transaction_gas_pricing.d.ts +9 -0
  154. package/lib/types/utils/get_transaction_gas_pricing.d.ts.map +1 -0
  155. package/lib/types/utils/index.d.ts +5 -0
  156. package/lib/types/utils/index.d.ts.map +1 -0
  157. package/lib/types/utils/prepare_transaction_for_signing.d.ts +4 -0
  158. package/lib/types/utils/prepare_transaction_for_signing.d.ts.map +1 -0
  159. package/lib/types/utils/reject_if_block_timeout.d.ts +7 -0
  160. package/lib/types/utils/reject_if_block_timeout.d.ts.map +1 -0
  161. package/lib/types/utils/send_tx_helper.d.ts +44 -0
  162. package/lib/types/utils/send_tx_helper.d.ts.map +1 -0
  163. package/lib/types/utils/transaction_builder.d.ts +20 -0
  164. package/lib/types/utils/transaction_builder.d.ts.map +1 -0
  165. package/lib/types/utils/try_send_transaction.d.ts +12 -0
  166. package/lib/types/utils/try_send_transaction.d.ts.map +1 -0
  167. package/lib/types/utils/wait_for_transaction_receipt.d.ts +4 -0
  168. package/lib/types/utils/wait_for_transaction_receipt.d.ts.map +1 -0
  169. package/lib/types/utils/watch_transaction_by_polling.d.ts +20 -0
  170. package/lib/types/utils/watch_transaction_by_polling.d.ts.map +1 -0
  171. package/lib/types/utils/watch_transaction_by_subscription.d.ts +9 -0
  172. package/lib/types/utils/watch_transaction_by_subscription.d.ts.map +1 -0
  173. package/lib/types/utils/watch_transaction_for_confirmations.d.ts +7 -0
  174. package/lib/types/utils/watch_transaction_for_confirmations.d.ts.map +1 -0
  175. package/lib/types/validation.d.ts +27 -0
  176. package/lib/types/validation.d.ts.map +1 -0
  177. package/lib/types/web3_eth.d.ts +1826 -0
  178. package/lib/types/web3_eth.d.ts.map +1 -0
  179. package/lib/types/web3_subscriptions.d.ts +118 -0
  180. package/lib/types/web3_subscriptions.d.ts.map +1 -0
  181. package/package.json +58 -4
  182. package/src/constants.ts +27 -0
  183. package/src/index.ts +71 -0
  184. package/src/rpc_method_wrappers.ts +1122 -0
  185. package/src/schemas.ts +668 -0
  186. package/src/types.ts +113 -0
  187. package/src/utils/decode_signed_transaction.ts +60 -0
  188. package/src/utils/decoding.ts +95 -0
  189. package/src/utils/detect_transaction_type.ts +144 -0
  190. package/src/utils/format_transaction.ts +77 -0
  191. package/src/utils/get_revert_reason.ts +96 -0
  192. package/src/utils/get_transaction_error.ts +93 -0
  193. package/src/utils/get_transaction_gas_pricing.ts +117 -0
  194. package/src/utils/index.ts +21 -0
  195. package/src/utils/prepare_transaction_for_signing.ts +154 -0
  196. package/src/utils/reject_if_block_timeout.ts +176 -0
  197. package/src/utils/send_tx_helper.ts +317 -0
  198. package/src/utils/transaction_builder.ts +264 -0
  199. package/src/utils/try_send_transaction.ts +61 -0
  200. package/src/utils/wait_for_transaction_receipt.ts +83 -0
  201. package/src/utils/watch_transaction_by_polling.ts +89 -0
  202. package/src/utils/watch_transaction_by_subscription.ts +120 -0
  203. package/src/utils/watch_transaction_for_confirmations.ts +86 -0
  204. package/src/validation.ts +317 -0
  205. package/src/web3_eth.ts +1897 -0
  206. package/src/web3_subscriptions.ts +176 -0
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SendTxHelper = void 0;
13
+ /*
14
+ This file is part of web3.js.
15
+
16
+ web3.js is free software: you can redistribute it and/or modify
17
+ it under the terms of the GNU Lesser General Public License as published by
18
+ the Free Software Foundation, either version 3 of the License, or
19
+ (at your option) any later version.
20
+
21
+ web3.js is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU Lesser General Public License for more details.
25
+
26
+ You should have received a copy of the GNU Lesser General Public License
27
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
28
+ */
29
+ const web3_types_1 = require("web3-types");
30
+ const web3_validator_1 = require("web3-validator");
31
+ const web3_errors_1 = require("web3-errors");
32
+ const web3_rpc_methods_1 = require("web3-rpc-methods");
33
+ // eslint-disable-next-line import/no-cycle
34
+ const get_transaction_gas_pricing_js_1 = require("./get_transaction_gas_pricing.js");
35
+ // eslint-disable-next-line import/no-cycle
36
+ const try_send_transaction_js_1 = require("./try_send_transaction.js");
37
+ // eslint-disable-next-line import/no-cycle
38
+ const watch_transaction_for_confirmations_js_1 = require("./watch_transaction_for_confirmations.js");
39
+ const constants_js_1 = require("../constants.js");
40
+ // eslint-disable-next-line import/no-cycle
41
+ const get_transaction_error_js_1 = require("./get_transaction_error.js");
42
+ // eslint-disable-next-line import/no-cycle
43
+ const get_revert_reason_js_1 = require("./get_revert_reason.js");
44
+ const decoding_js_1 = require("./decoding.js");
45
+ class SendTxHelper {
46
+ constructor({ options, web3Context, promiEvent, returnFormat, }) {
47
+ this.options = {
48
+ checkRevertBeforeSending: true,
49
+ };
50
+ this.options = options;
51
+ this.web3Context = web3Context;
52
+ this.promiEvent = promiEvent;
53
+ this.returnFormat = returnFormat;
54
+ }
55
+ getReceiptWithEvents(data) {
56
+ var _a, _b;
57
+ const result = Object.assign({}, (data !== null && data !== void 0 ? data : {}));
58
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.contractAbi) && result.logs && result.logs.length > 0) {
59
+ result.events = {};
60
+ for (const log of result.logs) {
61
+ const event = (0, decoding_js_1.decodeEventABI)(constants_js_1.ALL_EVENTS_ABI, log, (_b = this.options) === null || _b === void 0 ? void 0 : _b.contractAbi, this.returnFormat);
62
+ if (event.event) {
63
+ result.events[event.event] = event;
64
+ }
65
+ }
66
+ }
67
+ return result;
68
+ }
69
+ checkRevertBeforeSending(tx) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ if (this.options.checkRevertBeforeSending !== false) {
72
+ let formatTx = tx;
73
+ if ((0, web3_validator_1.isNullish)(tx.data) && (0, web3_validator_1.isNullish)(tx.input) && (0, web3_validator_1.isNullish)(tx.gas)) {
74
+ // eth.call runs into error if data isnt filled and gas is not defined, its a simple transaction so we fill it with 21000
75
+ formatTx = Object.assign(Object.assign({}, tx), { gas: 21000 });
76
+ }
77
+ const reason = yield (0, get_revert_reason_js_1.getRevertReason)(this.web3Context, formatTx, this.options.contractAbi);
78
+ if (reason !== undefined) {
79
+ throw yield (0, get_transaction_error_js_1.getTransactionError)(this.web3Context, tx, undefined, undefined, this.options.contractAbi, reason);
80
+ }
81
+ }
82
+ });
83
+ }
84
+ emitSending(tx) {
85
+ if (this.promiEvent.listenerCount('sending') > 0) {
86
+ this.promiEvent.emit('sending', tx);
87
+ }
88
+ }
89
+ populateGasPrice({ transactionFormatted, transaction, }) {
90
+ var _a;
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ let result = transactionFormatted;
93
+ if (!this.web3Context.config.ignoreGasPricing &&
94
+ !((_a = this.options) === null || _a === void 0 ? void 0 : _a.ignoreGasPricing) &&
95
+ (0, web3_validator_1.isNullish)(transactionFormatted.gasPrice) &&
96
+ ((0, web3_validator_1.isNullish)(transaction.maxPriorityFeePerGas) ||
97
+ (0, web3_validator_1.isNullish)(transaction.maxFeePerGas))) {
98
+ result = Object.assign(Object.assign({}, transactionFormatted), (yield (0, get_transaction_gas_pricing_js_1.getTransactionGasPricing)(transactionFormatted, this.web3Context, web3_types_1.ETH_DATA_FORMAT)));
99
+ }
100
+ return result;
101
+ });
102
+ }
103
+ signAndSend({ wallet, tx, }) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ if (wallet) {
106
+ const signedTransaction = yield wallet.signTransaction(tx);
107
+ return (0, try_send_transaction_js_1.trySendTransaction)(this.web3Context, () => __awaiter(this, void 0, void 0, function* () {
108
+ return web3_rpc_methods_1.ethRpcMethods.sendRawTransaction(this.web3Context.requestManager, signedTransaction.rawTransaction);
109
+ }), signedTransaction.transactionHash);
110
+ }
111
+ return (0, try_send_transaction_js_1.trySendTransaction)(this.web3Context, () => __awaiter(this, void 0, void 0, function* () {
112
+ return web3_rpc_methods_1.ethRpcMethods.sendTransaction(this.web3Context.requestManager, tx);
113
+ }));
114
+ });
115
+ }
116
+ emitSent(tx) {
117
+ if (this.promiEvent.listenerCount('sent') > 0) {
118
+ this.promiEvent.emit('sent', tx);
119
+ }
120
+ }
121
+ emitTransactionHash(hash) {
122
+ if (this.promiEvent.listenerCount('transactionHash') > 0) {
123
+ this.promiEvent.emit('transactionHash', hash);
124
+ }
125
+ }
126
+ emitReceipt(receipt) {
127
+ if (this.promiEvent.listenerCount('receipt') > 0) {
128
+ this.promiEvent.emit('receipt',
129
+ // @ts-expect-error unknown type fix
130
+ receipt);
131
+ }
132
+ }
133
+ handleError({ error, tx }) {
134
+ var _a;
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ let _error = error;
137
+ if (_error instanceof web3_errors_1.ContractExecutionError && this.web3Context.handleRevert) {
138
+ _error = yield (0, get_transaction_error_js_1.getTransactionError)(this.web3Context, tx, undefined, undefined, (_a = this.options) === null || _a === void 0 ? void 0 : _a.contractAbi);
139
+ }
140
+ if ((_error instanceof web3_errors_1.InvalidResponseError ||
141
+ _error instanceof web3_errors_1.ContractExecutionError ||
142
+ _error instanceof web3_errors_1.TransactionRevertWithCustomError ||
143
+ _error instanceof web3_errors_1.TransactionRevertedWithoutReasonError ||
144
+ _error instanceof web3_errors_1.TransactionRevertInstructionError ||
145
+ _error instanceof web3_errors_1.TransactionPollingTimeoutError) &&
146
+ this.promiEvent.listenerCount('error') > 0) {
147
+ this.promiEvent.emit('error', _error);
148
+ }
149
+ return _error;
150
+ });
151
+ }
152
+ emitConfirmation({ receipt, transactionHash, customTransactionReceiptSchema, }) {
153
+ if (this.promiEvent.listenerCount('confirmation') > 0) {
154
+ (0, watch_transaction_for_confirmations_js_1.watchTransactionForConfirmations)(this.web3Context, this.promiEvent, receipt, transactionHash, this.returnFormat, customTransactionReceiptSchema);
155
+ }
156
+ }
157
+ handleResolve({ receipt, tx }) {
158
+ var _a, _b, _c;
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.transactionResolver) {
161
+ return (_b = this.options) === null || _b === void 0 ? void 0 : _b.transactionResolver(receipt);
162
+ }
163
+ if (receipt.status === BigInt(0)) {
164
+ const error = yield (0, get_transaction_error_js_1.getTransactionError)(this.web3Context, tx,
165
+ // @ts-expect-error unknown type fix
166
+ receipt, undefined, (_c = this.options) === null || _c === void 0 ? void 0 : _c.contractAbi);
167
+ if (this.promiEvent.listenerCount('error') > 0) {
168
+ this.promiEvent.emit('error', error);
169
+ }
170
+ throw error;
171
+ }
172
+ else {
173
+ return receipt;
174
+ }
175
+ });
176
+ }
177
+ }
178
+ exports.SendTxHelper = SendTxHelper;
179
+ //# sourceMappingURL=send_tx_helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send_tx_helper.js","sourceRoot":"","sources":["../../../src/utils/send_tx_helper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,2CAiBoB;AAEpB,mDAAuD;AACvD,6CAOqB;AACrB,uDAAiD;AAOjD,2CAA2C;AAC3C,qFAA4E;AAC5E,2CAA2C;AAC3C,uEAA+D;AAC/D,2CAA2C;AAC3C,qGAA4F;AAC5F,kDAAiD;AACjD,2CAA2C;AAC3C,yEAAiE;AACjE,2CAA2C;AAC3C,iEAAyD;AACzD,+CAA+C;AAE/C,MAAa,YAAY;IAkBxB,YAAmB,EAClB,OAAO,EACP,WAAW,EACX,UAAU,EACV,YAAY,GASZ;QAjBgB,YAAO,GAAwC;YAC/D,wBAAwB,EAAE,IAAI;SAC9B,CAAC;QAgBD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IAClC,CAAC;IAEM,oBAAoB,CAAC,IAAwB;;QACnD,MAAM,MAAM,qBAAQ,CAAC,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC,CAAE,CAAC;QACnC,IAAI,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,WAAW,KAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;YACvE,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC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;KACd;IAEM,gBAAgB,CAAC,EACvB,OAAO,EACP,eAAe,EACf,8BAA8B,GAK9B;QACA,IAAI,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YACtD,IAAA,yEAAgC,EAK/B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,EACf,OAAwC,EACxC,eAAe,EACf,IAAI,CAAC,YAAY,EACjB,8BAA8B,CAC9B,CAAC;SACF;IACF,CAAC;IAEY,aAAa,CAAC,EAAE,OAAO,EAAE,EAAE,EAAiD;;;YACxF,IAAI,MAAA,IAAI,CAAC,OAAO,0CAAE,mBAAmB,EAAE;gBACtC,OAAO,MAAA,IAAI,CAAC,OAAO,0CAAE,mBAAmB,CAAC,OAAwC,CAAC,CAAC;aACnF;YACD,IAAK,OAAyC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,EAAE;gBACpE,MAAM,KAAK,GAAG,MAAM,IAAA,8CAAmB,EACtC,IAAI,CAAC,WAAW,EAChB,EAAE;gBACF,oCAAoC;gBACpC,OAAO,EACP,SAAS,EACT,MAAA,IAAI,CAAC,OAAO,0CAAE,WAAW,CACzB,CAAC;gBACF,IAAI,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;oBAC/C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;iBACrC;gBAED,MAAM,KAAK,CAAC;aACZ;iBAAM;gBACN,OAAO,OAAO,CAAC;aACf;;KACD;CACD;AA5PD,oCA4PC"}
@@ -0,0 +1,19 @@
1
+ import { EthExecutionAPI, Address, HexString, Transaction, TransactionWithFromLocalWalletIndex, TransactionWithToLocalWalletIndex, TransactionWithFromAndToLocalWalletIndex, Web3NetAPI, DataFormat, FormatType, ETH_DATA_FORMAT } from 'web3-types';
2
+ import { Web3Context } from 'web3-core';
3
+ export declare const getTransactionFromOrToAttr: (attr: 'from' | 'to', web3Context: Web3Context<EthExecutionAPI>, transaction?: Transaction | TransactionWithFromLocalWalletIndex | TransactionWithToLocalWalletIndex | TransactionWithFromAndToLocalWalletIndex, privateKey?: HexString | Uint8Array) => Address | undefined;
4
+ export declare const getTransactionNonce: <ReturnFormat extends DataFormat>(web3Context: Web3Context<EthExecutionAPI>, address?: Address, returnFormat?: ReturnFormat) => Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>;
5
+ export declare const getTransactionType: (transaction: FormatType<Transaction, typeof ETH_DATA_FORMAT>, web3Context: Web3Context<EthExecutionAPI>) => string | undefined;
6
+ export declare function defaultTransactionBuilder<ReturnType = Transaction>(options: {
7
+ transaction: Transaction;
8
+ web3Context: Web3Context<EthExecutionAPI & Web3NetAPI>;
9
+ privateKey?: HexString | Uint8Array;
10
+ fillGasPrice?: boolean;
11
+ fillGasLimit?: boolean;
12
+ }): Promise<ReturnType>;
13
+ export declare const transactionBuilder: <ReturnType_1 = Transaction>(options: {
14
+ transaction: Transaction;
15
+ web3Context: Web3Context<EthExecutionAPI>;
16
+ privateKey?: HexString | Uint8Array;
17
+ fillGasPrice?: boolean;
18
+ fillGasLimit?: boolean;
19
+ }) => Promise<ReturnType_1>;
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ /*
3
+ This file is part of web3.js.
4
+
5
+ web3.js is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ web3.js is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.transactionBuilder = exports.defaultTransactionBuilder = exports.getTransactionType = exports.getTransactionNonce = exports.getTransactionFromOrToAttr = void 0;
29
+ const web3_types_1 = require("web3-types");
30
+ const web3_eth_accounts_1 = require("web3-eth-accounts");
31
+ const web3_net_1 = require("web3-net");
32
+ const web3_validator_1 = require("web3-validator");
33
+ const web3_errors_1 = require("web3-errors");
34
+ const web3_utils_1 = require("web3-utils");
35
+ const constants_js_1 = require("../constants.js");
36
+ // eslint-disable-next-line import/no-cycle
37
+ const rpc_method_wrappers_js_1 = require("../rpc_method_wrappers.js");
38
+ const detect_transaction_type_js_1 = require("./detect_transaction_type.js");
39
+ const schemas_js_1 = require("../schemas.js");
40
+ // eslint-disable-next-line import/no-cycle
41
+ const get_transaction_gas_pricing_js_1 = require("./get_transaction_gas_pricing.js");
42
+ const getTransactionFromOrToAttr = (attr, web3Context, transaction, privateKey) => {
43
+ if (transaction !== undefined && attr in transaction && transaction[attr] !== undefined) {
44
+ if (typeof transaction[attr] === 'string' && (0, web3_validator_1.isAddress)(transaction[attr])) {
45
+ return transaction[attr];
46
+ }
47
+ if (!(0, web3_validator_1.isHexStrict)(transaction[attr]) && (0, web3_validator_1.isNumber)(transaction[attr])) {
48
+ if (web3Context.wallet) {
49
+ const account = web3Context.wallet.get((0, web3_utils_1.format)({ format: 'uint' }, transaction[attr], constants_js_1.NUMBER_DATA_FORMAT));
50
+ if (!(0, web3_validator_1.isNullish)(account)) {
51
+ return account.address;
52
+ }
53
+ throw new web3_errors_1.LocalWalletNotAvailableError();
54
+ }
55
+ throw new web3_errors_1.LocalWalletNotAvailableError();
56
+ }
57
+ else {
58
+ throw attr === 'from'
59
+ ? new web3_errors_1.InvalidTransactionWithSender(transaction.from)
60
+ : // eslint-disable-next-line @typescript-eslint/no-unsafe-call
61
+ new web3_errors_1.InvalidTransactionWithReceiver(transaction.to);
62
+ }
63
+ }
64
+ if (attr === 'from') {
65
+ if (!(0, web3_validator_1.isNullish)(privateKey))
66
+ return (0, web3_eth_accounts_1.privateKeyToAddress)(privateKey);
67
+ if (!(0, web3_validator_1.isNullish)(web3Context.defaultAccount))
68
+ return web3Context.defaultAccount;
69
+ }
70
+ return undefined;
71
+ };
72
+ exports.getTransactionFromOrToAttr = getTransactionFromOrToAttr;
73
+ const getTransactionNonce = (web3Context, address, returnFormat = web3Context.defaultReturnFormat) => __awaiter(void 0, void 0, void 0, function* () {
74
+ if ((0, web3_validator_1.isNullish)(address)) {
75
+ // TODO if (web3.eth.accounts.wallet) use address from local wallet
76
+ throw new web3_errors_1.UnableToPopulateNonceError();
77
+ }
78
+ return (0, rpc_method_wrappers_js_1.getTransactionCount)(web3Context, address, web3Context.defaultBlock, returnFormat);
79
+ });
80
+ exports.getTransactionNonce = getTransactionNonce;
81
+ const getTransactionType = (transaction, web3Context) => {
82
+ const inferredType = (0, detect_transaction_type_js_1.detectTransactionType)(transaction, web3Context);
83
+ if (!(0, web3_validator_1.isNullish)(inferredType))
84
+ return inferredType;
85
+ if (!(0, web3_validator_1.isNullish)(web3Context.defaultTransactionType))
86
+ return (0, web3_utils_1.format)({ format: 'uint' }, web3Context.defaultTransactionType, web3_types_1.ETH_DATA_FORMAT);
87
+ return undefined;
88
+ };
89
+ exports.getTransactionType = getTransactionType;
90
+ // Keep in mind that the order the properties of populateTransaction get populated matters
91
+ // as some of the properties are dependent on others
92
+ function defaultTransactionBuilder(options) {
93
+ var _a, _b;
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ let populatedTransaction = (0, web3_utils_1.format)(schemas_js_1.transactionSchema, options.transaction, options.web3Context.defaultReturnFormat);
96
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.from)) {
97
+ populatedTransaction.from = (0, exports.getTransactionFromOrToAttr)('from', options.web3Context, undefined, options.privateKey);
98
+ }
99
+ // TODO: Debug why need to typecase getTransactionNonce
100
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.nonce)) {
101
+ populatedTransaction.nonce = yield (0, exports.getTransactionNonce)(options.web3Context, populatedTransaction.from, web3_types_1.ETH_DATA_FORMAT);
102
+ }
103
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.value)) {
104
+ populatedTransaction.value = '0x0';
105
+ }
106
+ if (!(0, web3_validator_1.isNullish)(populatedTransaction.data)) {
107
+ if (!(0, web3_validator_1.isNullish)(populatedTransaction.input) &&
108
+ populatedTransaction.data !== populatedTransaction.input)
109
+ throw new web3_errors_1.TransactionDataAndInputError({
110
+ data: (0, web3_utils_1.bytesToHex)(populatedTransaction.data),
111
+ input: (0, web3_utils_1.bytesToHex)(populatedTransaction.input),
112
+ });
113
+ if (!populatedTransaction.data.startsWith('0x'))
114
+ populatedTransaction.data = `0x${populatedTransaction.data}`;
115
+ }
116
+ else if (!(0, web3_validator_1.isNullish)(populatedTransaction.input)) {
117
+ if (!populatedTransaction.input.startsWith('0x'))
118
+ populatedTransaction.input = `0x${populatedTransaction.input}`;
119
+ }
120
+ else {
121
+ populatedTransaction.input = '0x';
122
+ }
123
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.common)) {
124
+ if (options.web3Context.defaultCommon) {
125
+ const common = options.web3Context.defaultCommon;
126
+ const chainId = common.customChain.chainId;
127
+ const networkId = common.customChain.networkId;
128
+ const name = common.customChain.name;
129
+ populatedTransaction.common = Object.assign(Object.assign({}, common), { customChain: { chainId, networkId, name } });
130
+ }
131
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.chain)) {
132
+ populatedTransaction.chain = options.web3Context.defaultChain;
133
+ }
134
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.hardfork)) {
135
+ populatedTransaction.hardfork = options.web3Context.defaultHardfork;
136
+ }
137
+ }
138
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.chainId) &&
139
+ (0, web3_validator_1.isNullish)((_a = populatedTransaction.common) === null || _a === void 0 ? void 0 : _a.customChain.chainId)) {
140
+ populatedTransaction.chainId = yield (0, rpc_method_wrappers_js_1.getChainId)(options.web3Context, web3_types_1.ETH_DATA_FORMAT);
141
+ }
142
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.networkId)) {
143
+ populatedTransaction.networkId =
144
+ (_b = options.web3Context.defaultNetworkId) !== null && _b !== void 0 ? _b : (yield (0, web3_net_1.getId)(options.web3Context, web3_types_1.ETH_DATA_FORMAT));
145
+ }
146
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.gasLimit) && !(0, web3_validator_1.isNullish)(populatedTransaction.gas)) {
147
+ populatedTransaction.gasLimit = populatedTransaction.gas;
148
+ }
149
+ populatedTransaction.type = (0, exports.getTransactionType)(populatedTransaction, options.web3Context);
150
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.accessList) &&
151
+ (populatedTransaction.type === '0x1' || populatedTransaction.type === '0x2')) {
152
+ populatedTransaction.accessList = [];
153
+ }
154
+ if (options.fillGasPrice)
155
+ populatedTransaction = Object.assign(Object.assign({}, populatedTransaction), (yield (0, get_transaction_gas_pricing_js_1.getTransactionGasPricing)(populatedTransaction, options.web3Context, web3_types_1.ETH_DATA_FORMAT)));
156
+ if ((0, web3_validator_1.isNullish)(populatedTransaction.gas) &&
157
+ (0, web3_validator_1.isNullish)(populatedTransaction.gasLimit) &&
158
+ options.fillGasLimit) {
159
+ const fillGasLimit = yield (0, rpc_method_wrappers_js_1.estimateGas)(options.web3Context, populatedTransaction, 'latest', web3_types_1.ETH_DATA_FORMAT);
160
+ populatedTransaction = Object.assign(Object.assign({}, populatedTransaction), { gas: (0, web3_utils_1.format)({ format: 'uint' }, fillGasLimit, web3_types_1.ETH_DATA_FORMAT) });
161
+ }
162
+ return populatedTransaction;
163
+ });
164
+ }
165
+ exports.defaultTransactionBuilder = defaultTransactionBuilder;
166
+ const transactionBuilder = (options) => __awaiter(void 0, void 0, void 0, function* () {
167
+ var _a;
168
+ return ((_a = options.web3Context.transactionBuilder) !== null && _a !== void 0 ? _a : defaultTransactionBuilder)(Object.assign(Object.assign({}, options), { transaction: options.transaction }));
169
+ });
170
+ exports.transactionBuilder = transactionBuilder;
171
+ //# sourceMappingURL=transaction_builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction_builder.js","sourceRoot":"","sources":["../../../src/utils/transaction_builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;AAEF,2CAgBoB;AAEpB,yDAAwD;AACxD,uCAAiC;AACjC,mDAA6E;AAC7E,6CAMqB;AACrB,2CAAgD;AAChD,kDAAqD;AACrD,2CAA2C;AAC3C,sEAAyF;AACzF,6EAAqE;AACrE,8CAAkD;AAElD,2CAA2C;AAC3C,qFAA4E;AAErE,MAAM,0BAA0B,GAAG,CACzC,IAAmB,EACnB,WAAyC,EACzC,WAI2C,EAC3C,UAAmC,EACb,EAAE;IACxB,IAAI,WAAW,KAAK,SAAS,IAAI,IAAI,IAAI,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC,KAAK,SAAS,EAAE;QACxF,IAAI,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,QAAQ,IAAI,IAAA,0BAAS,EAAC,WAAW,CAAC,IAAI,CAAW,CAAC,EAAE;YACpF,OAAO,WAAW,CAAC,IAAI,CAAY,CAAC;SACpC;QACD,IAAI,CAAC,IAAA,4BAAW,EAAC,WAAW,CAAC,IAAI,CAAW,CAAC,IAAI,IAAA,yBAAQ,EAAC,WAAW,CAAC,IAAI,CAAY,CAAC,EAAE;YACxF,IAAI,WAAW,CAAC,MAAM,EAAE;gBACvB,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG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AAoB,mCAChB,oBAAoB,GACpB,CAAC,MAAM,IAAA,yDAAwB,EACjC,oBAAoB,EACpB,OAAO,CAAC,WAAW,EACnB,4BAAe,CACf,CAAC,CACF,CAAC;QACH,IACC,IAAA,0BAAS,EAAC,oBAAoB,CAAC,GAAG,CAAC;YACnC,IAAA,0BAAS,EAAC,oBAAoB,CAAC,QAAQ,CAAC;YACxC,OAAO,CAAC,YAAY,EACnB;YACD,MAAM,YAAY,GAAG,MAAM,IAAA,oCAAW,EACrC,OAAO,CAAC,WAAW,EACnB,oBAAoB,EACpB,QAAQ,EACR,4BAAe,CACf,CAAC;YACF,oBAAoB,mCAChB,oBAAoB,KACvB,GAAG,EAAE,IAAA,mBAAM,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,YAAuB,EAAE,4BAAe,CAAC,GACzE,CAAC;SACF;QACD,OAAO,oBAAkC,CAAC;;CAC1C;AA5HD,8DA4HC;AAEM,MAAM,kBAAkB,GAAG,CACjC,OAMC,EAEA,EAAE;;IACH,OAAA,CAAC,MAAA,OAAO,CAAC,WAAW,CAAC,kBAAkB,mCAAI,yBAAyB,CAAC,iCACjE,OAAO,KACV,WAAW,EAAE,OAAO,CAAC,WAAW,IACN,CAAA;EAAA,CAAC;AAbhB,QAAA,kBAAkB,sBAaF"}
@@ -0,0 +1,11 @@
1
+ import { Web3Context } from 'web3-core';
2
+ import { EthExecutionAPI, Bytes } from 'web3-types';
3
+ import { AsyncFunction } from 'web3-utils';
4
+ /**
5
+ * An internal function to send a transaction or throws if sending did not finish during the timeout during the blocks-timeout.
6
+ * @param web3Context - the context to read the configurations from
7
+ * @param sendTransactionFunc - the function that will send the transaction (could be sendTransaction or sendRawTransaction)
8
+ * @param transactionHash - to be used inside the exception message if there will be any exceptions.
9
+ * @returns the Promise<string> returned by the `sendTransactionFunc`.
10
+ */
11
+ export declare function trySendTransaction(web3Context: Web3Context<EthExecutionAPI>, sendTransactionFunc: AsyncFunction<string>, transactionHash?: Bytes): Promise<string>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.trySendTransaction = void 0;
13
+ const web3_utils_1 = require("web3-utils");
14
+ const web3_errors_1 = require("web3-errors");
15
+ // eslint-disable-next-line import/no-cycle
16
+ const reject_if_block_timeout_js_1 = require("./reject_if_block_timeout.js");
17
+ /**
18
+ * An internal function to send a transaction or throws if sending did not finish during the timeout during the blocks-timeout.
19
+ * @param web3Context - the context to read the configurations from
20
+ * @param sendTransactionFunc - the function that will send the transaction (could be sendTransaction or sendRawTransaction)
21
+ * @param transactionHash - to be used inside the exception message if there will be any exceptions.
22
+ * @returns the Promise<string> returned by the `sendTransactionFunc`.
23
+ */
24
+ function trySendTransaction(web3Context, sendTransactionFunc, transactionHash) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const [timeoutId, rejectOnTimeout] = (0, web3_utils_1.rejectIfTimeout)(web3Context.transactionSendTimeout, new web3_errors_1.TransactionSendTimeoutError({
27
+ numberOfSeconds: web3Context.transactionSendTimeout / 1000,
28
+ transactionHash,
29
+ }));
30
+ const [rejectOnBlockTimeout, blockTimeoutResourceCleaner] = yield (0, reject_if_block_timeout_js_1.rejectIfBlockTimeout)(web3Context, transactionHash);
31
+ try {
32
+ // If an error happened here, do not catch it, just clear the resources before raising it to the caller function.
33
+ return yield Promise.race([
34
+ sendTransactionFunc(),
35
+ rejectOnTimeout,
36
+ rejectOnBlockTimeout, // this will throw an error on Transaction Block Timeout
37
+ ]);
38
+ }
39
+ finally {
40
+ clearTimeout(timeoutId);
41
+ blockTimeoutResourceCleaner.clean();
42
+ }
43
+ });
44
+ }
45
+ exports.trySendTransaction = trySendTransaction;
46
+ //# sourceMappingURL=try_send_transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"try_send_transaction.js","sourceRoot":"","sources":["../../../src/utils/try_send_transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;AAkBA,2CAA4D;AAC5D,6CAA0D;AAE1D,2CAA2C;AAC3C,6EAAoE;AAEpE;;;;;;GAMG;AACH,SAAsB,kBAAkB,CACvC,WAAyC,EACzC,mBAA0C,EAC1C,eAAuB;;QAEvB,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,IAAA,4BAAe,EACnD,WAAW,CAAC,sBAAsB,EAClC,IAAI,yCAA2B,CAAC;YAC/B,eAAe,EAAE,WAAW,CAAC,sBAAsB,GAAG,IAAI;YAC1D,eAAe;SACf,CAAC,CACF,CAAC;QAEF,MAAM,CAAC,oBAAoB,EAAE,2BAA2B,CAAC,GAAG,MAAM,IAAA,iDAAoB,EACrF,WAAW,EACX,eAAe,CACf,CAAC;QAEF,IAAI;YACH,iHAAiH;YACjH,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC;gBACzB,mBAAmB,EAAE;gBACrB,eAAe;gBACf,oBAAoB,EAAE,wDAAwD;aAC9E,CAAC,CAAC;SACH;gBAAS;YACT,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,2BAA2B,CAAC,KAAK,EAAE,CAAC;SACpC;IACF,CAAC;CAAA;AA7BD,gDA6BC"}
@@ -0,0 +1,3 @@
1
+ import { Web3Context } from 'web3-core';
2
+ import { EthExecutionAPI, Bytes, TransactionReceipt, DataFormat } from 'web3-types';
3
+ export declare function waitForTransactionReceipt<ReturnFormat extends DataFormat>(web3Context: Web3Context<EthExecutionAPI>, transactionHash: Bytes, returnFormat: ReturnFormat, customGetTransactionReceipt?: (web3Context: Web3Context<EthExecutionAPI>, transactionHash: Bytes, returnFormat: ReturnFormat) => Promise<TransactionReceipt>): Promise<TransactionReceipt>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /*
3
+ This file is part of web3.js.
4
+
5
+ web3.js is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ web3.js is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.waitForTransactionReceipt = void 0;
29
+ const web3_errors_1 = require("web3-errors");
30
+ // eslint-disable-next-line import/no-cycle
31
+ const web3_utils_1 = require("web3-utils");
32
+ // eslint-disable-next-line import/no-cycle
33
+ const reject_if_block_timeout_js_1 = require("./reject_if_block_timeout.js");
34
+ // eslint-disable-next-line import/no-cycle
35
+ const rpc_method_wrappers_js_1 = require("../rpc_method_wrappers.js");
36
+ function waitForTransactionReceipt(web3Context, transactionHash, returnFormat, customGetTransactionReceipt) {
37
+ var _a;
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const pollingInterval = (_a = web3Context.transactionReceiptPollingInterval) !== null && _a !== void 0 ? _a : web3Context.transactionPollingInterval;
40
+ const [awaitableTransactionReceipt, IntervalId] = (0, web3_utils_1.pollTillDefinedAndReturnIntervalId)(() => __awaiter(this, void 0, void 0, function* () {
41
+ try {
42
+ return (customGetTransactionReceipt !== null && customGetTransactionReceipt !== void 0 ? customGetTransactionReceipt : rpc_method_wrappers_js_1.getTransactionReceipt)(web3Context, transactionHash, returnFormat);
43
+ }
44
+ catch (error) {
45
+ console.warn('An error happen while trying to get the transaction receipt', error);
46
+ return undefined;
47
+ }
48
+ }), pollingInterval);
49
+ const [timeoutId, rejectOnTimeout] = (0, web3_utils_1.rejectIfTimeout)(web3Context.transactionPollingTimeout, new web3_errors_1.TransactionPollingTimeoutError({
50
+ numberOfSeconds: web3Context.transactionPollingTimeout / 1000,
51
+ transactionHash,
52
+ }));
53
+ const [rejectOnBlockTimeout, blockTimeoutResourceCleaner] = yield (0, reject_if_block_timeout_js_1.rejectIfBlockTimeout)(web3Context, transactionHash);
54
+ try {
55
+ // If an error happened here, do not catch it, just clear the resources before raising it to the caller function.
56
+ return yield Promise.race([
57
+ awaitableTransactionReceipt,
58
+ rejectOnTimeout,
59
+ rejectOnBlockTimeout, // this will throw an error on Transaction Block Timeout
60
+ ]);
61
+ }
62
+ finally {
63
+ if (timeoutId)
64
+ clearTimeout(timeoutId);
65
+ if (IntervalId)
66
+ clearInterval(IntervalId);
67
+ blockTimeoutResourceCleaner.clean();
68
+ }
69
+ });
70
+ }
71
+ exports.waitForTransactionReceipt = waitForTransactionReceipt;
72
+ //# sourceMappingURL=wait_for_transaction_receipt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait_for_transaction_receipt.js","sourceRoot":"","sources":["../../../src/utils/wait_for_transaction_receipt.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;AAGF,6CAA6D;AAG7D,2CAA2C;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AAC;SACpC;;CACD;AAtDD,8DAsDC"}
@@ -0,0 +1,19 @@
1
+ import { EthExecutionAPI, TransactionReceipt } from 'web3-types';
2
+ import { Web3Context, Web3PromiEvent } from 'web3-core';
3
+ import { DataFormat } from 'web3-types';
4
+ import { JsonSchema } from 'web3-validator';
5
+ import { SendSignedTransactionEvents, SendTransactionEvents } from '../types.js';
6
+ export declare type Web3PromiEventEventTypeBase<ReturnFormat extends DataFormat> = SendTransactionEvents<ReturnFormat> | SendSignedTransactionEvents<ReturnFormat>;
7
+ export declare type WaitProps<ReturnFormat extends DataFormat, ResolveType = TransactionReceipt> = {
8
+ web3Context: Web3Context<EthExecutionAPI>;
9
+ transactionReceipt: TransactionReceipt;
10
+ customTransactionReceiptSchema?: JsonSchema;
11
+ transactionPromiEvent: Web3PromiEvent<ResolveType, Web3PromiEventEventTypeBase<ReturnFormat>>;
12
+ returnFormat: ReturnFormat;
13
+ };
14
+ /**
15
+ * This function watches a Transaction by subscribing to new heads.
16
+ * It is used by `watchTransactionForConfirmations`, in case the provider does not support subscription.
17
+ * And it is also used by `watchTransactionBySubscription`, as a fallback, if the subscription failed for any reason.
18
+ */
19
+ export declare const watchTransactionByPolling: <ReturnFormat extends DataFormat, ResolveType = TransactionReceipt>({ web3Context, transactionReceipt, transactionPromiEvent, customTransactionReceiptSchema, returnFormat, }: WaitProps<ReturnFormat, ResolveType>) => void;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.watchTransactionByPolling = void 0;
13
+ const web3_utils_1 = require("web3-utils");
14
+ const web3_rpc_methods_1 = require("web3-rpc-methods");
15
+ const schemas_js_1 = require("../schemas.js");
16
+ /**
17
+ * This function watches a Transaction by subscribing to new heads.
18
+ * It is used by `watchTransactionForConfirmations`, in case the provider does not support subscription.
19
+ * And it is also used by `watchTransactionBySubscription`, as a fallback, if the subscription failed for any reason.
20
+ */
21
+ const watchTransactionByPolling = ({ web3Context, transactionReceipt, transactionPromiEvent, customTransactionReceiptSchema, returnFormat, }) => {
22
+ var _a;
23
+ // Having a transactionReceipt means that the transaction has already been included
24
+ // in at least one block, so we start with 1
25
+ let confirmations = 1;
26
+ const intervalId = setInterval(() => {
27
+ (() => __awaiter(void 0, void 0, void 0, function* () {
28
+ if (confirmations >= web3Context.transactionConfirmationBlocks) {
29
+ clearInterval(intervalId);
30
+ return;
31
+ }
32
+ const nextBlock = yield web3_rpc_methods_1.ethRpcMethods.getBlockByNumber(web3Context.requestManager, (0, web3_utils_1.numberToHex)(BigInt(transactionReceipt.blockNumber) + BigInt(confirmations)), false);
33
+ if (nextBlock === null || nextBlock === void 0 ? void 0 : nextBlock.hash) {
34
+ confirmations += 1;
35
+ transactionPromiEvent.emit('confirmation', {
36
+ confirmations: (0, web3_utils_1.format)({ format: 'uint' }, confirmations, returnFormat),
37
+ receipt: (0, web3_utils_1.format)(customTransactionReceiptSchema !== null && customTransactionReceiptSchema !== void 0 ? customTransactionReceiptSchema : schemas_js_1.transactionReceiptSchema, transactionReceipt, returnFormat),
38
+ latestBlockHash: (0, web3_utils_1.format)({ format: 'bytes32' }, nextBlock.hash, returnFormat),
39
+ });
40
+ }
41
+ }))();
42
+ }, (_a = web3Context.transactionReceiptPollingInterval) !== null && _a !== void 0 ? _a : web3Context.transactionPollingInterval);
43
+ };
44
+ exports.watchTransactionByPolling = watchTransactionByPolling;
45
+ //# sourceMappingURL=watch_transaction_by_polling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"watch_transaction_by_polling.js","sourceRoot":"","sources":["../../../src/utils/watch_transaction_by_polling.ts"],"names":[],"mappings":";;;;;;;;;;;;AAkBA,2CAAiD;AACjD,uDAAiD;AAKjD,8CAAyD;AAczD;;;;GAIG;AACI,MAAM,yBAAyB,GAAG,CAGvC,EACD,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,8BAA8B,EAC9B,YAAY,GAC0B,EAAE,EAAE;;IAC1C,mFAAmF;IACnF,4CAA4C;IAC5C,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE;QACnC,CAAC,GAAS,EAAE;YACX,IAAI,aAAa,IAAI,WAAW,CAAC,6BAA6B,EAAE;gBAC/D,aAAa,CAAC,UAAU,CAAC,CAAC;gBAC1B,OAAO;aACP;YAED,MAAM,SAAS,GAAG,MAAM,gCAAa,CAAC,gBAAgB,CACrD,WAAW,CAAC,cAAc,EAC1B,IAAA,wBAAW,EAAC,MAAM,CAAC,kBAAkB,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,EAC3E,KAAK,CACL,CAAC;YAEF,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,EAAE;gBACpB,aAAa,IAAI,CAAC,CAAC;gBAEnB,qBAAqB,CAAC,IAAI,CAAC,cAAc,EAAE;oBAC1C,aAAa,EAAE,IAAA,mBAAM,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,YAAY,CAAC;oBACtE,OAAO,EAAE,IAAA,mBAAM,EACd,8BAA8B,aAA9B,8BAA8B,cAA9B,8BAA8B,GAAI,qCAAwB,EAC1D,kBAAkB,EAClB,YAAY,CACZ;oBACD,eAAe,EAAE,IAAA,mBAAM,EACtB,EAAE,MAAM,EAAE,SAAS,EAAE,EACrB,SAAS,CAAC,IAAa,EACvB,YAAY,CACZ;iBACD,CAAC,CAAC;aACH;QACF,CAAC,CAAA,CAAC,EAAa,CAAC;IACjB,CAAC,EAAE,MAAA,WAAW,CAAC,iCAAiC,mCAAI,WAAW,CAAC,0BAA0B,CAAC,CAAC;AAC7F,CAAC,CAAC;AA7CW,QAAA,yBAAyB,6BA6CpC"}
@@ -0,0 +1,8 @@
1
+ import { TransactionReceipt } from 'web3-types';
2
+ import { DataFormat } from 'web3-types';
3
+ import { WaitProps } from './watch_transaction_by_polling.js';
4
+ /**
5
+ * This function watches a Transaction by subscribing to new heads.
6
+ * It is used by `watchTransactionForConfirmations`, in case the provider supports subscription.
7
+ */
8
+ export declare const watchTransactionBySubscription: <ReturnFormat extends DataFormat, ResolveType = TransactionReceipt>({ web3Context, transactionReceipt, transactionPromiEvent, customTransactionReceiptSchema, returnFormat, }: WaitProps<ReturnFormat, ResolveType>) => void;