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


Golang binary.ReadJSON函数代码示例

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


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

示例1: GetStorage

func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
	request := rpctypes.RPCRequest{
		JSONRPC: "2.0",
		Method:  reverseFuncMap["GetStorage"],
		Params:  []interface{}{address, key},
		Id:      0,
	}
	body, err := c.RequestResponse(request)
	if err != nil {
		return nil, err
	}
	var response struct {
		Result  *ctypes.ResponseGetStorage `json:"result"`
		Error   string                     `json:"error"`
		Id      string                     `json:"id"`
		JSONRPC string                     `json:"jsonrpc"`
	}
	binary.ReadJSON(&response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response.Result, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:26,代码来源:client_methods.go

示例2: BlockchainInfo

func (c *ClientHTTP) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.ResponseBlockchainInfo, error) {
	values, err := argsToURLValues([]string{"minHeight", "maxHeight"}, minHeight, maxHeight)
	if err != nil {
		return nil, err
	}
	resp, err := http.PostForm(c.addr+reverseFuncMap["BlockchainInfo"], values)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var response struct {
		Result  *ctypes.ResponseBlockchainInfo `json:"result"`
		Error   string                         `json:"error"`
		Id      string                         `json:"id"`
		JSONRPC string                         `json:"jsonrpc"`
	}
	binary.ReadJSON(&response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response.Result, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:29,代码来源:client_methods.go

示例3: ListValidators

func (c *ClientHTTP) ListValidators() (*ctypes.ResponseListValidators, error) {
	values, err := argsToURLValues(nil)
	if err != nil {
		return nil, err
	}
	resp, err := http.PostForm(c.addr+reverseFuncMap["ListValidators"], values)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var response struct {
		Result  *ctypes.ResponseListValidators `json:"result"`
		Error   string                         `json:"error"`
		Id      string                         `json:"id"`
		JSONRPC string                         `json:"jsonrpc"`
	}
	binary.ReadJSON(&response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response.Result, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:29,代码来源:client_methods.go

示例4: Status

func (c *ClientJSON) Status() (*ctypes.ResponseStatus, error) {
	request := rpctypes.RPCRequest{
		JSONRPC: "2.0",
		Method:  reverseFuncMap["Status"],
		Params:  []interface{}{},
		Id:      0,
	}
	body, err := c.RequestResponse(request)
	if err != nil {
		return nil, err
	}
	var response struct {
		Result  *ctypes.ResponseStatus `json:"result"`
		Error   string                 `json:"error"`
		Id      string                 `json:"id"`
		JSONRPC string                 `json:"jsonrpc"`
	}
	binary.ReadJSON(&response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response.Result, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:26,代码来源:client_methods.go

示例5: consumeMessage

func (c *Crawler) consumeMessage(wsMsg *rpcclient.WSMsg, node *Node) error {
	if wsMsg.Error != nil {
		return wsMsg.Error
	}
	// unmarshal block event
	var response struct {
		Event string
		Data  *types.Block
		Error string
	}
	var err error
	binary.ReadJSON(&response, wsMsg.Data, &err)
	if err != nil {
		return err
	}
	if response.Error != "" {
		return fmt.Errorf(response.Error)
	}
	block := response.Data

	node.LastSeen = time.Now()
	node.BlockHeight = block.Height
	node.BlockHistory[block.Height] = node.LastSeen

	return nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:26,代码来源:crawl.go

示例6: Call

func (c *ClientHTTP) Call(address []byte, data []byte) (*ctypes.ResponseCall, error) {
	values, err := argsToURLValues([]string{"address", "data"}, address, data)
	if err != nil {
		return nil, err
	}
	resp, err := http.PostForm(c.addr+reverseFuncMap["Call"], values)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var response struct {
		Result  *ctypes.ResponseCall `json:"result"`
		Error   string               `json:"error"`
		Id      string               `json:"id"`
		JSONRPC string               `json:"jsonrpc"`
	}
	binary.ReadJSON(&response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response.Result, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:29,代码来源:client_methods.go

示例7: unmarshalValidateSend

func unmarshalValidateSend(amt uint64, toAddr []byte) func(string, []byte) error {
	return func(eid string, b []byte) error {
		// unmarshal and assert correctness
		var response struct {
			Event string       `json:"event"`
			Data  types.SendTx `json:"data"`
			Error string       `json:"error"`
		}
		var err error
		binary.ReadJSON(&response, b, &err)
		if err != nil {
			return err
		}
		if response.Error != "" {
			return fmt.Errorf(response.Error)
		}
		if eid != response.Event {
			return fmt.Errorf("Eventid is not correct. Got %s, expected %s", response.Event, eid)
		}
		tx := response.Data
		if bytes.Compare(tx.Inputs[0].Address, userByteAddr) != 0 {
			return fmt.Errorf("Senders do not match up! Got %x, expected %x", tx.Inputs[0].Address, userByteAddr)
		}
		if tx.Inputs[0].Amount != amt {
			return fmt.Errorf("Amt does not match up! Got %d, expected %d", tx.Inputs[0].Amount, amt)
		}
		if bytes.Compare(tx.Outputs[0].Address, toAddr) != 0 {
			return fmt.Errorf("Receivers do not match up! Got %x, expected %x", tx.Outputs[0].Address, userByteAddr)
		}
		return nil
	}
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:32,代码来源:ws_helpers.go

示例8: unmarshalValidateCallCall

func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(string, []byte) error {
	return func(eid string, b []byte) error {
		// unmarshall and assert somethings
		var response struct {
			Event string             `json:"event"`
			Data  types.EventMsgCall `json:"data"`
			Error string             `json:"error"`
		}
		var err error
		binary.ReadJSON(&response, b, &err)
		if err != nil {
			return err
		}
		if response.Error != "" {
			return fmt.Errorf(response.Error)
		}
		if response.Data.Exception != "" {
			return fmt.Errorf(response.Data.Exception)
		}
		if bytes.Compare(response.Data.Origin, origin) != 0 {
			return fmt.Errorf("Origin does not match up! Got %x, expected %x", response.Data.Origin, origin)
		}
		ret := response.Data.Return
		if bytes.Compare(ret, returnCode) != 0 {
			return fmt.Errorf("Call did not return correctly. Got %x, expected %x", ret, returnCode)
		}
		if bytes.Compare(response.Data.TxId, *txid) != 0 {
			return fmt.Errorf("TxIds do not match up! Got %x, expected %x", response.Data.TxId, *txid)
		}
		return nil
	}
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:32,代码来源:ws_helpers.go

示例9: BroadcastTx

func (c *ClientHTTP) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
	values, err := argsToURLValues([]string{"tx"}, tx)
	if err != nil {
		return nil, err
	}
	resp, err := http.PostForm(c.addr+reverseFuncMap["BroadcastTx"], values)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	var response struct {
		Result  *ctypes.ResponseBroadcastTx `json:"result"`
		Error   string                      `json:"error"`
		Id      string                      `json:"id"`
		JSONRPC string                      `json:"jsonrpc"`
	}
	binary.ReadJSON(&response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response.Result, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:29,代码来源:client_methods.go

示例10: GenesisDocFromJSON

func GenesisDocFromJSON(jsonBlob []byte) (genState *GenesisDoc) {
	var err error
	binary.ReadJSON(&genState, jsonBlob, &err)
	if err != nil {
		panic(Fmt("Couldn't read GenesisDoc: %v", err))
	}
	return
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:8,代码来源:genesis.go

示例11: parseValidateCommandStr

func parseValidateCommandStr(authCommandStr string) (Command, error) {
	var err error
	authCommand := binary.ReadJSON(AuthCommand{}, []byte(authCommandStr), &err).(AuthCommand)
	if err != nil {
		fmt.Printf("Failed to parse auth_command")
		return nil, errors.New("AuthCommand parse error")
	}
	return parseValidateCommand(authCommand)
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:9,代码来源:main.go

示例12: _jsonStringToArg

func _jsonStringToArg(ty reflect.Type, arg string) (reflect.Value, error) {
	var err error
	v := reflect.New(ty)
	binary.ReadJSON(v.Interface(), []byte(arg), &err)
	if err != nil {
		return v, err
	}
	v = v.Elem()
	return v, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:10,代码来源:handlers.go

示例13: ReadConfig

func ReadConfig(configFilePath string) {
	configJSONBytes, err := ioutil.ReadFile(configFilePath)
	if err != nil {
		Exit(Fmt("Failed to read config file %v. %v\n", configFilePath, err))
	}
	binary.ReadJSON(&Config, configJSONBytes, &err)
	if err != nil {
		Exit(Fmt("Failed to parse config. %v", err))
	}
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:10,代码来源:main.go

示例14: LoadPrivValidator

func LoadPrivValidator(filePath string) *PrivValidator {
	privValJSONBytes, err := ioutil.ReadFile(filePath)
	if err != nil {
		panic(err)
	}
	privVal := binary.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator)
	if err != nil {
		Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err))
	}
	privVal.filePath = filePath
	return privVal
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:12,代码来源:priv_validator.go

示例15: unmarshalResponseNewBlock

func unmarshalResponseNewBlock(b []byte) (*types.Block, error) {
	// unmarshall and assert somethings
	var response struct {
		Event string       `json:"event"`
		Data  *types.Block `json:"data"`
		Error string       `json:"error"`
	}
	var err error
	binary.ReadJSON(&response, b, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	block := response.Data
	return block, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:18,代码来源:ws_helpers.go


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