aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/message.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-29 19:01:51 +0800
committerobscuren <geffobscura@gmail.com>2015-01-29 19:01:51 +0800
commit6d012f628bbfc22b2587828968eff513dfeb4d8e (patch)
tree54ee7aa44e667a62bea049f5c58cacf4fe571e3f /rpc/message.go
parentec85458612e1d5374767f87005dd0ad5934f74d5 (diff)
downloaddexon-6d012f628bbfc22b2587828968eff513dfeb4d8e.tar.gz
dexon-6d012f628bbfc22b2587828968eff513dfeb4d8e.tar.zst
dexon-6d012f628bbfc22b2587828968eff513dfeb4d8e.zip
implement transact
Diffstat (limited to 'rpc/message.go')
-rw-r--r--rpc/message.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/rpc/message.go b/rpc/message.go
index 5785fcc87..e9f47634f 100644
--- a/rpc/message.go
+++ b/rpc/message.go
@@ -20,6 +20,7 @@ import (
"bytes"
"encoding/json"
"errors"
+ "fmt"
)
const (
@@ -56,6 +57,14 @@ type RpcRequest struct {
Params []json.RawMessage `json:"params"`
}
+func NewErrorResponse(msg string) error {
+ return errors.New(msg)
+}
+
+func NewErrorResponseWithError(msg string, err error) error {
+ return fmt.Errorf("%s: %v", msg, err)
+}
+
func (req *RpcRequest) ToSha3Args() (*Sha3Args, error) {
if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments)
@@ -86,7 +95,7 @@ func (req *RpcRequest) ToGetBlockArgs() (*GetBlockArgs, error) {
}
func (req *RpcRequest) ToNewTxArgs() (*NewTxArgs, error) {
- if len(req.Params) < 7 {
+ if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments)
}
@@ -94,7 +103,7 @@ func (req *RpcRequest) ToNewTxArgs() (*NewTxArgs, error) {
r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args)
if err != nil {
- return nil, NewErrorResponse(ErrorDecodeArgs)
+ return nil, NewErrorResponseWithError(ErrorDecodeArgs, err)
}
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil
@@ -175,7 +184,3 @@ func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil
}
-
-func NewErrorResponse(msg string) error {
- return errors.New(msg)
-}