func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 2 { return shared.NewInsufficientParamsError(len(obj), 2) } argstr, ok := obj[0].(string) if !ok { return shared.NewInvalidTypeError("blockHash", "not a string") } args.BlockHash = argstr args.IncludeTxs = obj[1].(bool) if inclTx, ok := obj[1].(bool); ok { args.IncludeTxs = inclTx return nil } return shared.NewInvalidTypeError("includeTxs", "not a bool") }
func blockHeight(raw interface{}, number *int64) error { // Parse as integer num, ok := raw.(float64) if ok { *number = int64(num) return nil } // Parse as string/hexstring str, ok := raw.(string) if !ok { return shared.NewInvalidTypeError("", "not a number or string") } switch str { case "earliest": *number = 0 case "latest": *number = -1 case "pending": *number = -2 default: if common.HasHexPrefix(str) { *number = common.String2Big(str).Int64() } else { return shared.NewInvalidTypeError("blockNumber", "is not a valid string") } } return nil }
func (args *SubmitHashRateArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 2 { return shared.NewInsufficientParamsError(len(obj), 2) } arg0, ok := obj[0].(string) if !ok { return shared.NewInvalidTypeError("hash", "not a string") } args.Id = arg0 arg1, ok := obj[1].(string) if !ok { return shared.NewInvalidTypeError("rate", "not a string") } args.Rate = common.String2Big(arg1).Uint64() return nil }
func (args *UnlockAccountArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } args.Duration = 0 if len(obj) < 1 { return shared.NewInsufficientParamsError(len(obj), 1) } if addrstr, ok := obj[0].(string); ok { args.Address = addrstr } else { return shared.NewInvalidTypeError("address", "not a string") } if len(obj) >= 2 && obj[1] != nil { if passphrasestr, ok := obj[1].(string); ok { args.Passphrase = &passphrasestr } else { return shared.NewInvalidTypeError("passphrase", "not a string") } } if len(obj) >= 3 && obj[2] != nil { if duration, ok := obj[2].(float64); ok { args.Duration = int(duration) } } return nil }
func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 2 { return shared.NewInsufficientParamsError(len(obj), 2) } addstr, ok := obj[0].(string) if !ok { return shared.NewInvalidTypeError("address", "not a string") } args.Address = addstr keystr, ok := obj[1].(string) if !ok { return shared.NewInvalidTypeError("key", "not a string") } args.Key = keystr if len(obj) > 2 { if err := blockHeight(obj[2], &args.BlockNumber); err != nil { return err } } else { args.BlockNumber = -1 } return nil }
func (args *DbHexArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 2 { return shared.NewInsufficientParamsError(len(obj), 2) } var objstr string var ok bool if objstr, ok = obj[0].(string); !ok { return shared.NewInvalidTypeError("database", "not a string") } args.Database = objstr if objstr, ok = obj[1].(string); !ok { return shared.NewInvalidTypeError("key", "not a string") } args.Key = objstr if len(obj) > 2 { objstr, ok = obj[2].(string) if !ok { return shared.NewInvalidTypeError("value", "not a string") } args.Value = common.FromHex(objstr) } return nil }
func (args *SubmitWorkArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err = json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 3 { return shared.NewInsufficientParamsError(len(obj), 3) } var objstr string var ok bool if objstr, ok = obj[0].(string); !ok { return shared.NewInvalidTypeError("nonce", "not a string") } args.Nonce = common.String2Big(objstr).Uint64() if objstr, ok = obj[1].(string); !ok { return shared.NewInvalidTypeError("header", "not a string") } args.Header = objstr if objstr, ok = obj[2].(string); !ok { return shared.NewInvalidTypeError("digest", "not a string") } args.Digest = objstr return nil }
func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } // Check for sufficient params if len(obj) < 1 { return shared.NewInsufficientParamsError(len(obj), 1) } from, ok := obj[0].(string) if !ok { return shared.NewInvalidTypeError("from", "not a string") } args.From = from if len(args.From) == 0 { return shared.NewValidationError("from", "is required") } data, ok := obj[1].(string) if !ok { return shared.NewInvalidTypeError("data", "not a string") } args.Data = data if len(args.Data) == 0 { return shared.NewValidationError("data", "is required") } return nil }
func (args *ResendArgs) 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) } data, err := json.Marshal(obj[0]) if err != nil { return shared.NewDecodeParamError("Unable to parse transaction object") } trans := new(tx) err = json.Unmarshal(data, trans) if err != nil { return shared.NewDecodeParamError("Unable to parse transaction object") } if trans == nil || trans.tx == nil { return shared.NewDecodeParamError("Unable to parse transaction object") } gasLimit, gasPrice := trans.GasLimit, trans.GasPrice if len(obj) > 1 && obj[1] != nil { if gp, ok := obj[1].(string); ok { gasPrice = gp } else { return shared.NewInvalidTypeError("gasPrice", "not a string") } } if len(obj) > 2 && obj[2] != nil { if gl, ok := obj[2].(string); ok { gasLimit = gl } else { return shared.NewInvalidTypeError("gasLimit", "not a string") } } args.Tx = trans args.GasPrice = gasPrice args.GasLimit = gasLimit return nil }
func (args *SetEtherbaseArgs) 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) } if addr, ok := obj[0].(string); ok { args.Etherbase = common.HexToAddress(addr) if (args.Etherbase == common.Address{}) { return shared.NewInvalidTypeError("Etherbase", "not a valid address") } return nil } return shared.NewInvalidTypeError("Etherbase", "not a string") }
func (args *NewAccountArgs) 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 && obj[0] != nil { if passphrasestr, ok := obj[0].(string); ok { args.Passphrase = &passphrasestr } else { return shared.NewInvalidTypeError("passphrase", "not a string") } } return nil }
func (args *GasPriceArgs) 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) } if pricestr, ok := obj[0].(string); ok { args.Price = pricestr return nil } return shared.NewInvalidTypeError("Price", "not a string") }
func (args *CompileArgs) 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("arg0", "is not a string") } args.Source = argstr return nil }
func numString(raw interface{}) (*big.Int, error) { var number *big.Int // Parse as integer num, ok := raw.(float64) if ok { number = big.NewInt(int64(num)) return number, nil } // Parse as string/hexstring str, ok := raw.(string) if ok { number = common.String2Big(str) return number, nil } return nil, shared.NewInvalidTypeError("", "not a number or string") }
func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) { var obj []interface{} if err := json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 2 { return shared.NewInsufficientParamsError(len(obj), 2) } if err := blockHeight(obj[0], &args.BlockNumber); err != nil { return err } if inclTx, ok := obj[1].(bool); ok { args.IncludeTxs = inclTx return nil } return shared.NewInvalidTypeError("includeTxs", "not a bool") }
func (args *FilterStringArgs) 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) } var argstr string argstr, ok := obj[0].(string) if !ok { return shared.NewInvalidTypeError("filter", "not a string") } switch argstr { case "latest", "pending": break default: return shared.NewValidationError("Word", "Must be `latest` or `pending`") } args.Word = argstr return nil }
func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { var obj []struct { FromBlock interface{} `json:"fromBlock"` ToBlock interface{} `json:"toBlock"` Limit interface{} `json:"limit"` Offset interface{} `json:"offset"` Address interface{} `json:"address"` Topics interface{} `json:"topics"` } if err = json.Unmarshal(b, &obj); err != nil { return shared.NewDecodeParamError(err.Error()) } if len(obj) < 1 { return shared.NewInsufficientParamsError(len(obj), 1) } // args.Earliest, err = toNumber(obj[0].ToBlock) // if err != nil { // return shared.NewDecodeParamError(fmt.Sprintf("FromBlock %v", err)) // } // args.Latest, err = toNumber(obj[0].FromBlock) // if err != nil { // return shared.NewDecodeParamError(fmt.Sprintf("ToBlock %v", err)) var num int64 var numBig *big.Int // if blank then latest if obj[0].FromBlock == nil { num = -1 } else { if err := blockHeight(obj[0].FromBlock, &num); err != nil { return err } } // if -2 or other "silly" number, use latest if num < 0 { args.Earliest = -1 //latest block } else { args.Earliest = num } // if blank than latest if obj[0].ToBlock == nil { num = -1 } else { if err := blockHeight(obj[0].ToBlock, &num); err != nil { return err } } if num == -2 { return fmt.Errorf("\"pending\" is unsupported") } else if num < -2 { return fmt.Errorf("Invalid to block number") } args.Latest = num if obj[0].Limit == nil { numBig = big.NewInt(defaultLogLimit) } else { if numBig, err = numString(obj[0].Limit); err != nil { return err } } args.Max = int(numBig.Int64()) if obj[0].Offset == nil { numBig = big.NewInt(defaultLogOffset) } else { if numBig, err = numString(obj[0].Offset); err != nil { return err } } args.Skip = int(numBig.Int64()) if obj[0].Address != nil { marg, ok := obj[0].Address.([]interface{}) if ok { v := make([]string, len(marg)) for i, arg := range marg { argstr, ok := arg.(string) if !ok { return shared.NewInvalidTypeError(fmt.Sprintf("address[%d]", i), "is not a string") } v[i] = argstr } args.Address = v } else { argstr, ok := obj[0].Address.(string) if ok { v := make([]string, 1) v[0] = argstr args.Address = v } else { return shared.NewInvalidTypeError("address", "is not a string or array") } } } if obj[0].Topics != nil { other, ok := obj[0].Topics.([]interface{}) if ok { topicdbl := make([][]string, len(other)) for i, iv := range other { if argstr, ok := iv.(string); ok { // Found a string, push into first element of array topicsgl := make([]string, 1) topicsgl[0] = argstr topicdbl[i] = topicsgl } else if argarray, ok := iv.([]interface{}); ok { // Found an array of other topicdbl[i] = make([]string, len(argarray)) for j, jv := range argarray { if v, ok := jv.(string); ok { topicdbl[i][j] = v } else if jv == nil { topicdbl[i][j] = "" } else { return shared.NewInvalidTypeError(fmt.Sprintf("topic[%d][%d]", i, j), "is not a string") } } } else if iv == nil { topicdbl[i] = []string{""} } else { return shared.NewInvalidTypeError(fmt.Sprintf("topic[%d]", i), "not a string or array") } } args.Topics = topicdbl return nil } else { return shared.NewInvalidTypeError("topic", "is not a string or array") } } return nil }