Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup in tx tags and response format #4230

Merged
merged 3 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pending/breaking/sdk/4230-Change-the-type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4230 Change the type of ABCIMessageLog#MsgIndex to uint16 for proper serialization.
1 change: 1 addition & 0 deletions .pending/bugfixes/sdk/4230-Properly-set-an
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4230 Properly set and display the message index through the TxResponse.
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re
tags = append(tags, sdk.MakeTag(sdk.TagAction, msg.Type()))
tags = append(tags, msgResult.Tags...)

idxLog := sdk.ABCIMessageLog{MsgIndex: msgIdx, Log: msgResult.Log}
idxLog := sdk.ABCIMessageLog{MsgIndex: uint16(msgIdx), Log: msgResult.Log}

// stop execution and return on first failed message
if !msgResult.IsOK() {
Expand Down
10 changes: 5 additions & 5 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ABCIMessageLogs []ABCIMessageLog

// ABCIMessageLog defines a structure containing an indexed tx ABCI message log.
type ABCIMessageLog struct {
MsgIndex int `json:"msg_index"`
MsgIndex uint16 `json:"msg_index"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We change this to a uint16 for two reasons:

  1. We'll never exceed this anyway
  2. We're guaranteed this is encoded and decoded as an integer and not stringified first (due to Amino)

Success bool `json:"success"`
Log string `json:"log"`
}
Expand Down Expand Up @@ -229,10 +229,6 @@ func (r TxResponse) String() string {
sb.WriteString(fmt.Sprintf(" GasUsed: %d\n", r.GasUsed))
}

if len(r.Tags) > 0 {
sb.WriteString(fmt.Sprintf(" Tags: \n%s\n", r.Tags.String()))
}

if r.Codespace != "" {
sb.WriteString(fmt.Sprintf(" Codespace: %s\n", r.Codespace))
}
Expand All @@ -241,6 +237,10 @@ func (r TxResponse) String() string {
sb.WriteString(fmt.Sprintf(" Timestamp: %s\n", r.Timestamp))
}

if len(r.Tags) > 0 {
sb.WriteString(fmt.Sprintf(" Tags: \n%s\n", r.Tags.String()))
}

return strings.TrimSpace(sb.String())
}

Expand Down
3 changes: 2 additions & 1 deletion types/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (st StringTags) String() string {
for _, t := range st {
sb.WriteString(fmt.Sprintf(" - %s\n", t.String()))
}
return sb.String()

return strings.TrimRight(sb.String(), "\n")
}

// Conversion function from a []byte tag to a string tag
Expand Down