Commit ce7fa52b authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

fix: tx enums (#781)

* enums: use additional enum for eth_sign txs

* chore: add changeset
parent 575bcf68
---
'@eth-optimism/core-utils': patch
'@eth-optimism/data-transport-layer': patch
---
Add an additional enum for EthSign transactions as they now are batch submitted with 2 different enum values
...@@ -9,11 +9,13 @@ import { Coder, Signature, Uint16, Uint8, Uint24, Address } from './types' ...@@ -9,11 +9,13 @@ import { Coder, Signature, Uint16, Uint8, Uint24, Address } from './types'
export enum TxType { export enum TxType {
EIP155 = 0, EIP155 = 0,
EthSign = 1, EthSign = 1,
EthSign2 = 2,
} }
export const txTypePlainText = { export const txTypePlainText = {
0: TxType.EIP155, 0: TxType.EIP155,
1: TxType.EthSign, 1: TxType.EthSign,
2: TxType.EthSign2,
EIP155: TxType.EIP155, EIP155: TxType.EIP155,
EthSign: TxType.EthSign, EthSign: TxType.EthSign,
} }
...@@ -169,6 +171,20 @@ class EthSignTxCoder extends DefaultEcdsaTxCoder { ...@@ -169,6 +171,20 @@ class EthSignTxCoder extends DefaultEcdsaTxCoder {
} }
} }
class EthSign2TxCoder extends DefaultEcdsaTxCoder {
constructor() {
super(TxType.EthSign2)
}
public encode(txData: EthSignTxData): string {
return super.encode(txData)
}
public decode(txData: string): EthSignTxData {
return super.decode(txData)
}
}
class Eip155TxCoder extends DefaultEcdsaTxCoder { class Eip155TxCoder extends DefaultEcdsaTxCoder {
constructor() { constructor() {
super(TxType.EIP155) super(TxType.EIP155)
...@@ -209,6 +225,9 @@ function decode(data: string | Buffer): EIP155TxData { ...@@ -209,6 +225,9 @@ function decode(data: string | Buffer): EIP155TxData {
if (type === TxType.EthSign) { if (type === TxType.EthSign) {
return new EthSignTxCoder().decode(data) return new EthSignTxCoder().decode(data)
} }
if (type === TxType.EthSign2) {
return new EthSign2TxCoder().decode(data)
}
return null return null
} }
...@@ -218,6 +237,7 @@ function decode(data: string | Buffer): EIP155TxData { ...@@ -218,6 +237,7 @@ function decode(data: string | Buffer): EIP155TxData {
export const ctcCoder = { export const ctcCoder = {
eip155TxData: new Eip155TxCoder(), eip155TxData: new Eip155TxCoder(),
ethSignTxData: new EthSignTxCoder(), ethSignTxData: new EthSignTxCoder(),
ethSign2TxData: new EthSign2TxCoder(),
encode, encode,
decode, decode,
} }
...@@ -254,6 +254,9 @@ const maybeDecodeSequencerBatchTransaction = ( ...@@ -254,6 +254,9 @@ const maybeDecodeSequencerBatchTransaction = (
} else if (txType === TxType.EthSign) { } else if (txType === TxType.EthSign) {
type = 'ETH_SIGN' type = 'ETH_SIGN'
decoded = ctcCoder.ethSignTxData.decode(transaction.toString('hex')) decoded = ctcCoder.ethSignTxData.decode(transaction.toString('hex'))
} else if (txType === TxType.EthSign2) {
type = 'ETH_SIGN'
decoded = ctcCoder.ethSign2TxData.decode(transaction.toString('hex'))
} else { } else {
throw new Error(`Unknown sequencer transaction type.`) throw new Error(`Unknown sequencer transaction type.`)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment