Ejemplo n.º 1
0
func (app *localClient) CommitAsync() *ReqRes {
	app.mtx.Lock()
	res := app.Application.Commit()
	app.mtx.Unlock()
	return app.callback(
		types.ToRequestCommit(),
		types.ToResponseCommit(res.Code, res.Data, res.Log),
	)
}
Ejemplo n.º 2
0
func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types.Response) {
	switch r := req.Value.(type) {
	case *types.Request_Echo:
		responses <- types.ToResponseEcho(r.Echo.Message)
	case *types.Request_Flush:
		responses <- types.ToResponseFlush()
	case *types.Request_Info:
		data := s.app.Info()
		responses <- types.ToResponseInfo(data)
	case *types.Request_SetOption:
		so := r.SetOption
		logStr := s.app.SetOption(so.Key, so.Value)
		responses <- types.ToResponseSetOption(logStr)
	case *types.Request_AppendTx:
		res := s.app.AppendTx(r.AppendTx.Tx)
		responses <- types.ToResponseAppendTx(res.Code, res.Data, res.Log)
	case *types.Request_CheckTx:
		res := s.app.CheckTx(r.CheckTx.Tx)
		responses <- types.ToResponseCheckTx(res.Code, res.Data, res.Log)
	case *types.Request_Commit:
		res := s.app.Commit()
		responses <- types.ToResponseCommit(res.Code, res.Data, res.Log)
	case *types.Request_Query:
		res := s.app.Query(r.Query.Query)
		responses <- types.ToResponseQuery(res.Code, res.Data, res.Log)
	case *types.Request_InitChain:
		if app, ok := s.app.(types.BlockchainAware); ok {
			app.InitChain(r.InitChain.Validators)
			responses <- types.ToResponseInitChain()
		} else {
			responses <- types.ToResponseInitChain()
		}
	case *types.Request_EndBlock:
		if app, ok := s.app.(types.BlockchainAware); ok {
			validators := app.EndBlock(r.EndBlock.Height)
			responses <- types.ToResponseEndBlock(validators)
		} else {
			responses <- types.ToResponseEndBlock(nil)
		}
	default:
		responses <- types.ToResponseException("Unknown request")
	}
}