Browse Source

fixed web3 rpc test failures

Bas van Kervel 10 years ago
parent
commit
5fdf72b1ab
1 changed files with 24 additions and 0 deletions
  1. 24 0
      rpc/api/web3_args.go

+ 24 - 0
rpc/api/web3_args.go

@@ -1,5 +1,29 @@
 package api
 
+import (
+	"encoding/json"
+
+	"github.com/ethereum/go-ethereum/rpc/shared"
+)
+
 type Sha3Args struct {
 	Data string
 }
+
+func (args *Sha3Args) UnmarshalJSON(b []byte) (err error) {
+	var obj []interface{}
+	if err := json.Unmarshal(b, &obj); err != nil {
+		return shared.NewDecodeParamError(err.Error())
+	}
+
+	if len(obj) < 1 {
+		return shared.NewInsufficientParamsError(len(obj), 1)
+	}
+
+	argstr, ok := obj[0].(string)
+	if !ok {
+		return shared.NewInvalidTypeError("data", "is not a string")
+	}
+	args.Data = argstr
+	return nil
+}