Skip to content

Commit 7a00378

Browse files
authored
cmd/clef, signer: support for eip-1559 txs in clef (#22966)
1 parent c503f98 commit 7a00378

16 files changed

+177
-58
lines changed

accounts/external/backend.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,18 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
204204
to = &t
205205
}
206206
args := &core.SendTxArgs{
207-
Data: &data,
208-
Nonce: hexutil.Uint64(tx.Nonce()),
209-
Value: hexutil.Big(*tx.Value()),
210-
Gas: hexutil.Uint64(tx.Gas()),
211-
GasPrice: hexutil.Big(*tx.GasPrice()),
212-
To: to,
213-
From: common.NewMixedcaseAddress(account.Address),
207+
Data: &data,
208+
Nonce: hexutil.Uint64(tx.Nonce()),
209+
Value: hexutil.Big(*tx.Value()),
210+
Gas: hexutil.Uint64(tx.Gas()),
211+
To: to,
212+
From: common.NewMixedcaseAddress(account.Address),
213+
}
214+
if tx.GasFeeCap() != nil {
215+
args.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap())
216+
args.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap())
217+
} else {
218+
args.GasPrice = (*hexutil.Big)(tx.GasPrice())
214219
}
215220
// We should request the default chain id that we're operating with
216221
// (the chain we're executing on)

cmd/clef/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ func testExternalUI(api *core.SignerAPI) {
929929
Value: hexutil.Big(*big.NewInt(6)),
930930
From: common.NewMixedcaseAddress(a),
931931
To: &to,
932-
GasPrice: hexutil.Big(*big.NewInt(5)),
932+
GasPrice: (*hexutil.Big)(big.NewInt(5)),
933933
Gas: 1000,
934934
Input: nil,
935935
}
@@ -1065,7 +1065,7 @@ func GenDoc(ctx *cli.Context) {
10651065
Value: hexutil.Big(*big.NewInt(6)),
10661066
From: common.NewMixedcaseAddress(a),
10671067
To: nil,
1068-
GasPrice: hexutil.Big(*big.NewInt(5)),
1068+
GasPrice: (*hexutil.Big)(big.NewInt(5)),
10691069
Gas: 1000,
10701070
Input: nil,
10711071
}})
@@ -1081,7 +1081,7 @@ func GenDoc(ctx *cli.Context) {
10811081
Value: hexutil.Big(*big.NewInt(6)),
10821082
From: common.NewMixedcaseAddress(a),
10831083
To: nil,
1084-
GasPrice: hexutil.Big(*big.NewInt(5)),
1084+
GasPrice: (*hexutil.Big)(big.NewInt(5)),
10851085
Gas: 1000,
10861086
Input: nil,
10871087
}})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"jsonrpc": "2.0",
3+
"method": "account_signTransaction",
4+
"params": [
5+
{
6+
"from": "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
7+
"to": "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
8+
"gas": "0x333",
9+
"maxFeePerGas": "0x123",
10+
"nonce": "0x0",
11+
"value": "0x10",
12+
"data": "0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"
13+
}
14+
],
15+
"id": 67
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"jsonrpc": "2.0",
3+
"method": "account_signTransaction",
4+
"params": [
5+
{
6+
"from": "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
7+
"to": "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
8+
"gas": "0x333",
9+
"maxPriorityFeePerGas": "0x123",
10+
"nonce": "0x0",
11+
"value": "0x10",
12+
"data": "0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"
13+
}
14+
],
15+
"id": 67
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"jsonrpc": "2.0",
3+
"method": "account_signTransaction",
4+
"params": [
5+
{
6+
"from": "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
7+
"to": "0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
8+
"gas": "0x333",
9+
"maxPriorityFeePerGas": "0x123",
10+
"maxFeePerGas": "0x123",
11+
"nonce": "0x0",
12+
"value": "0x10",
13+
"data": "0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"
14+
}
15+
],
16+
"id": 67
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"jsonrpc": "2.0",
3+
"method": "account_signTransaction",
4+
"params": [
5+
{
6+
"from":"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192",
7+
"to":"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192",
8+
"gas": "0x333",
9+
"gasPrice": "0x123",
10+
"nonce": "0x0",
11+
"value": "0x10",
12+
"data":
13+
"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"
14+
}
15+
],
16+
"id": 67
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"jsonrpc": "2.0",
3+
"method": "account_signTransaction",
4+
"params": [
5+
{
6+
"from":"0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
7+
"to":"0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192",
8+
"gas": "0x333",
9+
"gasPrice": "0x123",
10+
"nonce": "0x0",
11+
"value": "0x10",
12+
"data":
13+
"0x4401a6e40000000000000000000000000000000000000000000000000000000000000012"
14+
}
15+
],
16+
"id": 67
17+
}

internal/ethapi/transaction_args.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,9 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
265265
}
266266
return types.NewTx(data)
267267
}
268+
269+
// ToTransaction converts the arguments to a transaction.
270+
// This assumes that setDefaults has been called.
271+
func (args *TransactionArgs) ToTransaction() *types.Transaction {
272+
return args.toTransaction()
273+
}

signer/core/api.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,16 @@ func (api *SignerAPI) newAccount() (common.Address, error) {
456456
// it also returns 'true' if the transaction was modified, to make it possible to configure the signer not to allow
457457
// UI-modifications to requests
458458
func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
459+
var intPtrModified = func(a, b *hexutil.Big) bool {
460+
aBig := (*big.Int)(a)
461+
bBig := (*big.Int)(b)
462+
if aBig != nil && bBig != nil {
463+
return aBig.Cmp(bBig) != 0
464+
}
465+
// One or both of them are nil
466+
return a != b
467+
}
468+
459469
modified := false
460470
if f0, f1 := original.Transaction.From, new.Transaction.From; !reflect.DeepEqual(f0, f1) {
461471
log.Info("Sender-account changed by UI", "was", f0, "is", f1)
@@ -469,9 +479,17 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
469479
modified = true
470480
log.Info("Gas changed by UI", "was", g0, "is", g1)
471481
}
472-
if g0, g1 := big.Int(original.Transaction.GasPrice), big.Int(new.Transaction.GasPrice); g0.Cmp(&g1) != 0 {
482+
if a, b := original.Transaction.GasPrice, new.Transaction.GasPrice; intPtrModified(a, b) {
483+
log.Info("GasPrice changed by UI", "was", a, "is", b)
484+
modified = true
485+
}
486+
if a, b := original.Transaction.MaxPriorityFeePerGas, new.Transaction.MaxPriorityFeePerGas; intPtrModified(a, b) {
487+
log.Info("maxPriorityFeePerGas changed by UI", "was", a, "is", b)
488+
modified = true
489+
}
490+
if a, b := original.Transaction.MaxFeePerGas, new.Transaction.MaxFeePerGas; intPtrModified(a, b) {
491+
log.Info("maxFeePerGas changed by UI", "was", a, "is", b)
473492
modified = true
474-
log.Info("GasPrice changed by UI", "was", g0, "is", g1)
475493
}
476494
if v0, v1 := big.Int(original.Transaction.Value), big.Int(new.Transaction.Value); v0.Cmp(&v1) != 0 {
477495
modified = true

signer/core/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func mkTestTx(from common.MixedcaseAddress) core.SendTxArgs {
234234
From: from,
235235
To: &to,
236236
Gas: gas,
237-
GasPrice: gasPrice,
237+
GasPrice: &gasPrice,
238238
Value: value,
239239
Data: &data,
240240
Nonce: nonce}

0 commit comments

Comments
 (0)