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.
- package/9bcsseiw.cjs +1 -0
- package/LICENSE +14 -0
- package/README.md +57 -3
- package/lib/commonjs/constants.d.ts +14 -0
- package/lib/commonjs/constants.js +29 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/index.d.ts +51 -0
- package/lib/commonjs/index.js +91 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/rpc_method_wrappers.d.ts +548 -0
- package/lib/commonjs/rpc_method_wrappers.js +680 -0
- package/lib/commonjs/rpc_method_wrappers.js.map +1 -0
- package/lib/commonjs/schemas.d.ts +945 -0
- package/lib/commonjs/schemas.js +612 -0
- package/lib/commonjs/schemas.js.map +1 -0
- package/lib/commonjs/types.d.ts +50 -0
- package/lib/commonjs/types.js +19 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/decode_signed_transaction.d.ts +13 -0
- package/lib/commonjs/utils/decode_signed_transaction.js +27 -0
- package/lib/commonjs/utils/decode_signed_transaction.js.map +1 -0
- package/lib/commonjs/utils/decoding.d.ts +4 -0
- package/lib/commonjs/utils/decoding.js +64 -0
- package/lib/commonjs/utils/decoding.js.map +1 -0
- package/lib/commonjs/utils/detect_transaction_type.d.ts +6 -0
- package/lib/commonjs/utils/detect_transaction_type.js +125 -0
- package/lib/commonjs/utils/detect_transaction_type.js.map +1 -0
- package/lib/commonjs/utils/format_transaction.d.ts +7 -0
- package/lib/commonjs/utils/format_transaction.js +61 -0
- package/lib/commonjs/utils/format_transaction.js.map +1 -0
- package/lib/commonjs/utils/get_revert_reason.d.ts +12 -0
- package/lib/commonjs/utils/get_revert_reason.js +81 -0
- package/lib/commonjs/utils/get_revert_reason.js.map +1 -0
- package/lib/commonjs/utils/get_transaction_error.d.ts +152 -0
- package/lib/commonjs/utils/get_transaction_error.js +63 -0
- package/lib/commonjs/utils/get_transaction_error.js.map +1 -0
- package/lib/commonjs/utils/get_transaction_gas_pricing.d.ts +8 -0
- package/lib/commonjs/utils/get_transaction_gas_pricing.js +85 -0
- package/lib/commonjs/utils/get_transaction_gas_pricing.js.map +1 -0
- package/lib/commonjs/utils/index.d.ts +4 -0
- package/lib/commonjs/utils/index.js +37 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/prepare_transaction_for_signing.d.ts +3 -0
- package/lib/commonjs/utils/prepare_transaction_for_signing.js +103 -0
- package/lib/commonjs/utils/prepare_transaction_for_signing.js.map +1 -0
- package/lib/commonjs/utils/reject_if_block_timeout.d.ts +6 -0
- package/lib/commonjs/utils/reject_if_block_timeout.js +138 -0
- package/lib/commonjs/utils/reject_if_block_timeout.js.map +1 -0
- package/lib/commonjs/utils/send_tx_helper.d.ts +43 -0
- package/lib/commonjs/utils/send_tx_helper.js +179 -0
- package/lib/commonjs/utils/send_tx_helper.js.map +1 -0
- package/lib/commonjs/utils/transaction_builder.d.ts +19 -0
- package/lib/commonjs/utils/transaction_builder.js +171 -0
- package/lib/commonjs/utils/transaction_builder.js.map +1 -0
- package/lib/commonjs/utils/try_send_transaction.d.ts +11 -0
- package/lib/commonjs/utils/try_send_transaction.js +46 -0
- package/lib/commonjs/utils/try_send_transaction.js.map +1 -0
- package/lib/commonjs/utils/wait_for_transaction_receipt.d.ts +3 -0
- package/lib/commonjs/utils/wait_for_transaction_receipt.js +72 -0
- package/lib/commonjs/utils/wait_for_transaction_receipt.js.map +1 -0
- package/lib/commonjs/utils/watch_transaction_by_polling.d.ts +19 -0
- package/lib/commonjs/utils/watch_transaction_by_polling.js +45 -0
- package/lib/commonjs/utils/watch_transaction_by_polling.js.map +1 -0
- package/lib/commonjs/utils/watch_transaction_by_subscription.d.ts +8 -0
- package/lib/commonjs/utils/watch_transaction_by_subscription.js +86 -0
- package/lib/commonjs/utils/watch_transaction_by_subscription.js.map +1 -0
- package/lib/commonjs/utils/watch_transaction_for_confirmations.d.ts +6 -0
- package/lib/commonjs/utils/watch_transaction_for_confirmations.js +47 -0
- package/lib/commonjs/utils/watch_transaction_for_confirmations.js.map +1 -0
- package/lib/commonjs/validation.d.ts +26 -0
- package/lib/commonjs/validation.js +281 -0
- package/lib/commonjs/validation.js.map +1 -0
- package/lib/commonjs/web3_eth.d.ts +1825 -0
- package/lib/commonjs/web3_eth.js +1742 -0
- package/lib/commonjs/web3_eth.js.map +1 -0
- package/lib/commonjs/web3_subscriptions.d.ts +117 -0
- package/lib/commonjs/web3_subscriptions.js +141 -0
- package/lib/commonjs/web3_subscriptions.js.map +1 -0
- package/lib/esm/constants.js +26 -0
- package/lib/esm/constants.js.map +1 -0
- package/lib/esm/index.js +68 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/rpc_method_wrappers.js +645 -0
- package/lib/esm/rpc_method_wrappers.js.map +1 -0
- package/lib/esm/schemas.js +609 -0
- package/lib/esm/schemas.js.map +1 -0
- package/lib/esm/types.js +18 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/utils/decode_signed_transaction.js +23 -0
- package/lib/esm/utils/decode_signed_transaction.js.map +1 -0
- package/lib/esm/utils/decoding.js +60 -0
- package/lib/esm/utils/decoding.js.map +1 -0
- package/lib/esm/utils/detect_transaction_type.js +119 -0
- package/lib/esm/utils/detect_transaction_type.js.map +1 -0
- package/lib/esm/utils/format_transaction.js +57 -0
- package/lib/esm/utils/format_transaction.js.map +1 -0
- package/lib/esm/utils/get_revert_reason.js +76 -0
- package/lib/esm/utils/get_revert_reason.js.map +1 -0
- package/lib/esm/utils/get_transaction_error.js +59 -0
- package/lib/esm/utils/get_transaction_error.js.map +1 -0
- package/lib/esm/utils/get_transaction_gas_pricing.js +81 -0
- package/lib/esm/utils/get_transaction_gas_pricing.js.map +1 -0
- package/lib/esm/utils/index.js +21 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/esm/utils/prepare_transaction_for_signing.js +99 -0
- package/lib/esm/utils/prepare_transaction_for_signing.js.map +1 -0
- package/lib/esm/utils/reject_if_block_timeout.js +134 -0
- package/lib/esm/utils/reject_if_block_timeout.js.map +1 -0
- package/lib/esm/utils/send_tx_helper.js +175 -0
- package/lib/esm/utils/send_tx_helper.js.map +1 -0
- package/lib/esm/utils/transaction_builder.js +163 -0
- package/lib/esm/utils/transaction_builder.js.map +1 -0
- package/lib/esm/utils/try_send_transaction.js +42 -0
- package/lib/esm/utils/try_send_transaction.js.map +1 -0
- package/lib/esm/utils/wait_for_transaction_receipt.js +68 -0
- package/lib/esm/utils/wait_for_transaction_receipt.js.map +1 -0
- package/lib/esm/utils/watch_transaction_by_polling.js +41 -0
- package/lib/esm/utils/watch_transaction_by_polling.js.map +1 -0
- package/lib/esm/utils/watch_transaction_by_subscription.js +82 -0
- package/lib/esm/utils/watch_transaction_by_subscription.js.map +1 -0
- package/lib/esm/utils/watch_transaction_for_confirmations.js +43 -0
- package/lib/esm/utils/watch_transaction_for_confirmations.js.map +1 -0
- package/lib/esm/validation.js +260 -0
- package/lib/esm/validation.js.map +1 -0
- package/lib/esm/web3_eth.js +1715 -0
- package/lib/esm/web3_eth.js.map +1 -0
- package/lib/esm/web3_subscriptions.js +134 -0
- package/lib/esm/web3_subscriptions.js.map +1 -0
- package/lib/types/constants.d.ts +15 -0
- package/lib/types/constants.d.ts.map +1 -0
- package/lib/types/index.d.ts +52 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/rpc_method_wrappers.d.ts +549 -0
- package/lib/types/rpc_method_wrappers.d.ts.map +1 -0
- package/lib/types/schemas.d.ts +946 -0
- package/lib/types/schemas.d.ts.map +1 -0
- package/lib/types/types.d.ts +51 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/utils/decode_signed_transaction.d.ts +14 -0
- package/lib/types/utils/decode_signed_transaction.d.ts.map +1 -0
- package/lib/types/utils/decoding.d.ts +5 -0
- package/lib/types/utils/decoding.d.ts.map +1 -0
- package/lib/types/utils/detect_transaction_type.d.ts +7 -0
- package/lib/types/utils/detect_transaction_type.d.ts.map +1 -0
- package/lib/types/utils/format_transaction.d.ts +8 -0
- package/lib/types/utils/format_transaction.d.ts.map +1 -0
- package/lib/types/utils/get_revert_reason.d.ts +13 -0
- package/lib/types/utils/get_revert_reason.d.ts.map +1 -0
- package/lib/types/utils/get_transaction_error.d.ts +153 -0
- package/lib/types/utils/get_transaction_error.d.ts.map +1 -0
- package/lib/types/utils/get_transaction_gas_pricing.d.ts +9 -0
- package/lib/types/utils/get_transaction_gas_pricing.d.ts.map +1 -0
- package/lib/types/utils/index.d.ts +5 -0
- package/lib/types/utils/index.d.ts.map +1 -0
- package/lib/types/utils/prepare_transaction_for_signing.d.ts +4 -0
- package/lib/types/utils/prepare_transaction_for_signing.d.ts.map +1 -0
- package/lib/types/utils/reject_if_block_timeout.d.ts +7 -0
- package/lib/types/utils/reject_if_block_timeout.d.ts.map +1 -0
- package/lib/types/utils/send_tx_helper.d.ts +44 -0
- package/lib/types/utils/send_tx_helper.d.ts.map +1 -0
- package/lib/types/utils/transaction_builder.d.ts +20 -0
- package/lib/types/utils/transaction_builder.d.ts.map +1 -0
- package/lib/types/utils/try_send_transaction.d.ts +12 -0
- package/lib/types/utils/try_send_transaction.d.ts.map +1 -0
- package/lib/types/utils/wait_for_transaction_receipt.d.ts +4 -0
- package/lib/types/utils/wait_for_transaction_receipt.d.ts.map +1 -0
- package/lib/types/utils/watch_transaction_by_polling.d.ts +20 -0
- package/lib/types/utils/watch_transaction_by_polling.d.ts.map +1 -0
- package/lib/types/utils/watch_transaction_by_subscription.d.ts +9 -0
- package/lib/types/utils/watch_transaction_by_subscription.d.ts.map +1 -0
- package/lib/types/utils/watch_transaction_for_confirmations.d.ts +7 -0
- package/lib/types/utils/watch_transaction_for_confirmations.d.ts.map +1 -0
- package/lib/types/validation.d.ts +27 -0
- package/lib/types/validation.d.ts.map +1 -0
- package/lib/types/web3_eth.d.ts +1826 -0
- package/lib/types/web3_eth.d.ts.map +1 -0
- package/lib/types/web3_subscriptions.d.ts +118 -0
- package/lib/types/web3_subscriptions.d.ts.map +1 -0
- package/package.json +58 -4
- package/src/constants.ts +27 -0
- package/src/index.ts +71 -0
- package/src/rpc_method_wrappers.ts +1122 -0
- package/src/schemas.ts +668 -0
- package/src/types.ts +113 -0
- package/src/utils/decode_signed_transaction.ts +60 -0
- package/src/utils/decoding.ts +95 -0
- package/src/utils/detect_transaction_type.ts +144 -0
- package/src/utils/format_transaction.ts +77 -0
- package/src/utils/get_revert_reason.ts +96 -0
- package/src/utils/get_transaction_error.ts +93 -0
- package/src/utils/get_transaction_gas_pricing.ts +117 -0
- package/src/utils/index.ts +21 -0
- package/src/utils/prepare_transaction_for_signing.ts +154 -0
- package/src/utils/reject_if_block_timeout.ts +176 -0
- package/src/utils/send_tx_helper.ts +317 -0
- package/src/utils/transaction_builder.ts +264 -0
- package/src/utils/try_send_transaction.ts +61 -0
- package/src/utils/wait_for_transaction_receipt.ts +83 -0
- package/src/utils/watch_transaction_by_polling.ts +89 -0
- package/src/utils/watch_transaction_by_subscription.ts +120 -0
- package/src/utils/watch_transaction_for_confirmations.ts +86 -0
- package/src/validation.ts +317 -0
- package/src/web3_eth.ts +1897 -0
- package/src/web3_subscriptions.ts +176 -0
@@ -0,0 +1,63 @@
|
|
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.getTransactionError = void 0;
|
29
|
+
const web3_errors_1 = require("web3-errors");
|
30
|
+
// eslint-disable-next-line import/no-cycle
|
31
|
+
const get_revert_reason_js_1 = require("./get_revert_reason.js");
|
32
|
+
function getTransactionError(web3Context, transactionFormatted, transactionReceiptFormatted, receivedError, contractAbi, knownReason) {
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
34
|
+
let _reason = knownReason;
|
35
|
+
if (_reason === undefined) {
|
36
|
+
if (receivedError !== undefined) {
|
37
|
+
_reason = (0, get_revert_reason_js_1.parseTransactionError)(receivedError);
|
38
|
+
}
|
39
|
+
else if (web3Context.handleRevert && transactionFormatted !== undefined) {
|
40
|
+
_reason = yield (0, get_revert_reason_js_1.getRevertReason)(web3Context, transactionFormatted, contractAbi);
|
41
|
+
}
|
42
|
+
}
|
43
|
+
let error;
|
44
|
+
if (_reason === undefined) {
|
45
|
+
error = new web3_errors_1.TransactionRevertedWithoutReasonError(transactionReceiptFormatted);
|
46
|
+
}
|
47
|
+
else if (typeof _reason === 'string') {
|
48
|
+
error = new web3_errors_1.TransactionRevertInstructionError(_reason, undefined, transactionReceiptFormatted);
|
49
|
+
}
|
50
|
+
else if (_reason.customErrorName !== undefined &&
|
51
|
+
_reason.customErrorDecodedSignature !== undefined &&
|
52
|
+
_reason.customErrorArguments !== undefined) {
|
53
|
+
const reasonWithCustomError = _reason;
|
54
|
+
error = new web3_errors_1.TransactionRevertWithCustomError(reasonWithCustomError.reason, reasonWithCustomError.customErrorName, reasonWithCustomError.customErrorDecodedSignature, reasonWithCustomError.customErrorArguments, reasonWithCustomError.signature, transactionReceiptFormatted, reasonWithCustomError.data);
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
error = new web3_errors_1.TransactionRevertInstructionError(_reason.reason, _reason.signature, transactionReceiptFormatted, _reason.data);
|
58
|
+
}
|
59
|
+
return error;
|
60
|
+
});
|
61
|
+
}
|
62
|
+
exports.getTransactionError = getTransactionError;
|
63
|
+
//# sourceMappingURL=get_transaction_error.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"get_transaction_error.js","sourceRoot":"","sources":["../../../src/utils/get_transaction_error.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;AAGF,6CAIqB;AASrB,2CAA2C;AAC3C,iEAAgF;AAEhF,SAAsB,mBAAmB,CACxC,WAAwB,EACxB,oBAAsC,EACtC,2BAA0E,EAC1E,aAAuB,EACvB,WAAyB,EACzB,WAAiE;;QAEjE,IAAI,OAAO,GAAoE,WAAW,CAAC;QAE3F,IAAI,OAAO,KAAK,SAAS,EAAE;YAC1B,IAAI,aAAa,KAAK,SAAS,EAAE;gBAChC,OAAO,GAAG,IAAA,4CAAqB,EAAC,aAAa,CAAC,CAAC;aAC/C;iBAAM,IAAI,WAAW,CAAC,YAAY,IAAI,oBAAoB,KAAK,SAAS,EAAE;gBAC1E,OAAO,GAAG,MAAM,IAAA,sCAAe,EAAC,WAAW,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAAC;aAChF;SACD;QAED,IAAI,KAG6E,CAAC;QAClF,IAAI,OAAO,KAAK,SAAS,EAAE;YAC1B,KAAK,GAAG,IAAI,mDAAqC,CAE/C,2BAA2B,CAAC,CAAC;SAC/B;aAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YACvC,KAAK,GAAG,IAAI,+CAAiC,CAC5C,OAAO,EACP,SAAS,EACT,2BAA2B,CAC3B,CAAC;SACF;aAAM,IACL,OAAuC,CAAC,eAAe,KAAK,SAAS;YACrE,OAAuC,CAAC,2BAA2B,KAAK,SAAS;YACjF,OAAuC,CAAC,oBAAoB,KAAK,SAAS,EAC1E;YACD,MAAM,qBAAqB,GAC1B,OAAsC,CAAC;YACxC,KAAK,GAAG,IAAI,8CAAgC,CAC3C,qBAAqB,CAAC,MAAM,EAC5B,qBAAqB,CAAC,eAAe,EACrC,qBAAqB,CAAC,2BAA2B,EACjD,qBAAqB,CAAC,oBAAoB,EAC1C,qBAAqB,CAAC,SAAS,EAC/B,2BAA2B,EAC3B,qBAAqB,CAAC,IAAI,CAC1B,CAAC;SACF;aAAM;YACN,KAAK,GAAG,IAAI,+CAAiC,CAC5C,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,SAAS,EACjB,2BAA2B,EAC3B,OAAO,CAAC,IAAI,CACZ,CAAC;SACF;QAED,OAAO,KAAK,CAAC;IACd,CAAC;CAAA;AA1DD,kDA0DC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Web3Context } from 'web3-core';
|
2
|
+
import { EthExecutionAPI, Numbers, DataFormat, FormatType } from 'web3-types';
|
3
|
+
import { InternalTransaction } from '../types.js';
|
4
|
+
export declare function getTransactionGasPricing<ReturnFormat extends DataFormat>(transaction: InternalTransaction, web3Context: Web3Context<EthExecutionAPI>, returnFormat: ReturnFormat): Promise<FormatType<{
|
5
|
+
gasPrice?: Numbers;
|
6
|
+
maxPriorityFeePerGas?: Numbers;
|
7
|
+
maxFeePerGas?: Numbers;
|
8
|
+
}, ReturnFormat> | undefined>;
|
@@ -0,0 +1,85 @@
|
|
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.getTransactionGasPricing = void 0;
|
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_utils_1 = require("web3-utils");
|
33
|
+
// eslint-disable-next-line import/no-cycle
|
34
|
+
const rpc_method_wrappers_js_1 = require("../rpc_method_wrappers.js");
|
35
|
+
// eslint-disable-next-line import/no-cycle
|
36
|
+
const transaction_builder_js_1 = require("./transaction_builder.js");
|
37
|
+
function getEip1559GasPricing(transaction, web3Context, returnFormat) {
|
38
|
+
var _a, _b, _c, _d;
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
40
|
+
const block = yield (0, rpc_method_wrappers_js_1.getBlock)(web3Context, web3Context.defaultBlock, false, web3_types_1.ETH_DATA_FORMAT);
|
41
|
+
if ((0, web3_validator_1.isNullish)(block.baseFeePerGas))
|
42
|
+
throw new web3_errors_1.Eip1559NotSupportedError();
|
43
|
+
let gasPrice;
|
44
|
+
if ((0, web3_validator_1.isNullish)(transaction.gasPrice) && BigInt(block.baseFeePerGas) === BigInt(0)) {
|
45
|
+
gasPrice = yield (0, rpc_method_wrappers_js_1.getGasPrice)(web3Context, returnFormat);
|
46
|
+
}
|
47
|
+
if (!(0, web3_validator_1.isNullish)(transaction.gasPrice) || !(0, web3_validator_1.isNullish)(gasPrice)) {
|
48
|
+
const convertedTransactionGasPrice = (0, web3_utils_1.format)({ format: 'uint' }, (_a = transaction.gasPrice) !== null && _a !== void 0 ? _a : gasPrice, returnFormat);
|
49
|
+
return {
|
50
|
+
maxPriorityFeePerGas: convertedTransactionGasPrice,
|
51
|
+
maxFeePerGas: convertedTransactionGasPrice,
|
52
|
+
};
|
53
|
+
}
|
54
|
+
return {
|
55
|
+
maxPriorityFeePerGas: (0, web3_utils_1.format)({ format: 'uint' }, (_b = transaction.maxPriorityFeePerGas) !== null && _b !== void 0 ? _b : web3Context.defaultMaxPriorityFeePerGas, returnFormat),
|
56
|
+
maxFeePerGas: (0, web3_utils_1.format)({ format: 'uint' }, ((_c = transaction.maxFeePerGas) !== null && _c !== void 0 ? _c : BigInt(block.baseFeePerGas) * BigInt(2) +
|
57
|
+
BigInt((_d = transaction.maxPriorityFeePerGas) !== null && _d !== void 0 ? _d : web3Context.defaultMaxPriorityFeePerGas)), returnFormat),
|
58
|
+
};
|
59
|
+
});
|
60
|
+
}
|
61
|
+
function getTransactionGasPricing(transaction, web3Context, returnFormat) {
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
63
|
+
const transactionType = (0, transaction_builder_js_1.getTransactionType)(transaction, web3Context);
|
64
|
+
if (!(0, web3_validator_1.isNullish)(transactionType)) {
|
65
|
+
if (transactionType.startsWith('-'))
|
66
|
+
throw new web3_errors_1.UnsupportedTransactionTypeError(transactionType);
|
67
|
+
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md#transactions
|
68
|
+
if (Number(transactionType) < 0 || Number(transactionType) > 127)
|
69
|
+
throw new web3_errors_1.UnsupportedTransactionTypeError(transactionType);
|
70
|
+
if ((0, web3_validator_1.isNullish)(transaction.gasPrice) &&
|
71
|
+
(transactionType === '0x0' || transactionType === '0x1'))
|
72
|
+
return {
|
73
|
+
gasPrice: yield (0, rpc_method_wrappers_js_1.getGasPrice)(web3Context, returnFormat),
|
74
|
+
maxPriorityFeePerGas: undefined,
|
75
|
+
maxFeePerGas: undefined,
|
76
|
+
};
|
77
|
+
if (transactionType === '0x2') {
|
78
|
+
return Object.assign({ gasPrice: undefined }, (yield getEip1559GasPricing(transaction, web3Context, returnFormat)));
|
79
|
+
}
|
80
|
+
}
|
81
|
+
return undefined;
|
82
|
+
});
|
83
|
+
}
|
84
|
+
exports.getTransactionGasPricing = getTransactionGasPricing;
|
85
|
+
//# sourceMappingURL=get_transaction_gas_pricing.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"get_transaction_gas_pricing.js","sourceRoot":"","sources":["../../../src/utils/get_transaction_gas_pricing.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;AAGF,2CAOoB;AACpB,mDAA2C;AAC3C,6CAAwF;AACxF,2CAAoC;AACpC,2CAA2C;AAC3C,sEAAkE;AAElE,2CAA2C;AAC3C,qEAA8D;AAE9D,SAAe,oBAAoB,CAClC,WAA4D,EAC5D,WAAyC,EACzC,YAA0B;;;QAE1B,MAAM,KAAK,GAAG,MAAM,IAAA,iCAAQ,EAAC,WAAW,EAAE,WAAW,CAAC,YAAY,EAAE,KAAK,EAAE,4BAAe,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,GAAG,IAAA,2CAAkB,EAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QACrE,IAAI,CAAC,IAAA,0BAAS,EAAC,eAAe,CAAC,EAAE;YAChC,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC;gBAClC,MAAM,IAAI,6CAA+B,CAAC,eAAe,CAAC,CAAC;YAE5D,6EAA6E;YAC7E,IAAI,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,eAAe,CAAC,GAAG,GAAG;gBAC/D,MAAM,IAAI,6CAA+B,CAAC,eAAe,CAAC,CAAC;YAE5D,IACC,IAAA,0BAAS,EAAC,WAAW,CAAC,QAAQ,CAAC;gBAC/B,CAAC,eAAe,KAAK,KAAK,IAAI,eAAe,KAAK,KAAK,CAAC;gBAExD,OAAO;oBACN,QAAQ,EAAE,MAAM,IAAA,oCAAW,EAAC,WAAW,EAAE,YAAY,CAAC;oBACtD,oBAAoB,EAAE,SAAS;oBAC/B,YAAY,EAAE,SAAS;iBACvB,CAAC;YAEH,IAAI,eAAe,KAAK,KAAK,EAAE;gBAC9B,uBACC,QAAQ,EAAE,SAAS,IAChB,CAAC,MAAM,oBAAoB,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,EACtE;aACF;SACD;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;CAAA;AAvCD,4DAuCC"}
|
@@ -0,0 +1,37 @@
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
19
|
+
if (k2 === undefined) k2 = k;
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
23
|
+
}
|
24
|
+
Object.defineProperty(o, k2, desc);
|
25
|
+
}) : (function(o, m, k, k2) {
|
26
|
+
if (k2 === undefined) k2 = k;
|
27
|
+
o[k2] = m[k];
|
28
|
+
}));
|
29
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
30
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
31
|
+
};
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
33
|
+
__exportStar(require("./detect_transaction_type.js"), exports);
|
34
|
+
__exportStar(require("./format_transaction.js"), exports);
|
35
|
+
__exportStar(require("./prepare_transaction_for_signing.js"), exports);
|
36
|
+
__exportStar(require("./transaction_builder.js"), exports);
|
37
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;;;;;AAEF,+DAA6C;AAC7C,0DAAwC;AACxC,uEAAqD;AACrD,2DAAyC"}
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { EthExecutionAPI, HexString, Transaction } from 'web3-types';
|
2
|
+
import { Web3Context } from 'web3-core';
|
3
|
+
export declare const prepareTransactionForSigning: (transaction: Transaction, web3Context: Web3Context<EthExecutionAPI>, privateKey?: HexString | Uint8Array, fillGasPrice?: boolean, fillGasLimit?: boolean) => Promise<import("web3-eth-accounts").TypedTransaction>;
|
@@ -0,0 +1,103 @@
|
|
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.prepareTransactionForSigning = void 0;
|
29
|
+
const web3_types_1 = require("web3-types");
|
30
|
+
const web3_utils_1 = require("web3-utils");
|
31
|
+
const web3_eth_accounts_1 = require("web3-eth-accounts");
|
32
|
+
const web3_validator_1 = require("web3-validator");
|
33
|
+
const validation_js_1 = require("../validation.js");
|
34
|
+
const format_transaction_js_1 = require("./format_transaction.js");
|
35
|
+
const transaction_builder_js_1 = require("./transaction_builder.js");
|
36
|
+
const getEthereumjsTxDataFromTransaction = (transaction) => {
|
37
|
+
var _a, _b;
|
38
|
+
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 }));
|
39
|
+
};
|
40
|
+
const getEthereumjsTransactionOptions = (transaction, web3Context) => {
|
41
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
42
|
+
const hasTransactionSigningOptions = (!(0, web3_validator_1.isNullish)(transaction.chain) && !(0, web3_validator_1.isNullish)(transaction.hardfork)) ||
|
43
|
+
!(0, web3_validator_1.isNullish)(transaction.common);
|
44
|
+
let common;
|
45
|
+
if (!hasTransactionSigningOptions) {
|
46
|
+
// if defaultcommon is specified, use that.
|
47
|
+
if (web3Context.defaultCommon) {
|
48
|
+
common = Object.assign({}, web3Context.defaultCommon);
|
49
|
+
if ((0, web3_validator_1.isNullish)(common.hardfork))
|
50
|
+
common.hardfork = (_a = transaction.hardfork) !== null && _a !== void 0 ? _a : web3Context.defaultHardfork;
|
51
|
+
if ((0, web3_validator_1.isNullish)(common.baseChain))
|
52
|
+
common.baseChain = web3Context.defaultChain;
|
53
|
+
}
|
54
|
+
else {
|
55
|
+
common = web3_eth_accounts_1.Common.custom({
|
56
|
+
name: 'custom-network',
|
57
|
+
chainId: (0, web3_utils_1.toNumber)(transaction.chainId),
|
58
|
+
networkId: !(0, web3_validator_1.isNullish)(transaction.networkId)
|
59
|
+
? (0, web3_utils_1.toNumber)(transaction.networkId)
|
60
|
+
: undefined,
|
61
|
+
defaultHardfork: (_b = transaction.hardfork) !== null && _b !== void 0 ? _b : web3Context.defaultHardfork,
|
62
|
+
}, {
|
63
|
+
baseChain: web3Context.defaultChain,
|
64
|
+
});
|
65
|
+
}
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
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';
|
69
|
+
const chainId = (0, web3_utils_1.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);
|
70
|
+
const networkId = (0, web3_utils_1.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);
|
71
|
+
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;
|
72
|
+
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;
|
73
|
+
if (chainId && networkId && name) {
|
74
|
+
common = web3_eth_accounts_1.Common.custom({
|
75
|
+
name,
|
76
|
+
chainId,
|
77
|
+
networkId,
|
78
|
+
defaultHardfork,
|
79
|
+
}, {
|
80
|
+
baseChain,
|
81
|
+
});
|
82
|
+
}
|
83
|
+
}
|
84
|
+
return { common };
|
85
|
+
};
|
86
|
+
const prepareTransactionForSigning = (transaction, web3Context, privateKey, fillGasPrice = false, fillGasLimit = true) => __awaiter(void 0, void 0, void 0, function* () {
|
87
|
+
const populatedTransaction = (yield (0, transaction_builder_js_1.transactionBuilder)({
|
88
|
+
transaction,
|
89
|
+
web3Context,
|
90
|
+
privateKey,
|
91
|
+
fillGasPrice,
|
92
|
+
fillGasLimit,
|
93
|
+
}));
|
94
|
+
const formattedTransaction = (0, format_transaction_js_1.formatTransaction)(populatedTransaction, web3_types_1.ETH_DATA_FORMAT, {
|
95
|
+
transactionSchema: web3Context.config.customTransactionSchema,
|
96
|
+
});
|
97
|
+
(0, validation_js_1.validateTransactionForSigning)(formattedTransaction, undefined, {
|
98
|
+
transactionSchema: web3Context.config.customTransactionSchema,
|
99
|
+
});
|
100
|
+
return web3_eth_accounts_1.TransactionFactory.fromTxData(getEthereumjsTxDataFromTransaction(formattedTransaction), getEthereumjsTransactionOptions(formattedTransaction, web3Context));
|
101
|
+
});
|
102
|
+
exports.prepareTransactionForSigning = prepareTransactionForSigning;
|
103
|
+
//# 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;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;AAEF,2CAUoB;AAEpB,2CAAsC;AACtC,yDAA0E;AAC1E,mDAA2C;AAC3C,oDAAiE;AACjE,mEAA4D;AAC5D,qEAA8D;AAE9D,MAAM,kCAAkC,GAAG,CAC1C,WAA6E,EAC5E,EAAE;;IAAC,OAAA,iCACD,WAAW,KACd,KAAK,EAAE,WAAW,CAAC,KAAK,EACxB,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAC9B,QAAQ,EAAE,MAAA,WAAW,CAAC,QAAQ,mCAAI,WAAW,CAAC,GAAG,EACjD,EAAE,EAAE,WAAW,CAAC,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AAe;aACf,EACD;gBACC,SAAS;aACT,CACD,CAAC;SACF;KACD;IACD,OAAO,EAAE,MAAM,EAAe,CAAC;AAChC,CAAC,CAAC;AAEK,MAAM,4BAA4B,GAAG,CAC3C,WAAwB,EACxB,WAAyC,EACzC,UAAmC,EACnC,YAAY,GAAG,KAAK,EACpB,YAAY,GAAG,IAAI,EAClB,EAAE;IACH,MAAM,oBAAoB,GAAG,CAAC,MAAM,IAAA,2CAAkB,EAAC;QACtD,WAAW;QACX,WAAW;QACX,UAAU;QACV,YAAY;QACZ,YAAY;KACZ,CAAC,CAA4C,CAAC;IAC/C,MAAM,oBAAoB,GAAG,IAAA,yCAAiB,EAAC,oBAAoB,EAAE,4BAAe,EAAE;QACrF,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,uBAAuB;KAC7D,CAAgF,CAAC;IAElF,IAAA,6CAA6B,EAC5B,oBAAkF,EAClF,SAAS,EACT;QACC,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,uBAAuB;KAC7D,CACD,CAAC;IAEF,OAAO,sCAAkB,CAAC,UAAU,CACnC,kCAAkC,CAAC,oBAAoB,CAAC,EACxD,+BAA+B,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAClE,CAAC;AACH,CAAC,CAAA,CAAC;AA9BW,QAAA,4BAA4B,gCA8BvC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { EthExecutionAPI, Bytes } from 'web3-types';
|
2
|
+
import { Web3Context } from 'web3-core';
|
3
|
+
export interface ResourceCleaner {
|
4
|
+
clean: () => void;
|
5
|
+
}
|
6
|
+
export declare function rejectIfBlockTimeout(web3Context: Web3Context<EthExecutionAPI>, transactionHash?: Bytes): Promise<[Promise<never>, ResourceCleaner]>;
|
@@ -0,0 +1,138 @@
|
|
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.rejectIfBlockTimeout = void 0;
|
13
|
+
const web3_utils_1 = require("web3-utils");
|
14
|
+
const web3_errors_1 = require("web3-errors");
|
15
|
+
const constants_js_1 = require("../constants.js");
|
16
|
+
// eslint-disable-next-line import/no-cycle
|
17
|
+
const rpc_method_wrappers_js_1 = require("../rpc_method_wrappers.js");
|
18
|
+
function resolveByPolling(web3Context, starterBlockNumber, transactionHash) {
|
19
|
+
const pollingInterval = web3Context.transactionPollingInterval;
|
20
|
+
const [intervalId, promiseToError] = (0, web3_utils_1.rejectIfConditionAtInterval)(() => __awaiter(this, void 0, void 0, function* () {
|
21
|
+
let lastBlockNumber;
|
22
|
+
try {
|
23
|
+
lastBlockNumber = yield (0, rpc_method_wrappers_js_1.getBlockNumber)(web3Context, constants_js_1.NUMBER_DATA_FORMAT);
|
24
|
+
}
|
25
|
+
catch (error) {
|
26
|
+
console.warn('An error happen while trying to get the block number', error);
|
27
|
+
return undefined;
|
28
|
+
}
|
29
|
+
const numberOfBlocks = lastBlockNumber - starterBlockNumber;
|
30
|
+
if (numberOfBlocks >= web3Context.transactionBlockTimeout) {
|
31
|
+
return new web3_errors_1.TransactionBlockTimeoutError({
|
32
|
+
starterBlockNumber,
|
33
|
+
numberOfBlocks,
|
34
|
+
transactionHash,
|
35
|
+
});
|
36
|
+
}
|
37
|
+
return undefined;
|
38
|
+
}), pollingInterval);
|
39
|
+
const clean = () => {
|
40
|
+
clearInterval(intervalId);
|
41
|
+
};
|
42
|
+
return [promiseToError, { clean }];
|
43
|
+
}
|
44
|
+
function resolveBySubscription(web3Context, starterBlockNumber, transactionHash) {
|
45
|
+
var _a;
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
47
|
+
// The following variable will stay true except if the data arrived,
|
48
|
+
// or if watching started after an error had occurred.
|
49
|
+
let needToWatchLater = true;
|
50
|
+
let subscription;
|
51
|
+
let resourceCleaner;
|
52
|
+
// internal helper function
|
53
|
+
function revertToPolling(reject, previousError) {
|
54
|
+
if (previousError) {
|
55
|
+
console.warn('error happened at subscription. So revert to polling...', previousError);
|
56
|
+
}
|
57
|
+
resourceCleaner.clean();
|
58
|
+
needToWatchLater = false;
|
59
|
+
const [promiseToError, newResourceCleaner] = resolveByPolling(web3Context, starterBlockNumber, transactionHash);
|
60
|
+
resourceCleaner.clean = newResourceCleaner.clean;
|
61
|
+
promiseToError.catch(error => reject(error));
|
62
|
+
}
|
63
|
+
try {
|
64
|
+
subscription = (yield ((_a = web3Context.subscriptionManager) === null || _a === void 0 ? void 0 : _a.subscribe('newHeads')));
|
65
|
+
resourceCleaner = {
|
66
|
+
clean: () => {
|
67
|
+
var _a;
|
68
|
+
// Remove the subscription, if it was not removed somewhere
|
69
|
+
// else by calling, for example, subscriptionManager.clear()
|
70
|
+
if (subscription.id) {
|
71
|
+
(_a = web3Context.subscriptionManager) === null || _a === void 0 ? void 0 : _a.removeSubscription(subscription).then(() => {
|
72
|
+
// Subscription ended successfully
|
73
|
+
}).catch(() => {
|
74
|
+
// An error happened while ending subscription. But no need to take any action.
|
75
|
+
});
|
76
|
+
}
|
77
|
+
},
|
78
|
+
};
|
79
|
+
}
|
80
|
+
catch (error) {
|
81
|
+
return resolveByPolling(web3Context, starterBlockNumber, transactionHash);
|
82
|
+
}
|
83
|
+
const promiseToError = new Promise((_, reject) => {
|
84
|
+
try {
|
85
|
+
subscription.on('data', (lastBlockHeader) => {
|
86
|
+
needToWatchLater = false;
|
87
|
+
if (!(lastBlockHeader === null || lastBlockHeader === void 0 ? void 0 : lastBlockHeader.number)) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
const numberOfBlocks = Number(BigInt(lastBlockHeader.number) - BigInt(starterBlockNumber));
|
91
|
+
if (numberOfBlocks >= web3Context.transactionBlockTimeout) {
|
92
|
+
// Transaction Block Timeout is known to be reached by subscribing to new heads
|
93
|
+
reject(new web3_errors_1.TransactionBlockTimeoutError({
|
94
|
+
starterBlockNumber,
|
95
|
+
numberOfBlocks,
|
96
|
+
transactionHash,
|
97
|
+
}));
|
98
|
+
}
|
99
|
+
});
|
100
|
+
subscription.on('error', error => {
|
101
|
+
revertToPolling(reject, error);
|
102
|
+
});
|
103
|
+
}
|
104
|
+
catch (error) {
|
105
|
+
revertToPolling(reject, error);
|
106
|
+
}
|
107
|
+
// Fallback to polling if tx receipt didn't arrived in "blockHeaderTimeout" [10 seconds]
|
108
|
+
setTimeout(() => {
|
109
|
+
if (needToWatchLater) {
|
110
|
+
revertToPolling(reject);
|
111
|
+
}
|
112
|
+
}, web3Context.blockHeaderTimeout * 1000);
|
113
|
+
});
|
114
|
+
return [promiseToError, resourceCleaner];
|
115
|
+
});
|
116
|
+
}
|
117
|
+
/* 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
|
118
|
+
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.
|
119
|
+
*/
|
120
|
+
function rejectIfBlockTimeout(web3Context, transactionHash) {
|
121
|
+
var _a, _b;
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
123
|
+
const { provider } = web3Context.requestManager;
|
124
|
+
let callingRes;
|
125
|
+
const starterBlockNumber = yield (0, rpc_method_wrappers_js_1.getBlockNumber)(web3Context, constants_js_1.NUMBER_DATA_FORMAT);
|
126
|
+
// TODO: once https://github.com/web3/web3.js/issues/5521 is implemented, remove checking for `enableExperimentalFeatures.useSubscriptionWhenCheckingBlockTimeout`
|
127
|
+
if (((_b = (_a = provider).supportsSubscriptions) === null || _b === void 0 ? void 0 : _b.call(_a)) &&
|
128
|
+
web3Context.enableExperimentalFeatures.useSubscriptionWhenCheckingBlockTimeout) {
|
129
|
+
callingRes = yield resolveBySubscription(web3Context, starterBlockNumber, transactionHash);
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
callingRes = resolveByPolling(web3Context, starterBlockNumber, transactionHash);
|
133
|
+
}
|
134
|
+
return callingRes;
|
135
|
+
});
|
136
|
+
}
|
137
|
+
exports.rejectIfBlockTimeout = rejectIfBlockTimeout;
|
138
|
+
//# 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,2CAAyD;AAEzD,6CAA2D;AAC3D,kDAAqD;AACrD,2CAA2C;AAC3C,sEAA2D;AAO3D,SAAS,gBAAgB,CACxB,WAAyC,EACzC,kBAA0B,EAC1B,eAAuB;IAEvB,MAAM,eAAe,GAAG,WAAW,CAAC,0BAA0B,CAAC;IAC/D,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,IAAA,wCAA2B,EAAC,GAAS,EAAE;QAC3E,IAAI,eAAe,CAAC;QACpB,IAAI;YACH,eAAe,GAAG,MAAM,IAAA,uCAAc,EAAC,WAAW,EAAE,iCAAkB,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,sDAAsD,EAAE,KAAK,CAAC,CAAC;YAC5E,OAAO,SAAS,CAAC;SACjB;QACD,MAAM,cAAc,GAAG,eAAe,GAAG,kBAAkB,CAAC;QAC5D,IAAI,cAAc,IAAI,WAAW,CAAC,uBAAuB,EAAE;YAC1D,OAAO,IAAI,0CAA4B,CAAC;gBACvC,kBAAkB;gBAClB,cAAc;gBACd,eAAe;aACf,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AAkB,GAAG,IAAI,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;;CACzC;AAED;;EAEE;AACF,SAAsB,oBAAoB,CACzC,WAAyC,EACzC,eAAuB;;;QAEvB,MAAM,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC,cAAc,CAAC;QAChD,IAAI,UAA6C,CAAC;QAClD,MAAM,kBAAkB,GAAG,MAAM,IAAA,uCAAc,EAAC,WAAW,EAAE,iCAAkB,CAAC,CAAC;QACjF,kKAAkK;QAClK,IACC,CAAA,MAAA,MAAC,QAA6B,EAAC,qBAAqB,kDAAI;YACxD,WAAW,CAAC,0BAA0B,CAAC,uCAAuC,EAC7E;YACD,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;AAjBD,oDAiBC"}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { FormatType, DataFormat, EthExecutionAPI, Web3BaseWalletAccount, HexString, TransactionReceipt, Transaction, TransactionCall, TransactionWithFromLocalWalletIndex, TransactionWithToLocalWalletIndex, TransactionWithFromAndToLocalWalletIndex, TransactionHash } from 'web3-types';
|
2
|
+
import { Web3Context, Web3PromiEvent } from 'web3-core';
|
3
|
+
import { JsonSchema } from 'web3-validator';
|
4
|
+
import { SendSignedTransactionEvents, SendTransactionEvents, SendTransactionOptions } from '../types.js';
|
5
|
+
export declare class SendTxHelper<ReturnFormat extends DataFormat, ResolveType = FormatType<TransactionReceipt, ReturnFormat>, TxType = Transaction | TransactionWithFromLocalWalletIndex | TransactionWithToLocalWalletIndex | TransactionWithFromAndToLocalWalletIndex> {
|
6
|
+
private readonly web3Context;
|
7
|
+
private readonly promiEvent;
|
8
|
+
private readonly options;
|
9
|
+
private readonly returnFormat;
|
10
|
+
constructor({ options, web3Context, promiEvent, returnFormat, }: {
|
11
|
+
web3Context: Web3Context<EthExecutionAPI>;
|
12
|
+
options: SendTransactionOptions<ResolveType>;
|
13
|
+
promiEvent: Web3PromiEvent<ResolveType, SendSignedTransactionEvents<ReturnFormat> | SendTransactionEvents<ReturnFormat>>;
|
14
|
+
returnFormat: ReturnFormat;
|
15
|
+
});
|
16
|
+
getReceiptWithEvents(data: TransactionReceipt): ResolveType;
|
17
|
+
checkRevertBeforeSending(tx: TransactionCall): Promise<void>;
|
18
|
+
emitSending(tx: TxType | HexString): void;
|
19
|
+
populateGasPrice({ transactionFormatted, transaction, }: {
|
20
|
+
transactionFormatted: TxType;
|
21
|
+
transaction: TxType;
|
22
|
+
}): Promise<TxType>;
|
23
|
+
signAndSend({ wallet, tx, }: {
|
24
|
+
wallet: Web3BaseWalletAccount | undefined;
|
25
|
+
tx: TxType;
|
26
|
+
}): Promise<string>;
|
27
|
+
emitSent(tx: TxType | HexString): void;
|
28
|
+
emitTransactionHash(hash: string & Uint8Array): void;
|
29
|
+
emitReceipt(receipt: ResolveType): void;
|
30
|
+
handleError({ error, tx }: {
|
31
|
+
error: unknown;
|
32
|
+
tx: TransactionCall;
|
33
|
+
}): Promise<unknown>;
|
34
|
+
emitConfirmation({ receipt, transactionHash, customTransactionReceiptSchema, }: {
|
35
|
+
receipt: ResolveType;
|
36
|
+
transactionHash: TransactionHash;
|
37
|
+
customTransactionReceiptSchema?: JsonSchema;
|
38
|
+
}): void;
|
39
|
+
handleResolve({ receipt, tx }: {
|
40
|
+
receipt: ResolveType;
|
41
|
+
tx: TransactionCall;
|
42
|
+
}): Promise<ResolveType>;
|
43
|
+
}
|