本文整理汇总了Golang中github.com/tendermint/tendermint/binary.ReadJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadJSON函数的具体用法?Golang ReadJSON怎么用?Golang ReadJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadJSON函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: parseValidateCommand
func parseValidateCommand(authCommand AuthCommand) (Command, error) {
commandJSONStr := authCommand.CommandJSONStr
signatures := authCommand.Signatures
// Validate commandJSONStr
if !validate([]byte(commandJSONStr), barak.validators, signatures) {
fmt.Printf("Failed validation attempt")
return nil, errors.New("Validation error")
}
// Parse command
var err error
command := binary.ReadJSON(NoncedCommand{}, []byte(commandJSONStr), &err).(NoncedCommand)
if err != nil {
fmt.Printf("Failed to parse command")
return nil, errors.New("Command parse error")
}
// Prevent replays
if barak.nonce+1 != command.Nonce {
return nil, errors.New("Replay error")
} else {
barak.nonce += 1
}
return command.Command, nil
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:23,代码来源:main.go
示例17: unmarshalValidateCall
func unmarshalValidateCall(amt uint64, returnCode []byte) func(string, []byte) error {
return func(eid string, b []byte) error {
// unmarshall and assert somethings
var response struct {
Event string `json:"event"`
Data struct {
Tx types.CallTx `json:"tx"`
Return []byte `json:"return"`
Exception string `json:"exception"`
} `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)
}
tx := response.Data.Tx
if bytes.Compare(tx.Input.Address, userByteAddr) != 0 {
return fmt.Errorf("Senders do not match up! Got %x, expected %x", tx.Input.Address, userByteAddr)
}
if tx.Input.Amount != amt {
return fmt.Errorf("Amt does not match up! Got %d, expected %d", tx.Input.Amount, amt)
}
ret := response.Data.Return
if bytes.Compare(ret, returnCode) != 0 {
return fmt.Errorf("Call did not return correctly. Got %x, expected %x", ret, returnCode)
}
return nil
}
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:37,代码来源:ws_helpers.go
示例18: main
func main() {
fmt.Printf("New Barak Process (PID: %d)\n", os.Getpid())
// Apply bare tendermint/* configuration.
cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "info"}))
// read flags to change options file.
var optionsBytes []byte
var optionsFile string
var err error
flag.StringVar(&optionsFile, "options-file", "", "Read options from file instead of stdin")
flag.Parse()
if optionsFile != "" {
optionsBytes, err = ioutil.ReadFile(optionsFile)
} else {
optionsBytes, err = ioutil.ReadAll(os.Stdin)
}
if err != nil {
panic(Fmt("Error reading input: %v", err))
}
options := binary.ReadJSON(&Options{}, optionsBytes, &err).(*Options)
if err != nil {
panic(Fmt("Error parsing input: %v", err))
}
barak.nonce = options.StartNonce
barak.validators = options.Validators
barak.rootDir = os.Getenv("BRKROOT")
if barak.rootDir == "" {
barak.rootDir = os.Getenv("HOME") + "/.barak"
}
err = EnsureDir(barak.rootDir)
if err != nil {
panic(Fmt("Error creating barak rootDir: %v", err))
}
barak.registries = options.Registries
// Debug.
fmt.Printf("Options: %v\n", options)
fmt.Printf("Barak: %v\n", barak)
// Start rpc server.
mux := http.NewServeMux()
mux.HandleFunc("/download", ServeFile)
mux.HandleFunc("/register", Register)
// TODO: mux.HandleFunc("/upload", UploadFile)
rpcserver.RegisterRPCFuncs(mux, Routes)
rpcserver.StartHTTPServer(options.ListenAddress, mux)
// Register this barak with central listener
for _, registry := range barak.registries {
go func(registry string) {
for {
resp, err := http.Get(registry + "/register")
if err != nil {
fmt.Printf("Error registering to registry %v:\n %v\n", registry, err)
time.Sleep(1 * time.Hour)
continue
}
body, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("Successfully registered with registry %v\n %v\n", registry, string(body))
return
}
}(registry)
}
// Write pid to file. This should be the last thing before TrapSignal.
err = WriteFileAtomic(barak.rootDir+"/pidfile", []byte(Fmt("%v", barak.pid)))
if err != nil {
panic(Fmt("Error writing pidfile: %v", err))
}
TrapSignal(func() {
fmt.Println("Barak shutting down")
})
}
开发者ID:jaekwon,项目名称:GuppyCamp,代码行数:75,代码来源:main.go
注:本文中的github.com/tendermint/tendermint/binary.ReadJSON函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论