當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。