@@ -497,24 +497,39 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
497497type DbArgs struct {
498498 Database string
499499 Key string
500- Value string
500+ Value [] byte
501501}
502502
503503func (args * DbArgs ) UnmarshalJSON (b []byte ) (err error ) {
504504 var obj []interface {}
505- r := bytes .NewReader (b )
506- if err := json .NewDecoder (r ).Decode (& obj ); err != nil {
505+ if err := json .Unmarshal (b , & obj ); err != nil {
507506 return NewDecodeParamError (err .Error ())
508507 }
509508
510509 if len (obj ) < 2 {
511510 return NewInsufficientParamsError (len (obj ), 2 )
512511 }
513- args .Database = obj [0 ].(string )
514- args .Key = obj [1 ].(string )
512+
513+ var objstr string
514+ var ok bool
515+
516+ if objstr , ok = obj [0 ].(string ); ! ok {
517+ return NewDecodeParamError ("Database is not a string" )
518+ }
519+ args .Database = objstr
520+
521+ if objstr , ok = obj [1 ].(string ); ! ok {
522+ return NewDecodeParamError ("Key is not a string" )
523+ }
524+ args .Key = objstr
515525
516526 if len (obj ) > 2 {
517- args .Value = obj [2 ].(string )
527+ objstr , ok = obj [2 ].(string )
528+ if ! ok {
529+ return NewDecodeParamError ("Value is not a string" )
530+ }
531+
532+ args .Value = []byte (objstr )
518533 }
519534
520535 return nil
@@ -530,6 +545,57 @@ func (a *DbArgs) requirements() error {
530545 return nil
531546}
532547
548+ type DbHexArgs struct {
549+ Database string
550+ Key string
551+ Value []byte
552+ }
553+
554+ func (args * DbHexArgs ) UnmarshalJSON (b []byte ) (err error ) {
555+ var obj []interface {}
556+ if err := json .Unmarshal (b , & obj ); err != nil {
557+ return NewDecodeParamError (err .Error ())
558+ }
559+
560+ if len (obj ) < 2 {
561+ return NewInsufficientParamsError (len (obj ), 2 )
562+ }
563+
564+ var objstr string
565+ var ok bool
566+
567+ if objstr , ok = obj [0 ].(string ); ! ok {
568+ return NewDecodeParamError ("Database is not a string" )
569+ }
570+ args .Database = objstr
571+
572+ if objstr , ok = obj [1 ].(string ); ! ok {
573+ return NewDecodeParamError ("Key is not a string" )
574+ }
575+ args .Key = objstr
576+
577+ if len (obj ) > 2 {
578+ objstr , ok = obj [2 ].(string )
579+ if ! ok {
580+ return NewDecodeParamError ("Value is not a string" )
581+ }
582+
583+ args .Value = common .FromHex (objstr )
584+ }
585+
586+ return nil
587+ }
588+
589+ func (a * DbHexArgs ) requirements () error {
590+ if len (a .Database ) == 0 {
591+ return NewValidationError ("Database" , "cannot be blank" )
592+ }
593+ if len (a .Key ) == 0 {
594+ return NewValidationError ("Key" , "cannot be blank" )
595+ }
596+ return nil
597+ }
598+
533599type WhisperMessageArgs struct {
534600 Payload string
535601 To string
0 commit comments