diff options
Diffstat (limited to 'rpc/message.go')
-rw-r--r-- | rpc/message.go | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/rpc/message.go b/rpc/message.go index 05f66ee95..a76eaece4 100644 --- a/rpc/message.go +++ b/rpc/message.go @@ -126,12 +126,12 @@ func (req *RpcRequest) ToPushTxArgs() (*PushTxArgs, error) { return args, nil } -func (req *RpcRequest) ToGetStorageArgs() (*GetStorageArgs, error) { - if len(req.Params) < 2 { +func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) { + if len(req.Params) < 1 { return nil, NewErrorResponse(ErrorArguments) } - args := new(GetStorageArgs) + args := new(GetStateArgs) // TODO need to pass both arguments r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) @@ -142,6 +142,21 @@ func (req *RpcRequest) ToGetStorageArgs() (*GetStorageArgs, error) { return args, nil } +func (req *RpcRequest) ToStorageAtArgs() (*GetStorageArgs, error) { + if len(req.Params) < 1 { + return nil, NewErrorResponse(ErrorArguments) + } + + args := new(GetStorageArgs) + r := bytes.NewReader(req.Params[0]) + err := json.NewDecoder(r).Decode(args) + if err != nil { + return nil, NewErrorResponse(ErrorDecodeArgs) + } + rpclogger.DebugDetailf("%T %v", args, args) + return args, nil +} + func (req *RpcRequest) ToGetTxCountArgs() (*GetTxCountArgs, error) { if len(req.Params) < 1 { return nil, NewErrorResponse(ErrorArguments) @@ -239,3 +254,44 @@ func toLogs(logs state.Logs) (ls []Log) { return } + +func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) { + if len(req.Params) < 3 { + return nil, NewErrorResponse(ErrorArguments) + } + + var args DbArgs + err := json.Unmarshal(req.Params[0], &args.Database) + if err != nil { + return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + } + err = json.Unmarshal(req.Params[1], &args.Key) + if err != nil { + return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + } + err = json.Unmarshal(req.Params[2], &args.Value) + if err != nil { + return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + } + rpclogger.DebugDetailf("%T %v", args, args) + return &args, nil +} + +func (req *RpcRequest) ToDbGetArgs() (*DbArgs, error) { + if len(req.Params) < 2 { + return nil, NewErrorResponse(ErrorArguments) + } + + var args DbArgs + err := json.Unmarshal(req.Params[0], &args.Database) + if err != nil { + return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + } + + err = json.Unmarshal(req.Params[1], &args.Key) + if err != nil { + return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + } + rpclogger.DebugDetailf("%T %v", args, args) + return &args, nil +} |