File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import (
2222
2323 "github.com/ethereum/go-ethereum/accounts/abi"
2424 "github.com/ethereum/go-ethereum/common"
25+ "github.com/stretchr/testify/require"
2526)
2627
2728var (
@@ -93,3 +94,18 @@ func FuzzUnpackIntoDeposit(f *testing.F) {
9394 }
9495 })
9596}
97+
98+ func TestDepositTxFrom (t * testing.T ) {
99+ from := common .HexToAddress ("0x1234567890123456789012345678901234567890" )
100+ dtx := & DepositTx {From : from }
101+ tx := NewTx (dtx )
102+ require .Equal (t , from , tx .From ())
103+
104+ dtxwn := & depositTxWithNonce {DepositTx : * dtx }
105+ tx = NewTx (dtxwn )
106+ require .Equal (t , from , tx .From ())
107+
108+ dftx := new (DynamicFeeTx )
109+ tx = NewTx (dftx )
110+ require .Panics (t , func () { tx .From () })
111+ }
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ func (tx *DepositTx) gasTipCap() *big.Int { return new(big.Int) }
7777func (tx * DepositTx ) gasPrice () * big.Int { return new (big.Int ) }
7878func (tx * DepositTx ) value () * big.Int { return tx .Value }
7979func (tx * DepositTx ) nonce () uint64 { return 0 }
80+ func (tx * DepositTx ) from () common.Address { return tx .From }
8081func (tx * DepositTx ) to () * common.Address { return tx .To }
8182func (tx * DepositTx ) isSystemTx () bool { return tx .IsSystemTransaction }
8283
@@ -105,3 +106,14 @@ func (tx *DepositTx) encode(b *bytes.Buffer) error {
105106func (tx * DepositTx ) decode (input []byte ) error {
106107 return rlp .DecodeBytes (input , tx )
107108}
109+
110+ // From is an OP-Stack addition to the Transaction type to easily get a deposit
111+ // transaction sender address.
112+ // It can be difficult to create a correct signer just to extract the From field
113+ // from a deposit transaction if the chain ID is not known.
114+ func (tx * Transaction ) From () common.Address {
115+ if tx .Type () != DepositTxType {
116+ panic ("From() called on non-deposit transaction" )
117+ }
118+ return tx .inner .(interface { from () common.Address }).from ()
119+ }
You can’t perform that action at this time.
0 commit comments