Skip to content

Commit

Permalink
fix: Add Events to TxResponse (backport cosmos#10630) (cosmos#10643)
Browse files Browse the repository at this point in the history
* fix: Add Events to TxResponse (cosmos#10630)

(cherry picked from commit c4bedf8)

# Conflicts:
#	CHANGELOG.md
#	go.sum
#	types/abci.pb.go
#	types/result.go

* FOR REAL.

* Merging the merge

* This is not a commit

* You wouldn't get this from any other guy

* We'll figure it out on Monday

Co-authored-by: Aleksandr Bezobchuk <[email protected]>
Co-authored-by: Aleksandr Bezobchuk <[email protected]>
  • Loading branch information
3 people authored Dec 2, 2021
1 parent 72fb852 commit fd34e37
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 117 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [v0.44.4](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.4) - 2021-11-25

### Improvements

* (types) [\#10630](https://github.com/cosmos/cosmos-sdk/pull/10630) Add an `Events` field to the `TxResponse` type that captures _all_ events emitted by a transaction, unlike `Logs` which only contains events emitted during message execution.
* (x/upgrade) [\#10532](https://github.com/cosmos/cosmos-sdk/pull/10532) Add `keeper.DumpUpgradeInfoWithInfoToDisk` to include `Plan.Info` in the upgrade-info file.
* (store) [\#10544](https://github.com/cosmos/cosmos-sdk/pull/10544) Use the new IAVL iterator structure which significantly improves iterator performance.

Expand Down
7 changes: 7 additions & 0 deletions proto/cosmos/base/abci/v1beta1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ message TxResponse {
// the timestamps of the valid votes in the block.LastCommit. For height == 1,
// it's genesis time.
string timestamp = 12;
// Events defines all the events emitted by processing a transaction. Note,
// these events include those emitted by processing all the messages and those
// emitted from the ante handler. Whereas Logs contains the events, with
// additional metadata, emitted only by processing the messages.
//
// Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
repeated tendermint.abci.Event events = 13 [(gogoproto.nullable) = false];
}

// ABCIMessageLog defines a structure containing an indexed tx ABCI message log.
Expand Down
180 changes: 121 additions & 59 deletions types/abci.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 7 additions & 44 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package types
import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"strings"

"github.com/gogo/protobuf/proto"

yaml "gopkg.in/yaml.v2"

abci "github.com/tendermint/tendermint/abci/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types"

Expand All @@ -21,12 +17,12 @@ import (
var cdc = codec.NewLegacyAmino()

func (gi GasInfo) String() string {
bz, _ := yaml.Marshal(gi)
bz, _ := codec.MarshalYAML(codec.NewProtoCodec(nil), &gi)
return string(bz)
}

func (r Result) String() string {
bz, _ := yaml.Marshal(r)
bz, _ := codec.MarshalYAML(codec.NewProtoCodec(nil), &r)
return string(bz)
}

Expand Down Expand Up @@ -83,6 +79,7 @@ func NewResponseResultTx(res *ctypes.ResultTx, anyTx *codectypes.Any, timestamp
GasUsed: res.TxResult.GasUsed,
Tx: anyTx,
Timestamp: timestamp,
Events: res.TxResult.Events,
}
}

Expand Down Expand Up @@ -123,6 +120,7 @@ func newTxResponseCheckTx(res *ctypes.ResultBroadcastTxCommit) *TxResponse {
Info: res.CheckTx.Info,
GasWanted: res.CheckTx.GasWanted,
GasUsed: res.CheckTx.GasUsed,
Events: res.CheckTx.Events,
}
}

Expand All @@ -149,6 +147,7 @@ func newTxResponseDeliverTx(res *ctypes.ResultBroadcastTxCommit) *TxResponse {
Info: res.DeliverTx.Info,
GasWanted: res.DeliverTx.GasWanted,
GasUsed: res.DeliverTx.GasUsed,
Events: res.DeliverTx.Events,
}
}

Expand All @@ -171,44 +170,8 @@ func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) *TxResponse {
}

func (r TxResponse) String() string {
var sb strings.Builder
sb.WriteString("Response:\n")

if r.Height > 0 {
sb.WriteString(fmt.Sprintf(" Height: %d\n", r.Height))
}
if r.TxHash != "" {
sb.WriteString(fmt.Sprintf(" TxHash: %s\n", r.TxHash))
}
if r.Code > 0 {
sb.WriteString(fmt.Sprintf(" Code: %d\n", r.Code))
}
if r.Data != "" {
sb.WriteString(fmt.Sprintf(" Data: %s\n", r.Data))
}
if r.RawLog != "" {
sb.WriteString(fmt.Sprintf(" Raw Log: %s\n", r.RawLog))
}
if r.Logs != nil {
sb.WriteString(fmt.Sprintf(" Logs: %s\n", r.Logs))
}
if r.Info != "" {
sb.WriteString(fmt.Sprintf(" Info: %s\n", r.Info))
}
if r.GasWanted != 0 {
sb.WriteString(fmt.Sprintf(" GasWanted: %d\n", r.GasWanted))
}
if r.GasUsed != 0 {
sb.WriteString(fmt.Sprintf(" GasUsed: %d\n", r.GasUsed))
}
if r.Codespace != "" {
sb.WriteString(fmt.Sprintf(" Codespace: %s\n", r.Codespace))
}
if r.Timestamp != "" {
sb.WriteString(fmt.Sprintf(" Timestamp: %s\n", r.Timestamp))
}

return strings.TrimSpace(sb.String())
bz, _ := codec.MarshalYAML(codec.NewProtoCodec(nil), &r)
return string(bz)
}

// Empty returns true if the response is empty
Expand Down
Loading

0 comments on commit fd34e37

Please sign in to comment.