Ejemplo n.º 1
0
func handleRequest(app types.Application, req *types.Request, responses chan<- *types.Response) {
	switch req.Type {
	case types.MessageType_Echo:
		responses <- types.ResponseEcho(string(req.Data))
	case types.MessageType_Flush:
		responses <- types.ResponseFlush()
	case types.MessageType_Info:
		data := app.Info()
		responses <- types.ResponseInfo(data)
	case types.MessageType_SetOption:
		logStr := app.SetOption(req.Key, req.Value)
		responses <- types.ResponseSetOption(logStr)
	case types.MessageType_AppendTx:
		code, result, logStr := app.AppendTx(req.Data)
		responses <- types.ResponseAppendTx(code, result, logStr)
	case types.MessageType_CheckTx:
		code, result, logStr := app.CheckTx(req.Data)
		responses <- types.ResponseCheckTx(code, result, logStr)
	case types.MessageType_Commit:
		hash, logStr := app.Commit()
		responses <- types.ResponseCommit(hash, logStr)
	case types.MessageType_Query:
		code, result, logStr := app.Query(req.Data)
		responses <- types.ResponseQuery(code, result, logStr)
	default:
		responses <- types.ResponseException("Unknown request")
	}
}
Ejemplo n.º 2
0
func (app *localAppConn) CheckTxAsync(tx []byte) *tmspcli.ReqRes {
	app.mtx.Lock()
	code, result, log := app.Application.CheckTx(tx)
	app.mtx.Unlock()
	app.Callback(
		tmsp.RequestCheckTx(tx),
		tmsp.ResponseCheckTx(code, result, log),
	)
	return nil // TODO maybe create a ReqRes
}