Resolve storage/storageat

pull/444/head
Taylor Gerring 10 years ago
parent a6599404e4
commit 9f5e9eb38d
  1. 10
      rpc/api.go
  2. 6
      rpc/args.go
  3. 24
      rpc/messages.go

@ -311,7 +311,7 @@ func (p *EthereumApi) PushTx(args *PushTxArgs, reply *interface{}) error {
return nil return nil
} }
func (p *EthereumApi) GetStateAt(args *GetStateArgs, reply *interface{}) error { func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) error {
err := args.requirements() err := args.requirements()
if err != nil { if err != nil {
return err return err
@ -333,7 +333,7 @@ func (p *EthereumApi) GetStateAt(args *GetStateArgs, reply *interface{}) error {
return nil return nil
} }
func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *interface{}) error { func (p *EthereumApi) GetStorage(args *GetStorageArgs, reply *interface{}) error {
err := args.requirements() err := args.requirements()
if err != nil { if err != nil {
return err return err
@ -527,14 +527,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return p.GetBalanceAt(args, reply) return p.GetBalanceAt(args, reply)
case "eth_getStorage": case "eth_getStorage":
// TODO handle defaultBlock // TODO handle defaultBlock
args, err := req.ToGetStateArgs() args, err := req.ToStorageArgs()
if err != nil { if err != nil {
return err return err
} }
return p.GetStateAt(args, reply) return p.GetStorage(args, reply)
case "eth_getStorageAt": case "eth_getStorageAt":
// TODO handle defaultBlock // TODO handle defaultBlock
args, err := req.ToStorageAtArgs() args, err := req.ToGetStorageAtArgs()
if err != nil { if err != nil {
return err return err
} }

@ -102,12 +102,12 @@ func (a *GetStorageArgs) requirements() error {
return nil return nil
} }
type GetStateArgs struct { type GetStorageAtArgs struct {
Address string Address string
Key string Key string
} }
func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) { func (obj *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) {
arg0 := "" arg0 := ""
if err = json.Unmarshal(b, &arg0); err == nil { if err = json.Unmarshal(b, &arg0); err == nil {
obj.Address = arg0 obj.Address = arg0
@ -116,7 +116,7 @@ func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) {
return errDecodeArgs return errDecodeArgs
} }
func (a *GetStateArgs) requirements() error { func (a *GetStorageAtArgs) requirements() error {
if a.Address == "" { if a.Address == "" {
return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument") return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument")
} }

@ -120,23 +120,31 @@ func (req *RpcRequest) ToPushTxArgs() (*PushTxArgs, error) {
return args, nil return args, nil
} }
func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) { func (req *RpcRequest) ToGetStorageAtArgs() (*GetStorageAtArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 2 {
return nil, errArguments return nil, errArguments
} }
args := new(GetStateArgs) args := new(GetStorageAtArgs)
// TODO need to pass both arguments var arg0, arg1 string
r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) r0 := bytes.NewReader(req.Params[0])
if err != nil { if err := json.NewDecoder(r0).Decode(arg0); err != nil {
return nil, errDecodeArgs return nil, errDecodeArgs
} }
r1 := bytes.NewReader(req.Params[1])
if err := json.NewDecoder(r1).Decode(arg1); err != nil {
return nil, errDecodeArgs
}
args.Address = arg0
args.Key = arg1
return args, nil return args, nil
} }
func (req *RpcRequest) ToStorageAtArgs() (*GetStorageArgs, error) { func (req *RpcRequest) ToStorageArgs() (*GetStorageArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, errArguments return nil, errArguments
} }

Loading…
Cancel
Save