From 22979d9365c7a78617ac4481d1259cb8bd40a359 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Sat, 1 Oct 2016 22:12:48 +0200 Subject: [PATCH] Fire proper EventData object on append transaction --- rpc/core/mempool.go | 11 +++++------ state/execution.go | 14 ++++++++++++-- types/events.go | 10 ++++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index bef85c796..4bc8f2866 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -52,9 +52,9 @@ func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { // subscribe to tx being committed in block - appendTxResCh := make(chan *tmsp.Response, 1) + appendTxResCh := make(chan types.EventDataTx, 1) eventSwitch.AddListenerForEvent("rpc", types.EventStringTx(tx), func(data events.EventData) { - appendTxResCh <- data.(*tmsp.Response) + appendTxResCh <- data.(types.EventDataTx) }) // broadcast the tx and register checktx callback @@ -84,11 +84,10 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { // The tx was included in a block. // NOTE we don't return an error regardless of the AppendTx code; // clients must check this to see if they need to send a new tx! - r := appendTxRes.GetAppendTx() return &ctypes.ResultBroadcastTx{ - Code: r.Code, - Data: r.Data, - Log: r.Log, + Code: appendTxRes.Code, + Data: appendTxRes.Result, + Log: appendTxRes.Log, }, nil case <-timer.C: r := checkTxR diff --git a/state/execution.go b/state/execution.go index 14ea965c1..9ae5601f0 100644 --- a/state/execution.go +++ b/state/execution.go @@ -67,15 +67,25 @@ func (s *State) execBlockOnProxyApp(eventCache events.Fireable, proxyAppConn pro // TODO: make use of this info // Blocks may include invalid txs. // reqAppendTx := req.(tmsp.RequestAppendTx) - if r.AppendTx.Code == tmsp.CodeType_OK { + txError := "" + apTx := r.AppendTx + if apTx.Code == tmsp.CodeType_OK { validTxs += 1 } else { log.Debug("Invalid tx", "code", r.AppendTx.Code, "log", r.AppendTx.Log) invalidTxs += 1 + txError = tmsp.CodeType_name[int32(apTx.Code)] // TODO } // NOTE: if we count we can access the tx from the block instead of // pulling it from the req - eventCache.FireEvent(types.EventStringTx(req.GetAppendTx().Tx), res) + event := types.EventDataTx{ + Tx: req.GetAppendTx().Tx, + Result: apTx.Data, + Code: apTx.Code, + Log: apTx.Log, + Error: txError, + } + eventCache.FireEvent(types.EventStringTx(req.GetAppendTx().Tx), event) } } proxyAppConn.SetResponseCallback(proxyCb) diff --git a/types/events.go b/types/events.go index 68313ff25..91b0757c3 100644 --- a/types/events.go +++ b/types/events.go @@ -5,6 +5,7 @@ import ( . "github.com/tendermint/go-common" "github.com/tendermint/go-events" "github.com/tendermint/go-wire" + tmsp "github.com/tendermint/tmsp/types" ) // Functions to generate eventId strings @@ -72,10 +73,11 @@ type EventDataNewBlockHeader struct { // All txs fire EventDataTx type EventDataTx struct { - Tx Tx `json:"tx"` - Result []byte `json:"result"` - Log string `json:"log"` - Error string `json:"error"` + Tx Tx `json:"tx"` + Result []byte `json:"result"` + Log string `json:"log"` + Code tmsp.CodeType `json:"code"` + Error string `json:"error"` } // NOTE: This goes into the replay WAL