Skip to content

Commit

Permalink
EIP1559 updates for SendTxArgs in signer pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
i-norden committed Jan 6, 2020
1 parent 5dd38c3 commit efb4ea5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
28 changes: 27 additions & 1 deletion signer/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,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)
Expand Down
2 changes: 1 addition & 1 deletion signer/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 6 additions & 3 deletions signer/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}

0 comments on commit efb4ea5

Please sign in to comment.