Beispiel #1
0
func unmarshalCheckResponse(body []byte) (response *ctypes.Response, err error) {
	response = new(ctypes.Response)
	wire.ReadJSON(response, body, &err)
	if err != nil {
		return nil, err
	}
	if response.Error != "" {
		return nil, fmt.Errorf(response.Error)
	}
	return response, nil
}
func LoadPrivValidator(filePath string) *PrivValidator {
	privValJSONBytes, err := ioutil.ReadFile(filePath)
	if err != nil {
		Exit(err.Error())
	}
	privVal := wire.ReadJSON(&PrivValidator{}, privValJSONBytes, &err).(*PrivValidator)
	if err != nil {
		Exit(Fmt("Error reading PrivValidator from %v: %v\n", filePath, err))
	}
	privVal.filePath = filePath
	return privVal
}
Beispiel #3
0
func (wsc *WSClient) receiveEventsRoutine() {
	for {
		_, data, err := wsc.ReadMessage()
		if err != nil {
			log.Info("WSClient failed to read message", "error", err, "data", string(data))
			wsc.Stop()
			break
		} else {
			var response ctypes.Response
			wire.ReadJSON(&response, data, &err)
			if err != nil {
				log.Info("WSClient failed to parse message", "error", err)
				wsc.Stop()
				break
			}
			if strings.HasSuffix(response.ID, "#event") {
				wsc.EventsCh <- *response.Result.(*ctypes.ResultEvent)
			} else {
				wsc.ResultsCh <- response.Result
			}
		}
	}
}