From 1db4ce12d49e235a7155de24ee153f409e7e7370 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 9 Mar 2021 15:26:20 -0500 Subject: [PATCH] Added abstraction for EIP-2718 support. --- packages/transactions/src.ts/index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/transactions/src.ts/index.ts b/packages/transactions/src.ts/index.ts index 89665037ee..e5da082972 100644 --- a/packages/transactions/src.ts/index.ts +++ b/packages/transactions/src.ts/index.ts @@ -30,6 +30,7 @@ export type UnsignedTransaction = { export interface Transaction { hash?: string; + type?: number | null; to?: string; from?: string; @@ -162,7 +163,7 @@ export function serialize(transaction: UnsignedTransaction, signature?: Signatur return RLP.encode(raw); } -export function parse(rawTransaction: BytesLike): Transaction { +function _parse(rawTransaction: Uint8Array): Transaction { const transaction = RLP.decode(rawTransaction); if (transaction.length !== 9 && transaction.length !== 6) { @@ -225,6 +226,17 @@ export function parse(rawTransaction: BytesLike): Transaction { tx.hash = keccak256(rawTransaction); } + tx.type = null; + return tx; } +export function parse(rawTransaction: BytesLike): Transaction { + const payload = arrayify(rawTransaction); + if (payload[0] > 0x7f) { return _parse(payload); } + return logger.throwError(`unsupported transaction type: ${ payload[0] }`, Logger.errors.UNSUPPORTED_OPERATION, { + operation: "parseTransaction", + transactionType: payload[0] + }); +} +