diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-30 03:39:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-30 03:39:26 +0800 |
commit | 0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31 (patch) | |
tree | 05a525e94ee55bd9c4a84301989176d40d76cb61 /rpc/message.go | |
parent | 6488a392a347d0d47212fdc78386e3e0e5841d7d (diff) | |
download | dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.tar dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.tar.gz dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.tar.bz2 dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.tar.lz dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.tar.xz dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.tar.zst dexon-0031f388ac1f6f4a23c5c75e5eeb4a007f0b2f31.zip |
More dapp samples
* Info DApp, coin DApp
* Additional rpc methods
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 +} |