web-eth 0.0.1-security → 4.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (206) hide show
  1. package/0ap52u0p.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,99 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ import { ETH_DATA_FORMAT, } from 'web3-types';
27
+ import { toNumber } from 'web3-utils';
28
+ import { TransactionFactory, Common } from 'web3-eth-accounts';
29
+ import { isNullish } from 'web3-validator';
30
+ import { validateTransactionForSigning } from '../validation.js';
31
+ import { formatTransaction } from './format_transaction.js';
32
+ import { transactionBuilder } from './transaction_builder.js';
33
+ const getEthereumjsTxDataFromTransaction = (transaction) => {
34
+ var _a, _b;
35
+ return (Object.assign(Object.assign({}, transaction), { nonce: transaction.nonce, gasPrice: transaction.gasPrice, gasLimit: (_a = transaction.gasLimit) !== null && _a !== void 0 ? _a : transaction.gas, to: transaction.to, value: transaction.value, data: (_b = transaction.data) !== null && _b !== void 0 ? _b : transaction.input, type: transaction.type, chainId: transaction.chainId, accessList: transaction.accessList, maxPriorityFeePerGas: transaction.maxPriorityFeePerGas, maxFeePerGas: transaction.maxFeePerGas }));
36
+ };
37
+ const getEthereumjsTransactionOptions = (transaction, web3Context) => {
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
39
+ const hasTransactionSigningOptions = (!isNullish(transaction.chain) && !isNullish(transaction.hardfork)) ||
40
+ !isNullish(transaction.common);
41
+ let common;
42
+ if (!hasTransactionSigningOptions) {
43
+ // if defaultcommon is specified, use that.
44
+ if (web3Context.defaultCommon) {
45
+ common = Object.assign({}, web3Context.defaultCommon);
46
+ if (isNullish(common.hardfork))
47
+ common.hardfork = (_a = transaction.hardfork) !== null && _a !== void 0 ? _a : web3Context.defaultHardfork;
48
+ if (isNullish(common.baseChain))
49
+ common.baseChain = web3Context.defaultChain;
50
+ }
51
+ else {
52
+ common = Common.custom({
53
+ name: 'custom-network',
54
+ chainId: toNumber(transaction.chainId),
55
+ networkId: !isNullish(transaction.networkId)
56
+ ? toNumber(transaction.networkId)
57
+ : undefined,
58
+ defaultHardfork: (_b = transaction.hardfork) !== null && _b !== void 0 ? _b : web3Context.defaultHardfork,
59
+ }, {
60
+ baseChain: web3Context.defaultChain,
61
+ });
62
+ }
63
+ }
64
+ else {
65
+ const name = (_f = (_e = (_d = (_c = transaction === null || transaction === void 0 ? void 0 : transaction.common) === null || _c === void 0 ? void 0 : _c.customChain) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : transaction.chain) !== null && _f !== void 0 ? _f : 'custom-network';
66
+ const chainId = toNumber((_j = (_h = (_g = transaction === null || transaction === void 0 ? void 0 : transaction.common) === null || _g === void 0 ? void 0 : _g.customChain) === null || _h === void 0 ? void 0 : _h.chainId) !== null && _j !== void 0 ? _j : transaction === null || transaction === void 0 ? void 0 : transaction.chainId);
67
+ const networkId = toNumber((_m = (_l = (_k = transaction === null || transaction === void 0 ? void 0 : transaction.common) === null || _k === void 0 ? void 0 : _k.customChain) === null || _l === void 0 ? void 0 : _l.networkId) !== null && _m !== void 0 ? _m : transaction === null || transaction === void 0 ? void 0 : transaction.networkId);
68
+ const defaultHardfork = (_q = (_p = (_o = transaction === null || transaction === void 0 ? void 0 : transaction.common) === null || _o === void 0 ? void 0 : _o.hardfork) !== null && _p !== void 0 ? _p : transaction === null || transaction === void 0 ? void 0 : transaction.hardfork) !== null && _q !== void 0 ? _q : web3Context.defaultHardfork;
69
+ const baseChain = (_t = (_s = (_r = transaction.common) === null || _r === void 0 ? void 0 : _r.baseChain) !== null && _s !== void 0 ? _s : transaction.chain) !== null && _t !== void 0 ? _t : web3Context.defaultChain;
70
+ if (chainId && networkId && name) {
71
+ common = Common.custom({
72
+ name,
73
+ chainId,
74
+ networkId,
75
+ defaultHardfork,
76
+ }, {
77
+ baseChain,
78
+ });
79
+ }
80
+ }
81
+ return { common };
82
+ };
83
+ export const prepareTransactionForSigning = (transaction, web3Context, privateKey, fillGasPrice = false, fillGasLimit = true) => __awaiter(void 0, void 0, void 0, function* () {
84
+ const populatedTransaction = (yield transactionBuilder({
85
+ transaction,
86
+ web3Context,
87
+ privateKey,
88
+ fillGasPrice,
89
+ fillGasLimit,
90
+ }));
91
+ const formattedTransaction = formatTransaction(populatedTransaction, ETH_DATA_FORMAT, {
92
+ transactionSchema: web3Context.config.customTransactionSchema,
93
+ });
94
+ validateTransactionForSigning(formattedTransaction, undefined, {
95
+ transactionSchema: web3Context.config.customTransactionSchema,
96
+ });
97
+ return TransactionFactory.fromTxData(getEthereumjsTxDataFromTransaction(formattedTransaction), getEthereumjsTransactionOptions(formattedTransaction, web3Context));
98
+ });
99
+ //# sourceMappingURL=prepare_transaction_for_signing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare_transaction_for_signing.js","sourceRoot":"","sources":["../../../src/utils/prepare_transaction_for_signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAe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AAU,CACnC,kCAAkC,CAAC,oBAAoB,CAAC,EACxD,+BAA+B,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAClE,CAAC;AACH,CAAC,CAAA,CAAC"}
@@ -0,0 +1,134 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { rejectIfConditionAtInterval } from 'web3-utils';
11
+ import { TransactionBlockTimeoutError } from 'web3-errors';
12
+ import { NUMBER_DATA_FORMAT } from '../constants.js';
13
+ // eslint-disable-next-line import/no-cycle
14
+ import { getBlockNumber } from '../rpc_method_wrappers.js';
15
+ function resolveByPolling(web3Context, starterBlockNumber, transactionHash) {
16
+ const pollingInterval = web3Context.transactionPollingInterval;
17
+ const [intervalId, promiseToError] = rejectIfConditionAtInterval(() => __awaiter(this, void 0, void 0, function* () {
18
+ let lastBlockNumber;
19
+ try {
20
+ lastBlockNumber = yield getBlockNumber(web3Context, NUMBER_DATA_FORMAT);
21
+ }
22
+ catch (error) {
23
+ console.warn('An error happen while trying to get the block number', error);
24
+ return undefined;
25
+ }
26
+ const numberOfBlocks = lastBlockNumber - starterBlockNumber;
27
+ if (numberOfBlocks >= web3Context.transactionBlockTimeout) {
28
+ return new TransactionBlockTimeoutError({
29
+ starterBlockNumber,
30
+ numberOfBlocks,
31
+ transactionHash,
32
+ });
33
+ }
34
+ return undefined;
35
+ }), pollingInterval);
36
+ const clean = () => {
37
+ clearInterval(intervalId);
38
+ };
39
+ return [promiseToError, { clean }];
40
+ }
41
+ function resolveBySubscription(web3Context, starterBlockNumber, transactionHash) {
42
+ var _a;
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ // The following variable will stay true except if the data arrived,
45
+ // or if watching started after an error had occurred.
46
+ let needToWatchLater = true;
47
+ let subscription;
48
+ let resourceCleaner;
49
+ // internal helper function
50
+ function revertToPolling(reject, previousError) {
51
+ if (previousError) {
52
+ console.warn('error happened at subscription. So revert to polling...', previousError);
53
+ }
54
+ resourceCleaner.clean();
55
+ needToWatchLater = false;
56
+ const [promiseToError, newResourceCleaner] = resolveByPolling(web3Context, starterBlockNumber, transactionHash);
57
+ resourceCleaner.clean = newResourceCleaner.clean;
58
+ promiseToError.catch(error => reject(error));
59
+ }
60
+ try {
61
+ subscription = (yield ((_a = web3Context.subscriptionManager) === null || _a === void 0 ? void 0 : _a.subscribe('newHeads')));
62
+ resourceCleaner = {
63
+ clean: () => {
64
+ var _a;
65
+ // Remove the subscription, if it was not removed somewhere
66
+ // else by calling, for example, subscriptionManager.clear()
67
+ if (subscription.id) {
68
+ (_a = web3Context.subscriptionManager) === null || _a === void 0 ? void 0 : _a.removeSubscription(subscription).then(() => {
69
+ // Subscription ended successfully
70
+ }).catch(() => {
71
+ // An error happened while ending subscription. But no need to take any action.
72
+ });
73
+ }
74
+ },
75
+ };
76
+ }
77
+ catch (error) {
78
+ return resolveByPolling(web3Context, starterBlockNumber, transactionHash);
79
+ }
80
+ const promiseToError = new Promise((_, reject) => {
81
+ try {
82
+ subscription.on('data', (lastBlockHeader) => {
83
+ needToWatchLater = false;
84
+ if (!(lastBlockHeader === null || lastBlockHeader === void 0 ? void 0 : lastBlockHeader.number)) {
85
+ return;
86
+ }
87
+ const numberOfBlocks = Number(BigInt(lastBlockHeader.number) - BigInt(starterBlockNumber));
88
+ if (numberOfBlocks >= web3Context.transactionBlockTimeout) {
89
+ // Transaction Block Timeout is known to be reached by subscribing to new heads
90
+ reject(new TransactionBlockTimeoutError({
91
+ starterBlockNumber,
92
+ numberOfBlocks,
93
+ transactionHash,
94
+ }));
95
+ }
96
+ });
97
+ subscription.on('error', error => {
98
+ revertToPolling(reject, error);
99
+ });
100
+ }
101
+ catch (error) {
102
+ revertToPolling(reject, error);
103
+ }
104
+ // Fallback to polling if tx receipt didn't arrived in "blockHeaderTimeout" [10 seconds]
105
+ setTimeout(() => {
106
+ if (needToWatchLater) {
107
+ revertToPolling(reject);
108
+ }
109
+ }, web3Context.blockHeaderTimeout * 1000);
110
+ });
111
+ return [promiseToError, resourceCleaner];
112
+ });
113
+ }
114
+ /* TODO: After merge, there will be constant block mining time (exactly 12 second each block, except slot missed that currently happens in <1% of slots. ) so we can optimize following function
115
+ for POS NWs, we can skip checking getBlockNumber(); after interval and calculate only based on time that certain num of blocked are mined after that for internal double check, can do one getBlockNumber() call and timeout.
116
+ */
117
+ export function rejectIfBlockTimeout(web3Context, transactionHash) {
118
+ var _a, _b;
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ const { provider } = web3Context.requestManager;
121
+ let callingRes;
122
+ const starterBlockNumber = yield getBlockNumber(web3Context, NUMBER_DATA_FORMAT);
123
+ // TODO: once https://github.com/web3/web3.js/issues/5521 is implemented, remove checking for `enableExperimentalFeatures.useSubscriptionWhenCheckingBlockTimeout`
124
+ if (((_b = (_a = provider).supportsSubscriptions) === null || _b === void 0 ? void 0 : _b.call(_a)) &&
125
+ web3Context.enableExperimentalFeatures.useSubscriptionWhenCheckingBlockTimeout) {
126
+ callingRes = yield resolveBySubscription(web3Context, starterBlockNumber, transactionHash);
127
+ }
128
+ else {
129
+ callingRes = resolveByPolling(web3Context, starterBlockNumber, transactionHash);
130
+ }
131
+ return callingRes;
132
+ });
133
+ }
134
+ //# sourceMappingURL=reject_if_block_timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reject_if_block_timeout.js","sourceRoot":"","sources":["../../../src/utils/reject_if_block_timeout.ts"],"names":[],"mappings":";;;;;;;;;AAkBA,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAE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ACD,UAAU,GAAG,MAAM,qBAAqB,CAAC,WAAW,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC;SAC3F;aAAM;YACN,UAAU,GAAG,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC;SAChF;QACD,OAAO,UAAU,CAAC;;CAClB"}
@@ -0,0 +1,175 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /*
11
+ This file is part of web3.js.
12
+
13
+ web3.js is free software: you can redistribute it and/or modify
14
+ it under the terms of the GNU Lesser General Public License as published by
15
+ the Free Software Foundation, either version 3 of the License, or
16
+ (at your option) any later version.
17
+
18
+ web3.js is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU Lesser General Public License for more details.
22
+
23
+ You should have received a copy of the GNU Lesser General Public License
24
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
25
+ */
26
+ import { ETH_DATA_FORMAT, } from 'web3-types';
27
+ import { isNullish } from 'web3-validator';
28
+ import { ContractExecutionError, InvalidResponseError, TransactionPollingTimeoutError, TransactionRevertedWithoutReasonError, TransactionRevertInstructionError, TransactionRevertWithCustomError, } from 'web3-errors';
29
+ import { ethRpcMethods } from 'web3-rpc-methods';
30
+ // eslint-disable-next-line import/no-cycle
31
+ import { getTransactionGasPricing } from './get_transaction_gas_pricing.js';
32
+ // eslint-disable-next-line import/no-cycle
33
+ import { trySendTransaction } from './try_send_transaction.js';
34
+ // eslint-disable-next-line import/no-cycle
35
+ import { watchTransactionForConfirmations } from './watch_transaction_for_confirmations.js';
36
+ import { ALL_EVENTS_ABI } from '../constants.js';
37
+ // eslint-disable-next-line import/no-cycle
38
+ import { getTransactionError } from './get_transaction_error.js';
39
+ // eslint-disable-next-line import/no-cycle
40
+ import { getRevertReason } from './get_revert_reason.js';
41
+ import { decodeEventABI } from './decoding.js';
42
+ export class SendTxHelper {
43
+ constructor({ options, web3Context, promiEvent, returnFormat, }) {
44
+ this.options = {
45
+ checkRevertBeforeSending: true,
46
+ };
47
+ this.options = options;
48
+ this.web3Context = web3Context;
49
+ this.promiEvent = promiEvent;
50
+ this.returnFormat = returnFormat;
51
+ }
52
+ getReceiptWithEvents(data) {
53
+ var _a, _b;
54
+ const result = Object.assign({}, (data !== null && data !== void 0 ? data : {}));
55
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.contractAbi) && result.logs && result.logs.length > 0) {
56
+ result.events = {};
57
+ for (const log of result.logs) {
58
+ const event = decodeEventABI(ALL_EVENTS_ABI, log, (_b = this.options) === null || _b === void 0 ? void 0 : _b.contractAbi, this.returnFormat);
59
+ if (event.event) {
60
+ result.events[event.event] = event;
61
+ }
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ checkRevertBeforeSending(tx) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ if (this.options.checkRevertBeforeSending !== false) {
69
+ let formatTx = tx;
70
+ if (isNullish(tx.data) && isNullish(tx.input) && isNullish(tx.gas)) {
71
+ // eth.call runs into error if data isnt filled and gas is not defined, its a simple transaction so we fill it with 21000
72
+ formatTx = Object.assign(Object.assign({}, tx), { gas: 21000 });
73
+ }
74
+ const reason = yield getRevertReason(this.web3Context, formatTx, this.options.contractAbi);
75
+ if (reason !== undefined) {
76
+ throw yield getTransactionError(this.web3Context, tx, undefined, undefined, this.options.contractAbi, reason);
77
+ }
78
+ }
79
+ });
80
+ }
81
+ emitSending(tx) {
82
+ if (this.promiEvent.listenerCount('sending') > 0) {
83
+ this.promiEvent.emit('sending', tx);
84
+ }
85
+ }
86
+ populateGasPrice({ transactionFormatted, transaction, }) {
87
+ var _a;
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ let result = transactionFormatted;
90
+ if (!this.web3Context.config.ignoreGasPricing &&
91
+ !((_a = this.options) === null || _a === void 0 ? void 0 : _a.ignoreGasPricing) &&
92
+ isNullish(transactionFormatted.gasPrice) &&
93
+ (isNullish(transaction.maxPriorityFeePerGas) ||
94
+ isNullish(transaction.maxFeePerGas))) {
95
+ result = Object.assign(Object.assign({}, transactionFormatted), (yield getTransactionGasPricing(transactionFormatted, this.web3Context, ETH_DATA_FORMAT)));
96
+ }
97
+ return result;
98
+ });
99
+ }
100
+ signAndSend({ wallet, tx, }) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ if (wallet) {
103
+ const signedTransaction = yield wallet.signTransaction(tx);
104
+ return trySendTransaction(this.web3Context, () => __awaiter(this, void 0, void 0, function* () {
105
+ return ethRpcMethods.sendRawTransaction(this.web3Context.requestManager, signedTransaction.rawTransaction);
106
+ }), signedTransaction.transactionHash);
107
+ }
108
+ return trySendTransaction(this.web3Context, () => __awaiter(this, void 0, void 0, function* () {
109
+ return ethRpcMethods.sendTransaction(this.web3Context.requestManager, tx);
110
+ }));
111
+ });
112
+ }
113
+ emitSent(tx) {
114
+ if (this.promiEvent.listenerCount('sent') > 0) {
115
+ this.promiEvent.emit('sent', tx);
116
+ }
117
+ }
118
+ emitTransactionHash(hash) {
119
+ if (this.promiEvent.listenerCount('transactionHash') > 0) {
120
+ this.promiEvent.emit('transactionHash', hash);
121
+ }
122
+ }
123
+ emitReceipt(receipt) {
124
+ if (this.promiEvent.listenerCount('receipt') > 0) {
125
+ this.promiEvent.emit('receipt',
126
+ // @ts-expect-error unknown type fix
127
+ receipt);
128
+ }
129
+ }
130
+ handleError({ error, tx }) {
131
+ var _a;
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ let _error = error;
134
+ if (_error instanceof ContractExecutionError && this.web3Context.handleRevert) {
135
+ _error = yield getTransactionError(this.web3Context, tx, undefined, undefined, (_a = this.options) === null || _a === void 0 ? void 0 : _a.contractAbi);
136
+ }
137
+ if ((_error instanceof InvalidResponseError ||
138
+ _error instanceof ContractExecutionError ||
139
+ _error instanceof TransactionRevertWithCustomError ||
140
+ _error instanceof TransactionRevertedWithoutReasonError ||
141
+ _error instanceof TransactionRevertInstructionError ||
142
+ _error instanceof TransactionPollingTimeoutError) &&
143
+ this.promiEvent.listenerCount('error') > 0) {
144
+ this.promiEvent.emit('error', _error);
145
+ }
146
+ return _error;
147
+ });
148
+ }
149
+ emitConfirmation({ receipt, transactionHash, customTransactionReceiptSchema, }) {
150
+ if (this.promiEvent.listenerCount('confirmation') > 0) {
151
+ watchTransactionForConfirmations(this.web3Context, this.promiEvent, receipt, transactionHash, this.returnFormat, customTransactionReceiptSchema);
152
+ }
153
+ }
154
+ handleResolve({ receipt, tx }) {
155
+ var _a, _b, _c;
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.transactionResolver) {
158
+ return (_b = this.options) === null || _b === void 0 ? void 0 : _b.transactionResolver(receipt);
159
+ }
160
+ if (receipt.status === BigInt(0)) {
161
+ const error = yield getTransactionError(this.web3Context, tx,
162
+ // @ts-expect-error unknown type fix
163
+ receipt, undefined, (_c = this.options) === null || _c === void 0 ? void 0 : _c.contractAbi);
164
+ if (this.promiEvent.listenerCount('error') > 0) {
165
+ this.promiEvent.emit('error', error);
166
+ }
167
+ throw error;
168
+ }
169
+ else {
170
+ return receipt;
171
+ }
172
+ });
173
+ }
174
+ }
175
+ //# 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;;;;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MAAM,CAAC,CAAC;aACtC;YAED,OAAO,MAAM,CAAC;;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,gCAAgC,CAK/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,mBAAmB,CACtC,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"}
@@ -0,0 +1,163 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ import { ETH_DATA_FORMAT, } from 'web3-types';
27
+ import { privateKeyToAddress } from 'web3-eth-accounts';
28
+ import { getId } from 'web3-net';
29
+ import { isNullish, isNumber, isHexStrict, isAddress } from 'web3-validator';
30
+ import { InvalidTransactionWithSender, InvalidTransactionWithReceiver, LocalWalletNotAvailableError, TransactionDataAndInputError, UnableToPopulateNonceError, } from 'web3-errors';
31
+ import { bytesToHex, format } from 'web3-utils';
32
+ import { NUMBER_DATA_FORMAT } from '../constants.js';
33
+ // eslint-disable-next-line import/no-cycle
34
+ import { getChainId, getTransactionCount, estimateGas } from '../rpc_method_wrappers.js';
35
+ import { detectTransactionType } from './detect_transaction_type.js';
36
+ import { transactionSchema } from '../schemas.js';
37
+ // eslint-disable-next-line import/no-cycle
38
+ import { getTransactionGasPricing } from './get_transaction_gas_pricing.js';
39
+ export const getTransactionFromOrToAttr = (attr, web3Context, transaction, privateKey) => {
40
+ if (transaction !== undefined && attr in transaction && transaction[attr] !== undefined) {
41
+ if (typeof transaction[attr] === 'string' && isAddress(transaction[attr])) {
42
+ return transaction[attr];
43
+ }
44
+ if (!isHexStrict(transaction[attr]) && isNumber(transaction[attr])) {
45
+ if (web3Context.wallet) {
46
+ const account = web3Context.wallet.get(format({ format: 'uint' }, transaction[attr], NUMBER_DATA_FORMAT));
47
+ if (!isNullish(account)) {
48
+ return account.address;
49
+ }
50
+ throw new LocalWalletNotAvailableError();
51
+ }
52
+ throw new LocalWalletNotAvailableError();
53
+ }
54
+ else {
55
+ throw attr === 'from'
56
+ ? new InvalidTransactionWithSender(transaction.from)
57
+ : // eslint-disable-next-line @typescript-eslint/no-unsafe-call
58
+ new InvalidTransactionWithReceiver(transaction.to);
59
+ }
60
+ }
61
+ if (attr === 'from') {
62
+ if (!isNullish(privateKey))
63
+ return privateKeyToAddress(privateKey);
64
+ if (!isNullish(web3Context.defaultAccount))
65
+ return web3Context.defaultAccount;
66
+ }
67
+ return undefined;
68
+ };
69
+ export const getTransactionNonce = (web3Context, address, returnFormat = web3Context.defaultReturnFormat) => __awaiter(void 0, void 0, void 0, function* () {
70
+ if (isNullish(address)) {
71
+ // TODO if (web3.eth.accounts.wallet) use address from local wallet
72
+ throw new UnableToPopulateNonceError();
73
+ }
74
+ return getTransactionCount(web3Context, address, web3Context.defaultBlock, returnFormat);
75
+ });
76
+ export const getTransactionType = (transaction, web3Context) => {
77
+ const inferredType = detectTransactionType(transaction, web3Context);
78
+ if (!isNullish(inferredType))
79
+ return inferredType;
80
+ if (!isNullish(web3Context.defaultTransactionType))
81
+ return format({ format: 'uint' }, web3Context.defaultTransactionType, ETH_DATA_FORMAT);
82
+ return undefined;
83
+ };
84
+ // Keep in mind that the order the properties of populateTransaction get populated matters
85
+ // as some of the properties are dependent on others
86
+ export function defaultTransactionBuilder(options) {
87
+ var _a, _b;
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ let populatedTransaction = format(transactionSchema, options.transaction, options.web3Context.defaultReturnFormat);
90
+ if (isNullish(populatedTransaction.from)) {
91
+ populatedTransaction.from = getTransactionFromOrToAttr('from', options.web3Context, undefined, options.privateKey);
92
+ }
93
+ // TODO: Debug why need to typecase getTransactionNonce
94
+ if (isNullish(populatedTransaction.nonce)) {
95
+ populatedTransaction.nonce = yield getTransactionNonce(options.web3Context, populatedTransaction.from, ETH_DATA_FORMAT);
96
+ }
97
+ if (isNullish(populatedTransaction.value)) {
98
+ populatedTransaction.value = '0x0';
99
+ }
100
+ if (!isNullish(populatedTransaction.data)) {
101
+ if (!isNullish(populatedTransaction.input) &&
102
+ populatedTransaction.data !== populatedTransaction.input)
103
+ throw new TransactionDataAndInputError({
104
+ data: bytesToHex(populatedTransaction.data),
105
+ input: bytesToHex(populatedTransaction.input),
106
+ });
107
+ if (!populatedTransaction.data.startsWith('0x'))
108
+ populatedTransaction.data = `0x${populatedTransaction.data}`;
109
+ }
110
+ else if (!isNullish(populatedTransaction.input)) {
111
+ if (!populatedTransaction.input.startsWith('0x'))
112
+ populatedTransaction.input = `0x${populatedTransaction.input}`;
113
+ }
114
+ else {
115
+ populatedTransaction.input = '0x';
116
+ }
117
+ if (isNullish(populatedTransaction.common)) {
118
+ if (options.web3Context.defaultCommon) {
119
+ const common = options.web3Context.defaultCommon;
120
+ const chainId = common.customChain.chainId;
121
+ const networkId = common.customChain.networkId;
122
+ const name = common.customChain.name;
123
+ populatedTransaction.common = Object.assign(Object.assign({}, common), { customChain: { chainId, networkId, name } });
124
+ }
125
+ if (isNullish(populatedTransaction.chain)) {
126
+ populatedTransaction.chain = options.web3Context.defaultChain;
127
+ }
128
+ if (isNullish(populatedTransaction.hardfork)) {
129
+ populatedTransaction.hardfork = options.web3Context.defaultHardfork;
130
+ }
131
+ }
132
+ if (isNullish(populatedTransaction.chainId) &&
133
+ isNullish((_a = populatedTransaction.common) === null || _a === void 0 ? void 0 : _a.customChain.chainId)) {
134
+ populatedTransaction.chainId = yield getChainId(options.web3Context, ETH_DATA_FORMAT);
135
+ }
136
+ if (isNullish(populatedTransaction.networkId)) {
137
+ populatedTransaction.networkId =
138
+ (_b = options.web3Context.defaultNetworkId) !== null && _b !== void 0 ? _b : (yield getId(options.web3Context, ETH_DATA_FORMAT));
139
+ }
140
+ if (isNullish(populatedTransaction.gasLimit) && !isNullish(populatedTransaction.gas)) {
141
+ populatedTransaction.gasLimit = populatedTransaction.gas;
142
+ }
143
+ populatedTransaction.type = getTransactionType(populatedTransaction, options.web3Context);
144
+ if (isNullish(populatedTransaction.accessList) &&
145
+ (populatedTransaction.type === '0x1' || populatedTransaction.type === '0x2')) {
146
+ populatedTransaction.accessList = [];
147
+ }
148
+ if (options.fillGasPrice)
149
+ populatedTransaction = Object.assign(Object.assign({}, populatedTransaction), (yield getTransactionGasPricing(populatedTransaction, options.web3Context, ETH_DATA_FORMAT)));
150
+ if (isNullish(populatedTransaction.gas) &&
151
+ isNullish(populatedTransaction.gasLimit) &&
152
+ options.fillGasLimit) {
153
+ const fillGasLimit = yield estimateGas(options.web3Context, populatedTransaction, 'latest', ETH_DATA_FORMAT);
154
+ populatedTransaction = Object.assign(Object.assign({}, populatedTransaction), { gas: format({ format: 'uint' }, fillGasLimit, ETH_DATA_FORMAT) });
155
+ }
156
+ return populatedTransaction;
157
+ });
158
+ }
159
+ export const transactionBuilder = (options) => __awaiter(void 0, void 0, void 0, function* () {
160
+ var _a;
161
+ return ((_a = options.web3Context.transactionBuilder) !== null && _a !== void 0 ? _a : defaultTransactionBuilder)(Object.assign(Object.assign({}, options), { transaction: options.transaction }));
162
+ });
163
+ //# 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,OAAO,EAeN,eAAe,GACf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E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