aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/args.go')
-rw-r--r--rpc/args.go73
1 files changed, 18 insertions, 55 deletions
diff --git a/rpc/args.go b/rpc/args.go
index f730819fd..e839da8bf 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -19,14 +19,7 @@ func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) {
obj.Hash = argstr
return
}
- return NewErrorResponse(ErrorDecodeArgs)
-}
-
-func (obj *GetBlockArgs) requirements() error {
- if obj.BlockNumber == 0 && obj.Hash == "" {
- return NewErrorResponse("GetBlock requires either a block 'number' or a block 'hash' as argument")
- }
- return nil
+ return errDecodeArgs
}
type NewTxArgs struct {
@@ -64,7 +57,7 @@ func (obj *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return
}
- return NewErrorResponse(ErrorDecodeArgs)
+ return errDecodeArgs
}
type PushTxArgs struct {
@@ -77,12 +70,12 @@ func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) {
obj.Tx = arg0
return
}
- return NewErrorResponse(ErrorDecodeArgs)
+ return errDecodeArgs
}
func (a *PushTxArgs) requirementsPushTx() error {
if a.Tx == "" {
- return NewErrorResponse("PushTx requires a 'tx' as argument")
+ return NewErrorWithMessage(errArguments, "PushTx requires a 'tx' as argument")
}
return nil
}
@@ -93,14 +86,14 @@ type GetStorageArgs struct {
func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &obj.Address); err != nil {
- return NewErrorResponse(ErrorDecodeArgs)
+ return errDecodeArgs
}
return
}
func (a *GetStorageArgs) requirements() error {
if len(a.Address) == 0 {
- return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
+ return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument")
}
return nil
}
@@ -116,64 +109,39 @@ func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) {
obj.Address = arg0
return
}
- return NewErrorResponse(ErrorDecodeArgs)
+ return errDecodeArgs
}
func (a *GetStateArgs) requirements() error {
if a.Address == "" {
- return NewErrorResponse("GetStorageAt requires an 'address' value as argument")
+ return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument")
}
if a.Key == "" {
- return NewErrorResponse("GetStorageAt requires an 'key' value as argument")
+ return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'key' value as argument")
}
return nil
}
-type GetStorageAtRes struct {
- Key string `json:"key"`
- Value string `json:"value"`
-}
-
type GetTxCountArgs struct {
Address string `json:"address"`
}
-// type GetTxCountRes struct {
-// Nonce int `json:"nonce"`
-// }
-
func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
arg0 := ""
if err = json.Unmarshal(b, &arg0); err == nil {
obj.Address = arg0
return
}
- return NewErrorResponse("Could not determine JSON parameters")
+ return errDecodeArgs
}
func (a *GetTxCountArgs) requirements() error {
if a.Address == "" {
- return NewErrorResponse("GetTxCountAt requires an 'address' value as argument")
+ return NewErrorWithMessage(errArguments, "GetTxCountAt requires an 'address' value as argument")
}
return nil
}
-// type GetPeerCountRes struct {
-// PeerCount int `json:"peerCount"`
-// }
-
-// type GetListeningRes struct {
-// IsListening bool `json:"isListening"`
-// }
-
-// type GetCoinbaseRes struct {
-// Coinbase string `json:"coinbase"`
-// }
-
-// type GetMiningRes struct {
-// IsMining bool `json:"isMining"`
-// }
-
type GetBalanceArgs struct {
Address string
}
@@ -184,21 +152,16 @@ func (obj *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
obj.Address = arg0
return
}
- return NewErrorResponse("Could not determine JSON parameters")
+ return errDecodeArgs
}
func (a *GetBalanceArgs) requirements() error {
if a.Address == "" {
- return NewErrorResponse("GetBalanceAt requires an 'address' value as argument")
+ return NewErrorWithMessage(errArguments, "GetBalanceAt requires an 'address' value as argument")
}
return nil
}
-type BalanceRes struct {
- Balance string `json:"balance"`
- Address string `json:"address"`
-}
-
type GetCodeAtArgs struct {
Address string
}
@@ -209,12 +172,12 @@ func (obj *GetCodeAtArgs) UnmarshalJSON(b []byte) (err error) {
obj.Address = arg0
return
}
- return NewErrorResponse(ErrorDecodeArgs)
+ return errDecodeArgs
}
func (a *GetCodeAtArgs) requirements() error {
if a.Address == "" {
- return NewErrorResponse("GetCodeAt requires an 'address' value as argument")
+ return NewErrorWithMessage(errArguments, "GetCodeAt requires an 'address' value as argument")
}
return nil
}
@@ -225,7 +188,7 @@ type Sha3Args struct {
func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &obj.Data); err != nil {
- return NewErrorResponse(ErrorDecodeArgs)
+ return errDecodeArgs
}
return
}
@@ -277,10 +240,10 @@ type DbArgs struct {
func (a *DbArgs) requirements() error {
if len(a.Database) == 0 {
- return NewErrorResponse("DbPutArgs requires an 'Database' value as argument")
+ return NewErrorWithMessage(errArguments, "DbPutArgs requires an 'Database' value as argument")
}
if len(a.Key) == 0 {
- return NewErrorResponse("DbPutArgs requires an 'Key' value as argument")
+ return NewErrorWithMessage(errArguments, "DbPutArgs requires an 'Key' value as argument")
}
return nil
}