本文整理匯總了Golang中github.com/expanse-project/go-expanse/rpc/shared.NewDecodeParamError函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDecodeParamError函數的具體用法?Golang NewDecodeParamError怎麽用?Golang NewDecodeParamError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewDecodeParamError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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)
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: 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
}
示例8: 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
}
示例9: SignTransaction
func (self *ethApi) SignTransaction(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()
}
tx, err := self.xeth.SignTransaction(args.From, args.To, nonce, args.Value.String(), gas, price, args.Data)
if err != nil {
return nil, err
}
data, err := rlp.EncodeToBytes(tx)
if err != nil {
return nil, err
}
return JsonTransaction{"0x" + common.Bytes2Hex(data), newTx(tx)}, nil
}
示例10: 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
}
示例11: 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
}
示例12: GetFilterLogs
func (self *ethApi) GetFilterLogs(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 NewLogsRes(self.xeth.Logs(args.Id)), nil
}
示例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
}
示例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
}
示例15: Sleep
func (self *adminApi) Sleep(req *shared.Request) (interface{}, error) {
args := new(SleepArgs)
if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
time.Sleep(time.Duration(args.S) * time.Second)
return nil, nil
}