本文整理匯總了Golang中github.com/expanse-project/go-expanse/rpc/shared.NewInvalidTypeError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewInvalidTypeError函數的具體用法?Golang NewInvalidTypeError怎麽用?Golang NewInvalidTypeError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewInvalidTypeError函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UnmarshalJSON
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")
}
示例2: blockHeight
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
}
示例3: UnmarshalJSON
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
}
示例4: UnmarshalJSON
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
}
示例5: UnmarshalJSON
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")
}
示例6: UnmarshalJSON
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
}
示例7: numString
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")
}