aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rpc/api.go8
-rw-r--r--rpc/args.go20
-rw-r--r--rpc/args_test.go27
3 files changed, 17 insertions, 38 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 8d1a412d1..b5f759711 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -185,11 +185,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err
}
- if err := args.requirements(); err != nil {
- return err
- }
-
- v, err := api.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
+ v, err := api.xeth().Transact(args.From.Hex(), args.To.Hex(), args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil {
return err
}
@@ -200,7 +196,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err
}
- v, err := api.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
+ v, err := api.xethAtStateNum(args.BlockNumber).Call(args.From.Hex(), args.To.Hex(), args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil {
return err
}
diff --git a/rpc/args.go b/rpc/args.go
index 9a51959f4..2446e778f 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -93,8 +93,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
}
type NewTxArgs struct {
- From string
- To string
+ From common.Address
+ To common.Address
Value *big.Int
Gas *big.Int
GasPrice *big.Int
@@ -122,9 +122,12 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return NewDecodeParamError(err.Error())
}
- // var ok bool
- args.From = ext.From
- args.To = ext.To
+ if len(ext.From) == 0 {
+ return NewValidationError("from", "is required")
+ }
+
+ args.From = common.HexToAddress(ext.From)
+ args.To = common.HexToAddress(ext.To)
args.Value = common.String2Big(ext.Value)
args.Gas = common.String2Big(ext.Gas)
args.GasPrice = common.String2Big(ext.GasPrice)
@@ -145,13 +148,6 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return nil
}
-func (args *NewTxArgs) requirements() error {
- if len(args.From) == 0 {
- return NewValidationError("From", "Is required")
- }
- return nil
-}
-
type GetStorageArgs struct {
Address string
BlockNumber int64
diff --git a/rpc/args_test.go b/rpc/args_test.go
index c6d3a558b..328eab0ec 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -149,8 +149,8 @@ func TestNewTxArgs(t *testing.T) {
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
"0x10"]`
expected := new(NewTxArgs)
- expected.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155"
- expected.To = "0xd46e8dd67c5d32be8058bb8eb970870f072445675"
+ expected.From = common.HexToAddress("0xb60e8dd61c5d32be8058bb8eb970870f07233155")
+ expected.To = common.HexToAddress("0xd46e8dd67c5d32be8058bb8eb970870f072445675")
expected.Gas = big.NewInt(30400)
expected.GasPrice = big.NewInt(10000000000000)
expected.Value = big.NewInt(10000000000000)
@@ -194,7 +194,7 @@ func TestNewTxArgs(t *testing.T) {
func TestNewTxArgsBlockInt(t *testing.T) {
input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}, 5]`
expected := new(NewTxArgs)
- expected.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155"
+ expected.From = common.HexToAddress("0xb60e8dd61c5d32be8058bb8eb970870f07233155")
expected.BlockNumber = big.NewInt(5).Int64()
args := new(NewTxArgs)
@@ -221,31 +221,18 @@ func TestNewTxArgsEmpty(t *testing.T) {
}
}
-func TestNewTxArgsReqs(t *testing.T) {
- args := new(NewTxArgs)
- args.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155"
-
- err := args.requirements()
- switch err.(type) {
- case nil:
- break
- default:
- t.Errorf("Get %T", err)
- }
-}
+func TestNewTxArgsFromEmpty(t *testing.T) {
+ input := `[{"to": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}]`
-func TestNewTxArgsReqsFromBlank(t *testing.T) {
args := new(NewTxArgs)
- args.From = ""
-
- err := args.requirements()
+ err := json.Unmarshal([]byte(input), &args)
switch err.(type) {
case nil:
t.Error("Expected error but didn't get one")
case *ValidationError:
break
default:
- t.Error("Wrong type of error")
+ t.Errorf("Expected *rpc.ValidationError, but got %T with message `%s`", err, err.Error())
}
}