Skip to content

Commit

Permalink
Added abstraction for EIP-2718 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Mar 9, 2021
1 parent 6c43e20 commit 1db4ce1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/transactions/src.ts/index.ts
Expand Up @@ -30,6 +30,7 @@ export type UnsignedTransaction = {

export interface Transaction {
hash?: string;
type?: number | null;

to?: string;
from?: string;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]
});
}

0 comments on commit 1db4ce1

Please sign in to comment.