diff --git a/types/access_list_tx.go b/types/access_list_tx.go index e0b47b76ae..4832fec3fb 100644 --- a/types/access_list_tx.go +++ b/types/access_list_tx.go @@ -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 } @@ -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) diff --git a/types/dynamic_fee_tx.go b/types/dynamic_fee_tx.go index eeaa43ee28..df88bc6335 100644 --- a/types/dynamic_fee_tx.go +++ b/types/dynamic_fee_tx.go @@ -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 } @@ -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) diff --git a/types/legacy_tx.go b/types/legacy_tx.go index e9d9cd23ef..233b5c29ae 100644 --- a/types/legacy_tx.go +++ b/types/legacy_tx.go @@ -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 } @@ -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) diff --git a/types/state_tx.go b/types/state_tx.go index c6f7b6b150..639303b40c 100644 --- a/types/state_tx.go +++ b/types/state_tx.go @@ -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 } @@ -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) diff --git a/types/transaction.go b/types/transaction.go index 00a6bc07e5..a500a6f074 100644 --- a/types/transaction.go +++ b/types/transaction.go @@ -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() } }