Differentiate between 0 and unspecified gas/gasprice
This commit is contained in:
+30
-2
@@ -182,7 +182,21 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||
nonce = args.Nonce.String()
|
||||
}
|
||||
|
||||
v, err := api.xeth().Transact(args.From, args.To, nonce, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
|
||||
var gas string
|
||||
if args.Gas == nil {
|
||||
gas = ""
|
||||
} else {
|
||||
gas = args.Gas.String()
|
||||
}
|
||||
|
||||
var gasprice string
|
||||
if args.GasPrice == nil {
|
||||
gas = ""
|
||||
} else {
|
||||
gas = args.GasPrice.String()
|
||||
}
|
||||
|
||||
v, err := api.xeth().Transact(args.From, args.To, nonce, args.Value.String(), gas, gasprice, args.Data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -603,5 +617,19 @@ func (api *EthereumApi) doCall(params json.RawMessage) (string, string, error) {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
return api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
|
||||
var gas string
|
||||
if args.Gas == nil {
|
||||
gas = ""
|
||||
} else {
|
||||
gas = args.Gas.String()
|
||||
}
|
||||
|
||||
var gasprice string
|
||||
if args.GasPrice == nil {
|
||||
gas = ""
|
||||
} else {
|
||||
gas = args.GasPrice.String()
|
||||
}
|
||||
|
||||
return api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), gas, gasprice, args.Data)
|
||||
}
|
||||
|
||||
+12
-12
@@ -261,22 +261,22 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
args.Value = num
|
||||
|
||||
num = nil
|
||||
if ext.Gas == nil {
|
||||
num = big.NewInt(0)
|
||||
} else {
|
||||
if ext.Gas != nil {
|
||||
if num, err = numString(ext.Gas); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
num = nil
|
||||
}
|
||||
args.Gas = num
|
||||
|
||||
num = nil
|
||||
if ext.GasPrice == nil {
|
||||
num = big.NewInt(0)
|
||||
} else {
|
||||
if ext.GasPrice != nil {
|
||||
if num, err = numString(ext.GasPrice); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
num = nil
|
||||
}
|
||||
args.GasPrice = num
|
||||
|
||||
@@ -346,21 +346,21 @@ func (args *CallArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
}
|
||||
args.Value = num
|
||||
|
||||
if ext.Gas == nil {
|
||||
num = big.NewInt(0)
|
||||
} else {
|
||||
if ext.Gas != nil {
|
||||
if num, err = numString(ext.Gas); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
num = nil
|
||||
}
|
||||
args.Gas = num
|
||||
|
||||
if ext.GasPrice == nil {
|
||||
num = big.NewInt(0)
|
||||
} else {
|
||||
if ext.GasPrice != nil {
|
||||
if num, err = numString(ext.GasPrice); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
num = nil
|
||||
}
|
||||
args.GasPrice = num
|
||||
|
||||
|
||||
+12
-8
@@ -573,14 +573,15 @@ func TestNewTxArgsGasMissing(t *testing.T) {
|
||||
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
|
||||
}]`
|
||||
expected := new(NewTxArgs)
|
||||
expected.Gas = big.NewInt(0)
|
||||
expected.Gas = nil
|
||||
|
||||
args := new(NewTxArgs)
|
||||
if err := json.Unmarshal([]byte(input), &args); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
|
||||
if args.Gas != expected.Gas {
|
||||
// if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
|
||||
t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas)
|
||||
}
|
||||
}
|
||||
@@ -594,14 +595,15 @@ func TestNewTxArgsBlockGaspriceMissing(t *testing.T) {
|
||||
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
|
||||
}]`
|
||||
expected := new(NewTxArgs)
|
||||
expected.GasPrice = big.NewInt(0)
|
||||
expected.GasPrice = nil
|
||||
|
||||
args := new(NewTxArgs)
|
||||
if err := json.Unmarshal([]byte(input), &args); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
|
||||
if args.GasPrice != expected.GasPrice {
|
||||
// if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
|
||||
t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice)
|
||||
}
|
||||
|
||||
@@ -829,9 +831,10 @@ func TestCallArgsGasMissing(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := new(CallArgs)
|
||||
expected.Gas = big.NewInt(0)
|
||||
expected.Gas = nil
|
||||
|
||||
if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
|
||||
if args.Gas != expected.Gas {
|
||||
// if bytes.Compare(expected.Gas.Bytes(), args.Gas.Bytes()) != 0 {
|
||||
t.Errorf("Gas shoud be %v but is %v", expected.Gas, args.Gas)
|
||||
}
|
||||
|
||||
@@ -852,9 +855,10 @@ func TestCallArgsBlockGaspriceMissing(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := new(CallArgs)
|
||||
expected.GasPrice = big.NewInt(0)
|
||||
expected.GasPrice = nil
|
||||
|
||||
if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
|
||||
if args.GasPrice != expected.GasPrice {
|
||||
// if bytes.Compare(expected.GasPrice.Bytes(), args.GasPrice.Bytes()) != 0 {
|
||||
t.Errorf("GasPrice shoud be %v but is %v", expected.GasPrice, args.GasPrice)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user