UNPKG

@ethereumjs/tx

Version:
68 lines 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createFeeMarket1559Tx = createFeeMarket1559Tx; exports.create1559FeeMarketTxFromBytesArray = create1559FeeMarketTxFromBytesArray; exports.createFeeMarket1559TxFromRLP = createFeeMarket1559TxFromRLP; const rlp_1 = require("@ethereumjs/rlp"); const util_1 = require("@ethereumjs/util"); const types_ts_1 = require("../types.js"); const internal_ts_1 = require("../util/internal.js"); const tx_ts_1 = require("./tx.js"); /** * Instantiate a transaction from a data dictionary. * * Format: { chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, v, r, s } * * Notes: * - `chainId` will be set automatically if not provided * - All parameters are optional and have some basic default values */ function createFeeMarket1559Tx(txData, opts = {}) { return new tx_ts_1.FeeMarket1559Tx(txData, opts); } /** * Create a transaction from an array of byte encoded values ordered according to the devp2p network encoding - format noted below. * * Format: `[chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, signatureYParity, signatureR, signatureS]` */ function create1559FeeMarketTxFromBytesArray(values, opts = {}) { if (values.length !== 9 && values.length !== 12) { throw (0, util_1.EthereumJSErrorWithoutCode)('Invalid EIP-1559 transaction. Only expecting 9 values (for unsigned tx) or 12 values (for signed tx).'); } const [chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, v, r, s,] = values; (0, internal_ts_1.validateNotArray)({ chainId, v }); (0, util_1.validateNoLeadingZeroes)({ nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, value, v, r, s }); return new tx_ts_1.FeeMarket1559Tx({ chainId: (0, util_1.bytesToBigInt)(chainId), nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList: accessList ?? [], v: v !== undefined ? (0, util_1.bytesToBigInt)(v) : undefined, // EIP2930 supports v's with value 0 (empty Uint8Array) r, s, }, opts); } /** * Instantiate a transaction from an RLP serialized tx. * * Format: `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, * accessList, signatureYParity, signatureR, signatureS])` */ function createFeeMarket1559TxFromRLP(serialized, opts = {}) { if ((0, util_1.equalsBytes)(serialized.subarray(0, 1), (0, internal_ts_1.txTypeBytes)(types_ts_1.TransactionType.FeeMarketEIP1559)) === false) { throw (0, util_1.EthereumJSErrorWithoutCode)(`Invalid serialized tx input: not an EIP-1559 transaction (wrong tx type, expected: ${types_ts_1.TransactionType.FeeMarketEIP1559}, received: ${(0, util_1.bytesToHex)(serialized.subarray(0, 1))}`); } const values = rlp_1.RLP.decode(serialized.subarray(1)); if (!Array.isArray(values)) { throw (0, util_1.EthereumJSErrorWithoutCode)('Invalid serialized tx input: must be array'); } return create1559FeeMarketTxFromBytesArray(values, opts); } //# sourceMappingURL=constructors.js.map