Exemple #1
0
func (args *SetGlobalRegistrarArgs) UnmarshalJSON(b []byte) (err error) {
	var obj []interface{}
	if err := json.Unmarshal(b, &obj); err != nil {
		return shared.NewDecodeParamError(err.Error())
	}

	if len(obj) == 0 {
		return shared.NewDecodeParamError("Expected namereg address")
	}

	if len(obj) >= 1 {
		if namereg, ok := obj[0].(string); ok {
			args.NameReg = namereg
		} else {
			return shared.NewInvalidTypeError("NameReg", "not a string")
		}
	}

	if len(obj) >= 2 && obj[1] != nil {
		if addr, ok := obj[1].(string); ok {
			args.ContractAddress = addr
		} else {
			return shared.NewInvalidTypeError("ContractAddress", "not a string")
		}
	}

	return nil
}
Exemple #2
0
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
}
Exemple #3
0
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
}
Exemple #4
0
func (args *SleepBlocksArgs) UnmarshalJSON(b []byte) (err error) {

	var obj []interface{}
	if err := json.Unmarshal(b, &obj); err != nil {
		return shared.NewDecodeParamError(err.Error())
	}

	args.N = 1
	args.Timeout = 0
	if len(obj) >= 1 && obj[0] != nil {
		if n, err := numString(obj[0]); err == nil {
			args.N = n.Int64()
		} else {
			return shared.NewInvalidTypeError("N", "not an integer: "+err.Error())
		}
	}

	if len(obj) >= 2 && obj[1] != nil {
		if n, err := numString(obj[1]); err == nil {
			args.Timeout = n.Int64()
		} else {
			return shared.NewInvalidTypeError("Timeout", "not an integer: "+err.Error())
		}
	}

	return nil
}
Exemple #5
0
func (args *HttpGetArgs) 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 len(obj) >= 1 {
		if uri, ok := obj[0].(string); ok {
			args.Uri = uri
		} else {
			return shared.NewInvalidTypeError("Uri", "not a string")
		}
	}

	if len(obj) >= 2 && obj[1] != nil {
		if path, ok := obj[1].(string); ok {
			args.Path = path
		} else {
			return shared.NewInvalidTypeError("Path", "not a string")
		}
	}

	return nil
}
Exemple #6
0
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
}
Exemple #7
0
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
}
Exemple #8
0
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
}
Exemple #9
0
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
}
Exemple #10
0
func (args *RegisterUrlArgs) 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 {
		if sender, ok := obj[0].(string); ok {
			args.Sender = sender
		} else {
			return shared.NewInvalidTypeError("Sender", "not a string")
		}
	}

	if len(obj) >= 2 {
		if sender, ok := obj[1].(string); ok {
			args.ContentHash = sender
		} else {
			return shared.NewInvalidTypeError("ContentHash", "not a string")
		}
	}

	if len(obj) >= 3 {
		if sender, ok := obj[2].(string); ok {
			args.Url = sender
		} else {
			return shared.NewInvalidTypeError("Url", "not a string")
		}
	}

	return nil
}
Exemple #11
0
func (args *ListTransactionsArgs) 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)
	}

	other, ok := obj[0].([]interface{})
	if !ok {
		other = obj
		ok = true
	}

	if ok {
		args.Accounts = make([]string, len(other))
		for i, acct := range other {
			if args.Accounts[i], ok = acct.(string); !ok {
				return shared.NewInvalidTypeError("accounts", "not a string array2")
			}
		}
		return nil
	}

	return shared.NewInvalidTypeError("accounts", "not a string array1")
}
Exemple #12
0
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
}
Exemple #13
0
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
}
Exemple #14
0
func (args *SaveInfoArgs) 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 jsonraw, err := json.Marshal(obj[0]); err == nil {
		if err = json.Unmarshal(jsonraw, &args.ContractInfo); err != nil {
			return err
		}
	} else {
		return err
	}

	if filename, ok := obj[1].(string); ok {
		args.Filename = filename
	} else {
		return shared.NewInvalidTypeError("Filename", "not a string")
	}

	return nil
}
Exemple #15
0
func (args *StartRPCArgs) UnmarshalJSON(b []byte) (err error) {
	var obj []interface{}
	if err := json.Unmarshal(b, &obj); err != nil {
		return shared.NewDecodeParamError(err.Error())
	}

	args.ListenAddress = "127.0.0.1"
	args.ListenPort = 53901
	args.Apis = "net,eth,web3"

	if len(obj) >= 1 && obj[0] != nil {
		if addr, ok := obj[0].(string); ok {
			args.ListenAddress = addr
		} else {
			return shared.NewInvalidTypeError("listenAddress", "not a string")
		}
	}

	if len(obj) >= 2 && obj[1] != nil {
		if port, ok := obj[1].(float64); ok && port >= 0 && port <= 64*1024 {
			args.ListenPort = uint(port)
		} else {
			return shared.NewInvalidTypeError("listenPort", "not a valid port number")
		}
	}

	if len(obj) >= 3 && obj[2] != nil {
		if corsDomain, ok := obj[2].(string); ok {
			args.CorsDomain = corsDomain
		} else {
			return shared.NewInvalidTypeError("corsDomain", "not a string")
		}
	}

	if len(obj) >= 4 && obj[3] != nil {
		if apis, ok := obj[3].(string); ok {
			args.Apis = apis
		} else {
			return shared.NewInvalidTypeError("apis", "not a string")
		}
	}

	return nil
}
Exemple #16
0
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("Shiftbase", "not a valid address")
		}
		return nil
	}

	return shared.NewInvalidTypeError("Shiftbase", "not a string")
}
Exemple #17
0
func (args *DeleteAccountArgs) 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 addr, ok := obj[0].(string); ok {
		args.Address = addr
	} else {
		return shared.NewInvalidTypeError("address", "not a string")
	}

	if passhrase, ok := obj[1].(string); ok {
		args.Passphrase = passhrase
	} else {
		return shared.NewInvalidTypeError("passhrase", "not a string")
	}

	return nil
}
Exemple #18
0
func (args *RegisterArgs) 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)
	}

	if len(obj) >= 1 {
		if sender, ok := obj[0].(string); ok {
			args.Sender = sender
		} else {
			return shared.NewInvalidTypeError("Sender", "not a string")
		}
	}

	if len(obj) >= 2 {
		if address, ok := obj[1].(string); ok {
			args.Address = address
		} else {
			return shared.NewInvalidTypeError("Address", "not a string")
		}
	}

	if len(obj) >= 3 {
		if hex, ok := obj[2].(string); ok {
			args.ContentHashHex = hex
		} else {
			return shared.NewInvalidTypeError("ContentHashHex", "not a string")
		}
	}

	return nil
}
Exemple #19
0
func (args *SetUrlHintArgs) 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 urlhint, ok := obj[0].(string); ok {
			args.UrlHint = urlhint
		} else {
			return shared.NewInvalidTypeError("UrlHint", "not a string")
		}
	}

	if len(obj) >= 2 && obj[1] != nil {
		if sender, ok := obj[1].(string); ok {
			args.Sender = sender
		} else {
			return shared.NewInvalidTypeError("Sender", "not a string")
		}
	}

	return nil
}
Exemple #20
0
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")
}
Exemple #21
0
func (args *SetSolcArgs) 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.NewDecodeParamError("Expected path as argument")
	}

	if pathstr, ok := obj[0].(string); ok {
		args.Path = pathstr
		return nil
	}

	return shared.NewInvalidTypeError("path", "not a string")
}
Exemple #22
0
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 {
		return shared.NewInsufficientParamsError(len(obj), 1)
	}

	if passhrase, ok := obj[0].(string); ok {
		args.Passphrase = passhrase
		return nil
	}

	return shared.NewInvalidTypeError("passhrase", "not a string")
}
Exemple #23
0
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
}
Exemple #24
0
func (args *ImportExportChainArgs) 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.NewDecodeParamError("Expected filename as argument")
	}

	filename, ok := obj[0].(string)
	if !ok {
		return shared.NewInvalidTypeError("filename", "not a string")
	}
	args.Filename = filename

	return nil
}
Exemple #25
0
func (args *AddPeerArgs) 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.NewDecodeParamError("Expected enode as argument")
	}

	urlstr, ok := obj[0].(string)
	if !ok {
		return shared.NewInvalidTypeError("url", "not a string")
	}
	args.Url = urlstr

	return nil
}
Exemple #26
0
func (args *IsAccountLockedArgs) 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 addrstr, ok := obj[0].(string); ok {
		args.Address = addrstr
	} else {
		return shared.NewInvalidTypeError("address", "not a string")
	}

	return nil
}
Exemple #27
0
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")
}
Exemple #28
0
func (args *SleepArgs) 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 {
		if obj[0] != nil {
			if n, err := numString(obj[0]); err == nil {
				args.S = int(n.Int64())
			} else {
				return shared.NewInvalidTypeError("N", "not an integer: "+err.Error())
			}
		} else {
			return shared.NewInsufficientParamsError(0, 1)
		}
	}
	return nil
}
Exemple #29
0
func (args *GetContractInfoArgs) 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 len(obj) >= 1 {
		if contract, ok := obj[0].(string); ok {
			args.Contract = contract
		} else {
			return shared.NewInvalidTypeError("Contract", "not a string")
		}
	}

	return nil
}
Exemple #30
0
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)

	return nil
}