From f02211d055567b51373b5faa2c3dc6efe0523618 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Thu, 8 Feb 2024 20:24:50 -0500 Subject: [PATCH] Allow transaction encoding for inferred type transactions. --- src.ts/transaction/transaction.ts | 32 ++++++++++++------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src.ts/transaction/transaction.ts b/src.ts/transaction/transaction.ts index 92157feda2..b9ec51d75c 100644 --- a/src.ts/transaction/transaction.ts +++ b/src.ts/transaction/transaction.ts @@ -206,11 +206,9 @@ function _parseLegacy(data: Uint8Array): TransactionLike { } function _serializeLegacy(tx: Transaction, sig?: Signature): string { - assertArgument(tx.isLegacy(), "internal check failed; !legacy", "tx", tx); - const fields: Array = [ formatNumber(tx.nonce, "nonce"), - formatNumber(tx.gasPrice, "gasPrice"), + formatNumber(tx.gasPrice || 0, "gasPrice"), formatNumber(tx.gasLimit, "gasLimit"), (tx.to || "0x"), formatNumber(tx.value, "value"), @@ -312,18 +310,16 @@ function _parseEip1559(data: Uint8Array): TransactionLike { } function _serializeEip1559(tx: Transaction, sig?: Signature): string { - assertArgument(tx.isLondon(), "internal check failed; !london", "tx", tx); - const fields: Array = [ formatNumber(tx.chainId, "chainId"), formatNumber(tx.nonce, "nonce"), - formatNumber(tx.maxPriorityFeePerGas, "maxPriorityFeePerGas"), - formatNumber(tx.maxFeePerGas, "maxFeePerGas"), + formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"), + formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"), formatNumber(tx.gasLimit, "gasLimit"), (tx.to || "0x"), formatNumber(tx.value, "value"), tx.data, - formatAccessList(tx.accessList) + formatAccessList(tx.accessList || [ ]) ]; if (sig) { @@ -364,17 +360,15 @@ function _parseEip2930(data: Uint8Array): TransactionLike { } function _serializeEip2930(tx: Transaction, sig?: Signature): string { - assertArgument(tx.isBerlin(), "internal check failed; !berlin", "tx", tx); - const fields: any = [ formatNumber(tx.chainId, "chainId"), formatNumber(tx.nonce, "nonce"), - formatNumber(tx.gasPrice, "gasPrice"), + formatNumber(tx.gasPrice || 0, "gasPrice"), formatNumber(tx.gasLimit, "gasLimit"), (tx.to || "0x"), formatNumber(tx.value, "value"), tx.data, - formatAccessList(tx.accessList) + formatAccessList(tx.accessList || [ ]) ]; if (sig) { @@ -426,20 +420,18 @@ function _parseEip4844(data: Uint8Array): TransactionLike { } function _serializeEip4844(tx: Transaction, sig?: Signature): string { - assertArgument(tx.isCancun(), "internal check failed; !cancun", "tx", tx); - const fields: Array = [ formatNumber(tx.chainId, "chainId"), formatNumber(tx.nonce, "nonce"), - formatNumber(tx.maxPriorityFeePerGas, "maxPriorityFeePerGas"), - formatNumber(tx.maxFeePerGas, "maxFeePerGas"), + formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"), + formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"), formatNumber(tx.gasLimit, "gasLimit"), - tx.to, + (tx.to || ZeroAddress), formatNumber(tx.value, "value"), tx.data, - (formatAccessList(tx.accessList)), - formatNumber(tx.maxFeePerBlobGas, "maxFeePerBlobGas"), - formatHashes(tx.blobVersionedHashes, "blobVersionedHashes") + formatAccessList(tx.accessList || [ ]), + formatNumber(tx.maxFeePerBlobGas || 0, "maxFeePerBlobGas"), + formatHashes(tx.blobVersionedHashes || [ ], "blobVersionedHashes") ]; if (sig) {