Merge PR #5032: Add Events to ABCIMessageLog

This commit is contained in:
Alexander Bezobchuk
2019-09-12 11:05:27 -04:00
committed by GitHub
parent 5bcab79e8a
commit 9eb5375fda
4 changed files with 38 additions and 12 deletions
+20 -2
View File
@@ -7,6 +7,8 @@ import (
"math"
"strings"
"github.com/cosmos/cosmos-sdk/codec"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
@@ -50,12 +52,25 @@ type ABCIMessageLog struct {
MsgIndex uint16 `json:"msg_index"`
Success bool `json:"success"`
Log string `json:"log"`
// Events contains a slice of Event objects that were emitted during some
// execution.
Events StringEvents `json:"events"`
}
func NewABCIMessageLog(i uint16, success bool, log string, events Events) ABCIMessageLog {
return ABCIMessageLog{
MsgIndex: i,
Success: success,
Log: log,
Events: StringifyEvents(events.ToABCIEvents()),
}
}
// String implements the fmt.Stringer interface for the ABCIMessageLogs type.
func (logs ABCIMessageLogs) String() (str string) {
if logs != nil {
raw, err := json.Marshal(logs)
raw, err := codec.Cdc.MarshalJSON(logs)
if err == nil {
str = string(raw)
}
@@ -76,10 +91,13 @@ type TxResponse struct {
Info string `json:"info,omitempty"`
GasWanted int64 `json:"gas_wanted,omitempty"`
GasUsed int64 `json:"gas_used,omitempty"`
Events StringEvents `json:"events,omitempty"`
Codespace string `json:"codespace,omitempty"`
Tx Tx `json:"tx,omitempty"`
Timestamp string `json:"timestamp,omitempty"`
// DEPRECATED: Remove in the next next major release in favor of using the
// ABCIMessageLog.Events field.
Events StringEvents `json:"events,omitempty"`
}
// NewResponseResultTx returns a TxResponse given a ResultTx from tendermint
+11
View File
@@ -3,6 +3,7 @@ package types
import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/stretchr/testify/require"
)
@@ -27,3 +28,13 @@ func TestParseABCILog(t *testing.T) {
require.Equal(t, res[0].MsgIndex, uint16(1))
require.True(t, res[0].Success)
}
func TestABCIMessageLog(t *testing.T) {
events := Events{NewEvent("transfer", NewAttribute("sender", "foo"))}
msgLog := NewABCIMessageLog(0, true, "", events)
msgLogs := ABCIMessageLogs{msgLog}
bz, err := codec.Cdc.MarshalJSON(msgLogs)
require.NoError(t, err)
require.Equal(t, string(bz), msgLogs.String())
}