Allow transaction encoding for inferred type transactions.

This commit is contained in:
Richard Moore 2024-02-08 20:24:50 -05:00
parent d8a7cbe83a
commit f02211d055

@ -206,11 +206,9 @@ function _parseLegacy(data: Uint8Array): TransactionLike {
} }
function _serializeLegacy(tx: Transaction, sig?: Signature): string { function _serializeLegacy(tx: Transaction, sig?: Signature): string {
assertArgument(tx.isLegacy(), "internal check failed; !legacy", "tx", tx);
const fields: Array<any> = [ const fields: Array<any> = [
formatNumber(tx.nonce, "nonce"), formatNumber(tx.nonce, "nonce"),
formatNumber(tx.gasPrice, "gasPrice"), formatNumber(tx.gasPrice || 0, "gasPrice"),
formatNumber(tx.gasLimit, "gasLimit"), formatNumber(tx.gasLimit, "gasLimit"),
(tx.to || "0x"), (tx.to || "0x"),
formatNumber(tx.value, "value"), formatNumber(tx.value, "value"),
@ -312,18 +310,16 @@ function _parseEip1559(data: Uint8Array): TransactionLike {
} }
function _serializeEip1559(tx: Transaction, sig?: Signature): string { function _serializeEip1559(tx: Transaction, sig?: Signature): string {
assertArgument(tx.isLondon(), "internal check failed; !london", "tx", tx);
const fields: Array<any> = [ const fields: Array<any> = [
formatNumber(tx.chainId, "chainId"), formatNumber(tx.chainId, "chainId"),
formatNumber(tx.nonce, "nonce"), formatNumber(tx.nonce, "nonce"),
formatNumber(tx.maxPriorityFeePerGas, "maxPriorityFeePerGas"), formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
formatNumber(tx.maxFeePerGas, "maxFeePerGas"), formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
formatNumber(tx.gasLimit, "gasLimit"), formatNumber(tx.gasLimit, "gasLimit"),
(tx.to || "0x"), (tx.to || "0x"),
formatNumber(tx.value, "value"), formatNumber(tx.value, "value"),
tx.data, tx.data,
formatAccessList(tx.accessList) formatAccessList(tx.accessList || [ ])
]; ];
if (sig) { if (sig) {
@ -364,17 +360,15 @@ function _parseEip2930(data: Uint8Array): TransactionLike {
} }
function _serializeEip2930(tx: Transaction, sig?: Signature): string { function _serializeEip2930(tx: Transaction, sig?: Signature): string {
assertArgument(tx.isBerlin(), "internal check failed; !berlin", "tx", tx);
const fields: any = [ const fields: any = [
formatNumber(tx.chainId, "chainId"), formatNumber(tx.chainId, "chainId"),
formatNumber(tx.nonce, "nonce"), formatNumber(tx.nonce, "nonce"),
formatNumber(tx.gasPrice, "gasPrice"), formatNumber(tx.gasPrice || 0, "gasPrice"),
formatNumber(tx.gasLimit, "gasLimit"), formatNumber(tx.gasLimit, "gasLimit"),
(tx.to || "0x"), (tx.to || "0x"),
formatNumber(tx.value, "value"), formatNumber(tx.value, "value"),
tx.data, tx.data,
formatAccessList(tx.accessList) formatAccessList(tx.accessList || [ ])
]; ];
if (sig) { if (sig) {
@ -426,20 +420,18 @@ function _parseEip4844(data: Uint8Array): TransactionLike {
} }
function _serializeEip4844(tx: Transaction, sig?: Signature): string { function _serializeEip4844(tx: Transaction, sig?: Signature): string {
assertArgument(tx.isCancun(), "internal check failed; !cancun", "tx", tx);
const fields: Array<any> = [ const fields: Array<any> = [
formatNumber(tx.chainId, "chainId"), formatNumber(tx.chainId, "chainId"),
formatNumber(tx.nonce, "nonce"), formatNumber(tx.nonce, "nonce"),
formatNumber(tx.maxPriorityFeePerGas, "maxPriorityFeePerGas"), formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
formatNumber(tx.maxFeePerGas, "maxFeePerGas"), formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
formatNumber(tx.gasLimit, "gasLimit"), formatNumber(tx.gasLimit, "gasLimit"),
tx.to, (tx.to || ZeroAddress),
formatNumber(tx.value, "value"), formatNumber(tx.value, "value"),
tx.data, tx.data,
(formatAccessList(tx.accessList)), formatAccessList(tx.accessList || [ ]),
formatNumber(tx.maxFeePerBlobGas, "maxFeePerBlobGas"), formatNumber(tx.maxFeePerBlobGas || 0, "maxFeePerBlobGas"),
formatHashes(tx.blobVersionedHashes, "blobVersionedHashes") formatHashes(tx.blobVersionedHashes || [ ], "blobVersionedHashes")
]; ];
if (sig) { if (sig) {