diff options
Diffstat (limited to 'rpc/args.go')
-rw-r--r-- | rpc/args.go | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/rpc/args.go b/rpc/args.go index 84b076d4a..f730819fd 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -1,6 +1,7 @@ package rpc import "encoding/json" + import "github.com/ethereum/go-ethereum/core" type GetBlockArgs struct { @@ -37,13 +38,42 @@ type NewTxArgs struct { Data string `json:"data"` } +func (obj *NewTxArgs) UnmarshalJSON(b []byte) (err error) { + // Data can be either specified as "data" or "code" :-/ + var ext struct { + From string + To string + Value string + Gas string + GasPrice string + Data string + Code string + } + + if err = json.Unmarshal(b, &ext); err == nil { + if len(ext.Data) == 0 { + ext.Data = ext.Code + } + obj.From = ext.From + obj.To = ext.To + obj.Value = ext.Value + obj.Gas = ext.Gas + obj.GasPrice = ext.GasPrice + obj.Data = ext.Data + + return + } + + return NewErrorResponse(ErrorDecodeArgs) +} + type PushTxArgs struct { Tx string `json:"tx"` } func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" - if err = json.Unmarshal(b, arg0); err == nil { + if err = json.Unmarshal(b, &arg0); err == nil { obj.Tx = arg0 return } @@ -82,7 +112,7 @@ type GetStateArgs struct { func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" - if err = json.Unmarshal(b, arg0); err == nil { + if err = json.Unmarshal(b, &arg0); err == nil { obj.Address = arg0 return } @@ -114,7 +144,7 @@ type GetTxCountArgs struct { func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" - if err = json.Unmarshal(b, arg0); err == nil { + if err = json.Unmarshal(b, &arg0); err == nil { obj.Address = arg0 return } @@ -203,7 +233,7 @@ func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) { type FilterOptions struct { Earliest int64 Latest int64 - Address string + Address interface{} Topic []string Skip int Max int @@ -211,9 +241,22 @@ type FilterOptions struct { func toFilterOptions(options *FilterOptions) core.FilterOptions { var opts core.FilterOptions + + // Convert optional address slice/string to byte slice + if str, ok := options.Address.(string); ok { + opts.Address = [][]byte{fromHex(str)} + } else if slice, ok := options.Address.([]interface{}); ok { + bslice := make([][]byte, len(slice)) + for i, addr := range slice { + if saddr, ok := addr.(string); ok { + bslice[i] = fromHex(saddr) + } + } + opts.Address = bslice + } + opts.Earliest = options.Earliest opts.Latest = options.Latest - opts.Address = fromHex(options.Address) opts.Topics = make([][]byte, len(options.Topic)) for i, topic := range options.Topic { opts.Topics[i] = fromHex(topic) @@ -246,7 +289,7 @@ type WhisperMessageArgs struct { Payload string To string From string - Topics []string + Topic []string Priority uint32 Ttl uint32 } |