aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-23 23:35:49 +0800
committerobscuren <geffobscura@gmail.com>2015-03-23 23:35:49 +0800
commit253ecdc8bba1b522e80fdee69410854f19a5a972 (patch)
tree4cdad80599f03c741634d7e6f9a856b8fe070ee1 /rpc/args.go
parent9be7853e349f97917120fd925e2c5a462bd78846 (diff)
parent3f6e1b2fd3cbc6aeb1bbe658dd5b70945a57dffa (diff)
downloadgo-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.tar
go-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.tar.gz
go-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.tar.bz2
go-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.tar.lz
go-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.tar.xz
go-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.tar.zst
go-tangerine-253ecdc8bba1b522e80fdee69410854f19a5a972.zip
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Diffstat (limited to 'rpc/args.go')
-rw-r--r--rpc/args.go78
1 files changed, 72 insertions, 6 deletions
diff --git a/rpc/args.go b/rpc/args.go
index 504e67c07..06dab99bc 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -497,24 +497,39 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
type DbArgs struct {
Database string
Key string
- Value string
+ Value []byte
}
func (args *DbArgs) UnmarshalJSON(b []byte) (err error) {
var obj []interface{}
- r := bytes.NewReader(b)
- if err := json.NewDecoder(r).Decode(&obj); err != nil {
+ if err := json.Unmarshal(b, &obj); err != nil {
return NewDecodeParamError(err.Error())
}
if len(obj) < 2 {
return NewInsufficientParamsError(len(obj), 2)
}
- args.Database = obj[0].(string)
- args.Key = obj[1].(string)
+
+ var objstr string
+ var ok bool
+
+ if objstr, ok = obj[0].(string); !ok {
+ return NewDecodeParamError("Database is not a string")
+ }
+ args.Database = objstr
+
+ if objstr, ok = obj[1].(string); !ok {
+ return NewDecodeParamError("Key is not a string")
+ }
+ args.Key = objstr
if len(obj) > 2 {
- args.Value = obj[2].(string)
+ objstr, ok = obj[2].(string)
+ if !ok {
+ return NewDecodeParamError("Value is not a string")
+ }
+
+ args.Value = []byte(objstr)
}
return nil
@@ -530,6 +545,57 @@ func (a *DbArgs) requirements() error {
return nil
}
+type DbHexArgs struct {
+ Database string
+ Key string
+ Value []byte
+}
+
+func (args *DbHexArgs) UnmarshalJSON(b []byte) (err error) {
+ var obj []interface{}
+ if err := json.Unmarshal(b, &obj); err != nil {
+ return NewDecodeParamError(err.Error())
+ }
+
+ if len(obj) < 2 {
+ return NewInsufficientParamsError(len(obj), 2)
+ }
+
+ var objstr string
+ var ok bool
+
+ if objstr, ok = obj[0].(string); !ok {
+ return NewDecodeParamError("Database is not a string")
+ }
+ args.Database = objstr
+
+ if objstr, ok = obj[1].(string); !ok {
+ return NewDecodeParamError("Key is not a string")
+ }
+ args.Key = objstr
+
+ if len(obj) > 2 {
+ objstr, ok = obj[2].(string)
+ if !ok {
+ return NewDecodeParamError("Value is not a string")
+ }
+
+ args.Value = common.FromHex(objstr)
+ }
+
+ return nil
+}
+
+func (a *DbHexArgs) requirements() error {
+ if len(a.Database) == 0 {
+ return NewValidationError("Database", "cannot be blank")
+ }
+ if len(a.Key) == 0 {
+ return NewValidationError("Key", "cannot be blank")
+ }
+ return nil
+}
+
type WhisperMessageArgs struct {
Payload string
To string