Skip to content

Commit 67da83a

Browse files
authored
accounts/external, signer/core: add support for EIP-2930 transactions (#22585)
This adds support for signing EIP-2930 with clef.
1 parent 4b783c0 commit 67da83a

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

accounts/external/backend.go

+14
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
212212
To: to,
213213
From: common.NewMixedcaseAddress(account.Address),
214214
}
215+
// We should request the default chain id that we're operating with
216+
// (the chain we're executing on)
217+
if chainID != nil {
218+
args.ChainID = (*hexutil.Big)(chainID)
219+
}
220+
// However, if the user asked for a particular chain id, then we should
221+
// use that instead.
222+
if tx.Type() != types.LegacyTxType && tx.ChainId() != nil {
223+
args.ChainID = (*hexutil.Big)(tx.ChainId())
224+
}
225+
if tx.Type() == types.AccessListTxType {
226+
accessList := tx.AccessList()
227+
args.AccessList = &accessList
228+
}
215229
var res signTransactionResult
216230
if err := api.client.Call(&res, "account_signTransaction", args); err != nil {
217231
return nil, err

signer/core/api.go

+8
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ func (api *SignerAPI) SignTransaction(ctx context.Context, args SendTxArgs, meth
534534
return nil, err
535535
}
536536
}
537+
if args.ChainID != nil {
538+
requestedChainId := (*big.Int)(args.ChainID)
539+
if api.chainID.Cmp(requestedChainId) != 0 {
540+
log.Error("Signing request with wrong chain id", "requested", requestedChainId, "configured", api.chainID)
541+
return nil, fmt.Errorf("requested chainid %d does not match the configuration of the signer",
542+
requestedChainId)
543+
}
544+
}
537545
req := SignTxRequest{
538546
Transaction: args,
539547
Meta: MetadataFromContext(ctx),

signer/core/cliui.go

+12
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ func (ui *CommandlineUI) ApproveTx(request *SignTxRequest) (SignTxResponse, erro
118118
fmt.Printf("gas: %v (%v)\n", request.Transaction.Gas, uint64(request.Transaction.Gas))
119119
fmt.Printf("gasprice: %v wei\n", request.Transaction.GasPrice.ToInt())
120120
fmt.Printf("nonce: %v (%v)\n", request.Transaction.Nonce, uint64(request.Transaction.Nonce))
121+
if chainId := request.Transaction.ChainID; chainId != nil {
122+
fmt.Printf("chainid: %v\n", chainId)
123+
}
124+
if list := request.Transaction.AccessList; list != nil {
125+
fmt.Printf("Accesslist\n")
126+
for i, el := range *list {
127+
fmt.Printf(" %d. %v\n", i, el.Address)
128+
for j, slot := range el.StorageKeys {
129+
fmt.Printf(" %d. %v\n", j, slot)
130+
}
131+
}
132+
}
121133
if request.Transaction.Data != nil {
122134
d := *request.Transaction.Data
123135
if len(d) > 0 {

signer/core/types.go

+31-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ type SendTxArgs struct {
7676
// We accept "data" and "input" for backwards-compatibility reasons.
7777
Data *hexutil.Bytes `json:"data"`
7878
Input *hexutil.Bytes `json:"input,omitempty"`
79+
80+
// For non-legacy transactions
81+
AccessList *types.AccessList `json:"accessList,omitempty"`
82+
ChainID *hexutil.Big `json:"chainId,omitempty"`
7983
}
8084

8185
func (args SendTxArgs) String() string {
@@ -93,8 +97,32 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
9397
} else if args.Input != nil {
9498
input = *args.Input
9599
}
96-
if args.To == nil {
97-
return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(&args.GasPrice), input)
100+
var to *common.Address
101+
if args.To != nil {
102+
_to := args.To.Address()
103+
to = &_to
104+
}
105+
var data types.TxData
106+
if args.AccessList == nil {
107+
data = &types.LegacyTx{
108+
To: to,
109+
Nonce: uint64(args.Nonce),
110+
Gas: uint64(args.Gas),
111+
GasPrice: (*big.Int)(&args.GasPrice),
112+
Value: (*big.Int)(&args.Value),
113+
Data: input,
114+
}
115+
} else {
116+
data = &types.AccessListTx{
117+
To: to,
118+
ChainID: (*big.Int)(args.ChainID),
119+
Nonce: uint64(args.Nonce),
120+
Gas: uint64(args.Gas),
121+
GasPrice: (*big.Int)(&args.GasPrice),
122+
Value: (*big.Int)(&args.Value),
123+
Data: input,
124+
AccessList: *args.AccessList,
125+
}
98126
}
99-
return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input)
127+
return types.NewTx(data)
100128
}

0 commit comments

Comments
 (0)