Browse Source

Fire proper EventData object on append transaction

pull/286/head
Ethan Frey 8 years ago
parent
commit
22979d9365
3 changed files with 23 additions and 12 deletions
  1. +5
    -6
      rpc/core/mempool.go
  2. +12
    -2
      state/execution.go
  3. +6
    -4
      types/events.go

+ 5
- 6
rpc/core/mempool.go View File

@ -52,9 +52,9 @@ func BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
// subscribe to tx being committed in block // 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) { 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 // 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. // The tx was included in a block.
// NOTE we don't return an error regardless of the AppendTx code; // 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! // clients must check this to see if they need to send a new tx!
r := appendTxRes.GetAppendTx()
return &ctypes.ResultBroadcastTx{ return &ctypes.ResultBroadcastTx{
Code: r.Code,
Data: r.Data,
Log: r.Log,
Code: appendTxRes.Code,
Data: appendTxRes.Result,
Log: appendTxRes.Log,
}, nil }, nil
case <-timer.C: case <-timer.C:
r := checkTxR r := checkTxR


+ 12
- 2
state/execution.go View File

@ -67,15 +67,25 @@ func (s *State) execBlockOnProxyApp(eventCache events.Fireable, proxyAppConn pro
// TODO: make use of this info // TODO: make use of this info
// Blocks may include invalid txs. // Blocks may include invalid txs.
// reqAppendTx := req.(tmsp.RequestAppendTx) // reqAppendTx := req.(tmsp.RequestAppendTx)
if r.AppendTx.Code == tmsp.CodeType_OK {
txError := ""
apTx := r.AppendTx
if apTx.Code == tmsp.CodeType_OK {
validTxs += 1 validTxs += 1
} else { } else {
log.Debug("Invalid tx", "code", r.AppendTx.Code, "log", r.AppendTx.Log) log.Debug("Invalid tx", "code", r.AppendTx.Code, "log", r.AppendTx.Log)
invalidTxs += 1 invalidTxs += 1
txError = tmsp.CodeType_name[int32(apTx.Code)] // TODO
} }
// NOTE: if we count we can access the tx from the block instead of // NOTE: if we count we can access the tx from the block instead of
// pulling it from the req // 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) proxyAppConn.SetResponseCallback(proxyCb)


+ 6
- 4
types/events.go View File

@ -5,6 +5,7 @@ import (
. "github.com/tendermint/go-common" . "github.com/tendermint/go-common"
"github.com/tendermint/go-events" "github.com/tendermint/go-events"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
tmsp "github.com/tendermint/tmsp/types"
) )
// Functions to generate eventId strings // Functions to generate eventId strings
@ -72,10 +73,11 @@ type EventDataNewBlockHeader struct {
// All txs fire EventDataTx // All txs fire EventDataTx
type EventDataTx struct { 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 // NOTE: This goes into the replay WAL


Loading…
Cancel
Save