Skip to content

Commit

Permalink
Allow transaction encoding for inferred type transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 9, 2024
1 parent d8a7cbe commit f02211d
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src.ts/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> = [
formatNumber(tx.nonce, "nonce"),
formatNumber(tx.gasPrice, "gasPrice"),
formatNumber(tx.gasPrice || 0, "gasPrice"),
formatNumber(tx.gasLimit, "gasLimit"),
(tx.to || "0x"),
formatNumber(tx.value, "value"),
Expand Down Expand Up @@ -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<any> = [
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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<any> = [
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) {
Expand Down

0 comments on commit f02211d

Please sign in to comment.