aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/messages.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-06 11:37:45 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-06 11:37:45 +0800
commitef9d825cfaa274a4063bf7dcbf19c033e29b90aa (patch)
treef7bf3e516ed238b5f70fafc07a77eb21ea616f60 /rpc/messages.go
parent9f5e9eb38d7bf00ec24ce4ae09f910236f776641 (diff)
downloaddexon-ef9d825cfaa274a4063bf7dcbf19c033e29b90aa.tar.gz
dexon-ef9d825cfaa274a4063bf7dcbf19c033e29b90aa.tar.zst
dexon-ef9d825cfaa274a4063bf7dcbf19c033e29b90aa.zip
Refactor & cleanup
Diffstat (limited to 'rpc/messages.go')
-rw-r--r--rpc/messages.go390
1 files changed, 26 insertions, 364 deletions
diff --git a/rpc/messages.go b/rpc/messages.go
index 3ab99d2c5..4f5b00990 100644
--- a/rpc/messages.go
+++ b/rpc/messages.go
@@ -17,7 +17,6 @@
package rpc
import (
- "bytes"
"encoding/json"
"errors"
"fmt"
@@ -33,10 +32,10 @@ var (
)
type RpcRequest struct {
- ID interface{} `json:"id"`
- JsonRpc string `json:"jsonrpc"`
- Method string `json:"method"`
- Params []json.RawMessage `json:"params"`
+ ID interface{} `json:"id"`
+ JsonRpc string `json:"jsonrpc"`
+ Method string `json:"method"`
+ Params json.RawMessage `json:"params"`
}
type RpcSuccessResponse struct {
@@ -61,367 +60,30 @@ func NewErrorWithMessage(err error, msg string) error {
return fmt.Errorf("%s: %s", err.Error(), msg)
}
-func (req *RpcRequest) ToSha3Args() (*Sha3Args, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(Sha3Args)
- r := bytes.NewReader(req.Params[0])
- if err := json.NewDecoder(r).Decode(args); err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToGetBlockArgs() (*GetBlockArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(GetBlockArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToNewTxArgs() (*NewTxArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(NewTxArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToPushTxArgs() (*PushTxArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(PushTxArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToGetStorageAtArgs() (*GetStorageAtArgs, error) {
- if len(req.Params) < 2 {
- return nil, errArguments
- }
-
- args := new(GetStorageAtArgs)
- var arg0, arg1 string
-
- r0 := bytes.NewReader(req.Params[0])
- if err := json.NewDecoder(r0).Decode(arg0); err != nil {
- 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
-}
-
-func (req *RpcRequest) ToStorageArgs() (*GetStorageArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(GetStorageArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToGetTxCountArgs() (*GetTxCountArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(GetTxCountArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToGetBalanceArgs() (*GetBalanceArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(GetBalanceArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(GetCodeAtArgs)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToBoolArgs() (bool, error) {
- if len(req.Params) < 1 {
- return false, errArguments
- }
-
- var args bool
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return false, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToIntArgs() (int, error) {
- if len(req.Params) < 1 {
- return 0, errArguments
- }
-
- var args int
- if err := json.Unmarshal(req.Params[0], &args); err != nil {
- return 0, errArguments
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToCompileArgs() (string, error) {
- if len(req.Params) < 1 {
- return "", errArguments
- }
-
- var args string
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return "", errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- args := new(FilterOptions)
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(args)
- if err != nil {
- return nil, errDecodeArgs
- }
- return args, nil
-}
-
-func (req *RpcRequest) ToFilterStringArgs() (string, error) {
- if len(req.Params) < 1 {
- return "", errArguments
- }
-
- var args string
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return "", errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToUninstallFilterArgs() (int, error) {
- if len(req.Params) < 1 {
- return 0, errArguments
- }
-
- var args int
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return 0, errDecodeArgs
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToFilterChangedArgs() (int, error) {
- if len(req.Params) < 1 {
- return 0, errArguments
- }
-
- var id int
- r := bytes.NewReader(req.Params[0])
- err := json.NewDecoder(r).Decode(&id)
- if err != nil {
- return 0, errDecodeArgs
- }
- return id, nil
-}
-
-func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) {
- if len(req.Params) < 3 {
- return nil, errArguments
- }
-
- var args DbArgs
- err := json.Unmarshal(req.Params[0], &args.Database)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
- err = json.Unmarshal(req.Params[1], &args.Key)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
- err = json.Unmarshal(req.Params[2], &args.Value)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
+// func (req *RpcRequest) ToRegisterArgs() (string, error) {
+// if len(req.Params) < 1 {
+// return "", errArguments
+// }
- return &args, nil
-}
-
-func (req *RpcRequest) ToDbGetArgs() (*DbArgs, error) {
- if len(req.Params) < 2 {
- return nil, errArguments
- }
+// var args string
+// err := json.Unmarshal(req.Params, &args)
+// if err != nil {
+// return "", err
+// }
- var args DbArgs
- err := json.Unmarshal(req.Params[0], &args.Database)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
+// return args, nil
+// }
- err = json.Unmarshal(req.Params[1], &args.Key)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
+// func (req *RpcRequest) ToWatchTxArgs() (string, error) {
+// if len(req.Params) < 1 {
+// return "", errArguments
+// }
- return &args, nil
-}
+// var args string
+// err := json.Unmarshal(req.Params, &args)
+// if err != nil {
+// return "", err
+// }
-func (req *RpcRequest) ToWhisperFilterArgs() (*xeth.Options, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- var args xeth.Options
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
- }
-
- return &args, nil
-}
-
-func (req *RpcRequest) ToIdArgs() (int, error) {
- if len(req.Params) < 1 {
- return 0, errArguments
- }
-
- var id int
- err := json.Unmarshal(req.Params[0], &id)
- if err != nil {
- return 0, errDecodeArgs
- }
-
- return id, nil
-}
-
-func (req *RpcRequest) ToWhisperPostArgs() (*WhisperMessageArgs, error) {
- if len(req.Params) < 1 {
- return nil, errArguments
- }
-
- var args WhisperMessageArgs
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return nil, err
- }
-
- return &args, nil
-}
-
-func (req *RpcRequest) ToWhisperHasIdentityArgs() (string, error) {
- if len(req.Params) < 1 {
- return "", errArguments
- }
-
- var args string
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return "", err
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToRegisterArgs() (string, error) {
- if len(req.Params) < 1 {
- return "", errArguments
- }
-
- var args string
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return "", err
- }
-
- return args, nil
-}
-
-func (req *RpcRequest) ToWatchTxArgs() (string, error) {
- if len(req.Params) < 1 {
- return "", errArguments
- }
-
- var args string
- err := json.Unmarshal(req.Params[0], &args)
- if err != nil {
- return "", err
- }
-
- return args, nil
-}
+// return args, nil
+// }