From b0047a2dea657c63d7e5e389c02fc7f08a93e87e Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 16 Dec 2019 13:33:48 -0600 Subject: [PATCH] EIP1559 updates for SendTxArgs in signer pkg --- signer/core/api.go | 28 +++++++++++++++++++++++++++- signer/core/api_test.go | 2 +- signer/core/types.go | 9 ++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/signer/core/api.go b/signer/core/api.go index 7e6ece997..61d4359e3 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -455,10 +455,36 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool { modified = true log.Info("Gas changed by UI", "was", g0, "is", g1) } - if g0, g1 := big.Int(original.Transaction.GasPrice), big.Int(new.Transaction.GasPrice); g0.Cmp(&g1) != 0 { + g0, g1 := (*big.Int)(original.Transaction.GasPrice), (*big.Int)(new.Transaction.GasPrice) + if g0 == nil || g1 == nil { + if g0 != g1 { + modified = true + log.Info("GasPrice changed by UI", "was", g0, "is", g1) + } + } else if g0.Cmp(g1) != 0 { modified = true log.Info("GasPrice changed by UI", "was", g0, "is", g1) } + gp0, gp1 := (*big.Int)(original.Transaction.GasPremium), (*big.Int)(new.Transaction.GasPremium) + if gp0 == nil || gp1 == nil { + if gp0 != gp1 { + modified = true + log.Info("GasPremium changed by UI", "was", gp0, "is", gp1) + } + } else if gp0.Cmp(gp1) != 0 { + modified = true + log.Info("GasPremium changed by UI", "was", gp0, "is", gp1) + } + f0, f1 := (*big.Int)(original.Transaction.FeeCap), (*big.Int)(new.Transaction.FeeCap) + if f0 == nil || f1 == nil { + if f0 != f1 { + modified = true + log.Info("GasFee changed by UI", "was", f0, "is", f1) + } + } else if f0.Cmp(f1) != 0 { + modified = true + log.Info("GasFee changed by UI", "was", f0, "is", f1) + } if v0, v1 := big.Int(original.Transaction.Value), big.Int(new.Transaction.Value); v0.Cmp(&v1) != 0 { modified = true log.Info("Value changed by UI", "was", v0, "is", v1) diff --git a/signer/core/api_test.go b/signer/core/api_test.go index 800020b0c..faefdcbe6 100644 --- a/signer/core/api_test.go +++ b/signer/core/api_test.go @@ -226,7 +226,7 @@ func TestNewAcc(t *testing.T) { func mkTestTx(from common.MixedcaseAddress) core.SendTxArgs { to := common.NewMixedcaseAddress(common.HexToAddress("0x1337")) gas := hexutil.Uint64(21000) - gasPrice := (hexutil.Big)(*big.NewInt(2000000000)) + gasPrice := (*hexutil.Big)(big.NewInt(2000000000)) value := (hexutil.Big)(*big.NewInt(1e18)) nonce := (hexutil.Uint64)(0) data := hexutil.Bytes(common.Hex2Bytes("01020304050607080a")) diff --git a/signer/core/types.go b/signer/core/types.go index 1a4fa277a..af74beb6c 100644 --- a/signer/core/types.go +++ b/signer/core/types.go @@ -70,12 +70,15 @@ type SendTxArgs struct { From common.MixedcaseAddress `json:"from"` To *common.MixedcaseAddress `json:"to"` Gas hexutil.Uint64 `json:"gas"` - GasPrice hexutil.Big `json:"gasPrice"` + GasPrice *hexutil.Big `json:"gasPrice"` Value hexutil.Big `json:"value"` Nonce hexutil.Uint64 `json:"nonce"` // We accept "data" and "input" for backwards-compatibility reasons. Data *hexutil.Bytes `json:"data"` Input *hexutil.Bytes `json:"input,omitempty"` + // EIP1559 fields + GasPremium *hexutil.Big `json:"gasPremium"` + FeeCap *hexutil.Big `json:"feeCap"` } func (args SendTxArgs) String() string { @@ -94,7 +97,7 @@ func (args *SendTxArgs) toTransaction() *types.Transaction { input = *args.Input } if args.To == nil { - return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(&args.GasPrice), input, nil, nil) + return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) } - return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(&args.GasPrice), input, nil, nil) + return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) }