NewTxArgs

This commit is contained in:
Taylor Gerring 2015-03-26 10:34:21 +01:00
parent c7dc379da5
commit 966cfa4bdd
3 changed files with 18 additions and 39 deletions

@ -185,11 +185,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err return err
} }
if err := args.requirements(); err != nil { v, err := api.xeth().Transact(args.From.Hex(), args.To.Hex(), args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
return err
}
v, err := api.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil { if err != nil {
return err return err
} }
@ -200,7 +196,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return 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 { if err != nil {
return err return err
} }

@ -93,8 +93,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
} }
type NewTxArgs struct { type NewTxArgs struct {
From string From common.Address
To string To common.Address
Value *big.Int Value *big.Int
Gas *big.Int Gas *big.Int
GasPrice *big.Int GasPrice *big.Int
@ -122,9 +122,12 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return NewDecodeParamError(err.Error()) return NewDecodeParamError(err.Error())
} }
// var ok bool if len(ext.From) == 0 {
args.From = ext.From return NewValidationError("from", "is required")
args.To = ext.To }
args.From = common.HexToAddress(ext.From)
args.To = common.HexToAddress(ext.To)
args.Value = common.String2Big(ext.Value) args.Value = common.String2Big(ext.Value)
args.Gas = common.String2Big(ext.Gas) args.Gas = common.String2Big(ext.Gas)
args.GasPrice = common.String2Big(ext.GasPrice) args.GasPrice = common.String2Big(ext.GasPrice)
@ -145,13 +148,6 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return nil return nil
} }
func (args *NewTxArgs) requirements() error {
if len(args.From) == 0 {
return NewValidationError("From", "Is required")
}
return nil
}
type GetStorageArgs struct { type GetStorageArgs struct {
Address string Address string
BlockNumber int64 BlockNumber int64

@ -149,8 +149,8 @@ func TestNewTxArgs(t *testing.T) {
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}, "data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"},
"0x10"]` "0x10"]`
expected := new(NewTxArgs) expected := new(NewTxArgs)
expected.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155" expected.From = common.HexToAddress("0xb60e8dd61c5d32be8058bb8eb970870f07233155")
expected.To = "0xd46e8dd67c5d32be8058bb8eb970870f072445675" expected.To = common.HexToAddress("0xd46e8dd67c5d32be8058bb8eb970870f072445675")
expected.Gas = big.NewInt(30400) expected.Gas = big.NewInt(30400)
expected.GasPrice = big.NewInt(10000000000000) expected.GasPrice = big.NewInt(10000000000000)
expected.Value = big.NewInt(10000000000000) expected.Value = big.NewInt(10000000000000)
@ -194,7 +194,7 @@ func TestNewTxArgs(t *testing.T) {
func TestNewTxArgsBlockInt(t *testing.T) { func TestNewTxArgsBlockInt(t *testing.T) {
input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}, 5]` input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}, 5]`
expected := new(NewTxArgs) expected := new(NewTxArgs)
expected.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155" expected.From = common.HexToAddress("0xb60e8dd61c5d32be8058bb8eb970870f07233155")
expected.BlockNumber = big.NewInt(5).Int64() expected.BlockNumber = big.NewInt(5).Int64()
args := new(NewTxArgs) args := new(NewTxArgs)
@ -221,31 +221,18 @@ func TestNewTxArgsEmpty(t *testing.T) {
} }
} }
func TestNewTxArgsReqs(t *testing.T) { func TestNewTxArgsFromEmpty(t *testing.T) {
input := `[{"to": "0xb60e8dd61c5d32be8058bb8eb970870f07233155"}]`
args := new(NewTxArgs) args := new(NewTxArgs)
args.From = "0xb60e8dd61c5d32be8058bb8eb970870f07233155" err := json.Unmarshal([]byte(input), &args)
err := args.requirements()
switch err.(type) {
case nil:
break
default:
t.Errorf("Get %T", err)
}
}
func TestNewTxArgsReqsFromBlank(t *testing.T) {
args := new(NewTxArgs)
args.From = ""
err := args.requirements()
switch err.(type) { switch err.(type) {
case nil: case nil:
t.Error("Expected error but didn't get one") t.Error("Expected error but didn't get one")
case *ValidationError: case *ValidationError:
break break
default: default:
t.Error("Wrong type of error") t.Errorf("Expected *rpc.ValidationError, but got %T with message `%s`", err, err.Error())
} }
} }