当前位置: 首页>>代码示例>>Golang>>正文


Golang shared.NewDecodeParamError函数代码示例

本文整理汇总了Golang中github.com/shiftcurrency/shift/rpc/shared.NewDecodeParamError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDecodeParamError函数的具体用法?Golang NewDecodeParamError怎么用?Golang NewDecodeParamError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDecodeParamError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: UnmarshalJSON

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
}
开发者ID:codeaudit,项目名称:shift,代码行数:28,代码来源:admin_args.go

示例2: UnmarshalJSON

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
}
开发者ID:codeaudit,项目名称:shift,代码行数:48,代码来源:eth_args.go

示例3: SendTransaction

func (self *ethApi) SendTransaction(req *shared.Request) (interface{}, error) {
	args := new(NewTxArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}

	// nonce may be nil ("guess" mode)
	var nonce string
	if args.Nonce != nil {
		nonce = args.Nonce.String()
	}

	var gas, price string
	if args.Gas != nil {
		gas = args.Gas.String()
	}
	if args.GasPrice != nil {
		price = args.GasPrice.String()
	}
	v, err := self.xeth.Transact(args.From, args.To, nonce, args.Value.String(), gas, price, args.Data)
	if err != nil {
		return nil, err
	}
	return v, nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:25,代码来源:eth.go

示例4: UnmarshalJSON

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")
}
开发者ID:codeaudit,项目名称:shift,代码行数:28,代码来源:personal_args.go

示例5: UninstallFilter

func (self *ethApi) UninstallFilter(req *shared.Request) (interface{}, error) {
	args := new(FilterIdArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}
	return self.xeth.UninstallFilter(args.Id), nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:7,代码来源:eth.go

示例6: 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
}
开发者ID:codeaudit,项目名称:shift,代码行数:34,代码来源:db_args.go

示例7: SubmitWork

func (self *ethApi) SubmitWork(req *shared.Request) (interface{}, error) {
	args := new(SubmitWorkArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}
	return self.xeth.RemoteMining().SubmitWork(args.Nonce, common.HexToHash(args.Digest), common.HexToHash(args.Header)), nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:7,代码来源:eth.go

示例8: blockHeightFromJson

func blockHeightFromJson(msg json.RawMessage, number *int64) error {
	var raw interface{}
	if err := json.Unmarshal(msg, &raw); err != nil {
		return shared.NewDecodeParamError(err.Error())
	}
	return blockHeight(raw, number)
}
开发者ID:codeaudit,项目名称:shift,代码行数:7,代码来源:parsing.go

示例9: GetLogs

func (self *ethApi) GetLogs(req *shared.Request) (interface{}, error) {
	args := new(BlockFilterArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}
	return NewLogsRes(self.xeth.AllLogs(args.Earliest, args.Latest, args.Skip, args.Max, args.Address, args.Topics)), nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:7,代码来源:eth.go

示例10: UnmarshalJSON

func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
	var obj []struct {
		Payload  string
		To       string
		From     string
		Topics   []string
		Priority interface{}
		Ttl      interface{}
	}

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

	if len(obj) < 1 {
		return shared.NewInsufficientParamsError(len(obj), 1)
	}
	args.Payload = obj[0].Payload
	args.To = obj[0].To
	args.From = obj[0].From
	args.Topics = obj[0].Topics

	var num *big.Int
	if num, err = numString(obj[0].Priority); err != nil {
		return err
	}
	args.Priority = uint32(num.Int64())

	if num, err = numString(obj[0].Ttl); err != nil {
		return err
	}
	args.Ttl = uint32(num.Int64())

	return nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:35,代码来源:shh_args.go

示例11: UnmarshalJSON

func (args *WaitForBlockArgs) 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 fmt.Errorf("waitForArgs needs 0, 1, 2 arguments")
	}

	// default values when not provided
	args.MinHeight = -1
	args.Timeout = -1

	if len(obj) >= 1 {
		var minHeight *big.Int
		if minHeight, err = numString(obj[0]); err != nil {
			return err
		}
		args.MinHeight = int(minHeight.Int64())
	}

	if len(obj) >= 2 {
		timeout, err := numString(obj[1])
		if err != nil {
			return err
		}
		args.Timeout = int(timeout.Int64())
	}

	return nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:32,代码来源:debug_args.go

示例12: ListAccountTransactions

func (self *personalApi) ListAccountTransactions(req *shared.Request) (interface{}, error) {
	args := new(ListTransactionsArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}

	return self.xeth.AccountTransactions(args.Accounts), nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:8,代码来源:personal.go

示例13: GetStorageAt

func (self *ethApi) GetStorageAt(req *shared.Request) (interface{}, error) {
	args := new(GetStorageAtArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}

	return self.xeth.AtStateNum(args.BlockNumber).StorageAt(args.Address, args.Key), nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:8,代码来源:eth.go

示例14: GetData

func (self *ethApi) GetData(req *shared.Request) (interface{}, error) {
	args := new(GetDataArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return nil, shared.NewDecodeParamError(err.Error())
	}
	v := self.xeth.AtStateNum(args.BlockNumber).CodeAtBytes(args.Address)
	return newHexData(v), nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:8,代码来源:eth.go

示例15: SubmitHashrate

func (self *ethApi) SubmitHashrate(req *shared.Request) (interface{}, error) {
	args := new(SubmitHashRateArgs)
	if err := self.codec.Decode(req.Params, &args); err != nil {
		return false, shared.NewDecodeParamError(err.Error())
	}
	self.xeth.RemoteMining().SubmitHashrate(common.HexToHash(args.Id), args.Rate)
	return true, nil
}
开发者ID:codeaudit,项目名称:shift,代码行数:8,代码来源:eth.go


注:本文中的github.com/shiftcurrency/shift/rpc/shared.NewDecodeParamError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。