Skip to content

Commit

Permalink
added contructor for all types of transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
dusannosovic-ethernal committed Mar 12, 2024
1 parent c85df85 commit 466a070
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
6 changes: 5 additions & 1 deletion types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ type AccessListTxn struct {
AccessList TxAccessList
}

func NewAccessListTx() *AccessListTxn {
return &AccessListTxn{BaseTx: &BaseTx{}}
}

func (tx *AccessListTxn) transactionType() TxType { return AccessListTxType }
func (tx *AccessListTxn) chainID() *big.Int { return tx.ChainID }
func (tx *AccessListTxn) gasPrice() *big.Int { return tx.GasPrice }
Expand Down Expand Up @@ -297,7 +301,7 @@ func (tx *AccessListTxn) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
}

func (tx *AccessListTxn) copy() TxData {
cpy := &AccessListTxn{}
cpy := NewAccessListTx()

if tx.chainID() != nil {
chainID := new(big.Int)
Expand Down
6 changes: 5 additions & 1 deletion types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type DynamicFeeTx struct {
AccessList TxAccessList
}

func NewDynamicFeeTx() *DynamicFeeTx {
return &DynamicFeeTx{BaseTx: &BaseTx{}}
}

func (tx *DynamicFeeTx) transactionType() TxType { return DynamicFeeTxType }
func (tx *DynamicFeeTx) chainID() *big.Int { return tx.ChainID }
func (tx *DynamicFeeTx) gasPrice() *big.Int { return nil }
Expand Down Expand Up @@ -208,7 +212,7 @@ func (tx *DynamicFeeTx) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
}

func (tx *DynamicFeeTx) copy() TxData {
cpy := &DynamicFeeTx{}
cpy := NewDynamicFeeTx()

if tx.chainID() != nil {
chainID := new(big.Int)
Expand Down
6 changes: 5 additions & 1 deletion types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type LegacyTx struct {
GasPrice *big.Int
}

func NewLegacyTx() *LegacyTx {
return &LegacyTx{BaseTx: &BaseTx{}}
}

func (tx *LegacyTx) transactionType() TxType { return LegacyTxType }
func (tx *LegacyTx) chainID() *big.Int { return deriveChainID(tx.v()) }
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
Expand Down Expand Up @@ -159,7 +163,7 @@ func (tx *LegacyTx) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
}

func (tx *LegacyTx) copy() TxData { //nolint:dupl
cpy := &LegacyTx{BaseTx: &BaseTx{}}
cpy := NewLegacyTx()

if tx.gasPrice() != nil {
gasPrice := new(big.Int)
Expand Down
6 changes: 5 additions & 1 deletion types/state_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type StateTx struct {
GasPrice *big.Int
}

func NewStateTx() *StateTx {
return &StateTx{BaseTx: &BaseTx{}}
}

func (tx *StateTx) transactionType() TxType { return StateTxType }
func (tx *StateTx) chainID() *big.Int { return deriveChainID(tx.v()) }
func (tx *StateTx) gasPrice() *big.Int { return tx.GasPrice }
Expand Down Expand Up @@ -175,7 +179,7 @@ func (tx *StateTx) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
}

func (tx *StateTx) copy() TxData { //nolint:dupl
cpy := &StateTx{}
cpy := NewStateTx()

if tx.gasPrice() != nil {
gasPrice := new(big.Int)
Expand Down
8 changes: 4 additions & 4 deletions types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func NewTx(inner TxData) *Transaction {
func (t *Transaction) InitInnerData(txType TxType) {
switch txType {
case AccessListTxType:
t.Inner = &AccessListTxn{BaseTx: &BaseTx{}}
t.Inner = NewAccessListTx()
case StateTxType:
t.Inner = &StateTx{BaseTx: &BaseTx{}}
t.Inner = NewStateTx()
case LegacyTxType:
t.Inner = &LegacyTx{BaseTx: &BaseTx{}}
t.Inner = NewLegacyTx()
default:
t.Inner = &DynamicFeeTx{BaseTx: &BaseTx{}}
t.Inner = NewDynamicFeeTx()
}
}

Expand Down

0 comments on commit 466a070

Please sign in to comment.