Skip to content

Commit 5e35354

Browse files
authored
Merge PR #3451: Make tags and responses legible
1 parent f15ad04 commit 5e35354

File tree

23 files changed

+316
-286
lines changed

23 files changed

+316
-286
lines changed

PENDING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ BREAKING CHANGES
1414
- [\#3465](https://github.com/cosmos/cosmos-sdk/issues/3465) `gaiacli rest-server` switched back to insecure mode by default:
1515
- `--insecure` flag is removed.
1616
- `--tls` is now used to enable secure layer.
17+
- [\#3451](https://github.com/cosmos/cosmos-sdk/pull/3451) `gaiacli` now returns transactions in plain text including tags.
1718

1819
* Gaia
1920
* [\#3457](https://github.com/cosmos/cosmos-sdk/issues/3457) Changed governance tally validatorGovInfo to use sdk.Int power instead of sdk.Dec
@@ -86,7 +87,7 @@ BUG FIXES
8687
- [\#3345](https://github.com/cosmos/cosmos-sdk/issues/3345) Upgrade ledger-cosmos-go dependency to v0.9.3 to pull
8788
https://github.com/ZondaX/ledger-cosmos-go/commit/ed9aa39ce8df31bad1448c72d3d226bf2cb1a8d1 in order to fix a derivation path issue that causes `gaiacli keys add --recover`
8889
to malfunction.
89-
- [\#3419](https://github.com/cosmos/cosmos-sdk/pull/3419) Fix `q distr slashes` panic
90+
- [\#3419](https://github.com/cosmos/cosmos-sdk/pull/3419) Fix `q distr slashes` panic
9091
- [\#3453](https://github.com/cosmos/cosmos-sdk/pull/3453) The `rest-server` command didn't respect persistent flags such as `--chain-id` and `--trust-node` if they were
9192
passed on the command line.
9293

baseapp/baseapp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re
630630

631631
// Append Data and Tags
632632
data = append(data, msgResult.Data...)
633-
tags = append(tags, sdk.MakeTag(sdk.TagAction, []byte(msg.Type())))
633+
tags = append(tags, sdk.MakeTag(sdk.TagAction, msg.Type()))
634634
tags = append(tags, msgResult.Tags...)
635635

636636
// Stop execution and return on first failed message.

client/context/broadcast.go

Lines changed: 25 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,80 @@
11
package context
22

33
import (
4-
"fmt"
5-
"io"
6-
74
"github.com/pkg/errors"
85

9-
abci "github.com/tendermint/tendermint/abci/types"
10-
ctypes "github.com/tendermint/tendermint/rpc/core/types"
6+
sdk "github.com/cosmos/cosmos-sdk/types"
117
)
128

13-
// TODO: This should get deleted eventually, and perhaps
14-
// ctypes.ResultBroadcastTx be stripped of unused fields, and
15-
// ctypes.ResultBroadcastTxCommit returned for tendermint RPC BroadcastTxSync.
16-
//
17-
// The motivation is that we want a unified type to return, and the better
18-
// option is the one that can hold CheckTx/DeliverTx responses optionally.
19-
func resultBroadcastTxToCommit(res *ctypes.ResultBroadcastTx) *ctypes.ResultBroadcastTxCommit {
20-
return &ctypes.ResultBroadcastTxCommit{
21-
Hash: res.Hash,
22-
// NOTE: other fields are unused for async.
23-
}
24-
}
25-
269
// BroadcastTx broadcasts a transactions either synchronously or asynchronously
2710
// based on the context parameters. The result of the broadcast is parsed into
2811
// an intermediate structure which is logged if the context has a logger
2912
// defined.
30-
func (ctx CLIContext) BroadcastTx(txBytes []byte) (*ctypes.ResultBroadcastTxCommit, error) {
13+
func (ctx CLIContext) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) {
3114
if ctx.Async {
32-
res, err := ctx.broadcastTxAsync(txBytes)
33-
if err != nil {
34-
return nil, err
15+
if res, err = ctx.BroadcastTxAsync(txBytes); err != nil {
16+
return
3517
}
18+
return
19+
}
3620

37-
resCommit := resultBroadcastTxToCommit(res)
38-
return resCommit, err
21+
if res, err = ctx.BroadcastTxAndAwaitCommit(txBytes); err != nil {
22+
return
3923
}
4024

41-
return ctx.broadcastTxCommit(txBytes)
25+
return
4226
}
4327

4428
// BroadcastTxAndAwaitCommit broadcasts transaction bytes to a Tendermint node
4529
// and waits for a commit.
46-
func (ctx CLIContext) BroadcastTxAndAwaitCommit(tx []byte) (*ctypes.ResultBroadcastTxCommit, error) {
30+
func (ctx CLIContext) BroadcastTxAndAwaitCommit(tx []byte) (sdk.TxResponse, error) {
4731
node, err := ctx.GetNode()
4832
if err != nil {
49-
return nil, err
33+
return sdk.TxResponse{}, err
5034
}
5135

5236
res, err := node.BroadcastTxCommit(tx)
5337
if err != nil {
54-
return res, err
38+
return sdk.NewResponseFormatBroadcastTxCommit(res), err
5539
}
5640

5741
if !res.CheckTx.IsOK() {
58-
return res, errors.Errorf(res.CheckTx.Log)
42+
return sdk.NewResponseFormatBroadcastTxCommit(res), errors.Errorf(res.CheckTx.Log)
5943
}
6044

6145
if !res.DeliverTx.IsOK() {
62-
return res, errors.Errorf(res.DeliverTx.Log)
46+
return sdk.NewResponseFormatBroadcastTxCommit(res), errors.Errorf(res.DeliverTx.Log)
6347
}
6448

65-
return res, err
49+
return sdk.NewResponseFormatBroadcastTxCommit(res), err
6650
}
6751

68-
// BroadcastTxSync broadcasts transaction bytes to a Tendermint node
69-
// synchronously.
70-
func (ctx CLIContext) BroadcastTxSync(tx []byte) (*ctypes.ResultBroadcastTx, error) {
52+
// BroadcastTxSync broadcasts transaction bytes to a Tendermint node synchronously.
53+
func (ctx CLIContext) BroadcastTxSync(tx []byte) (sdk.TxResponse, error) {
7154
node, err := ctx.GetNode()
7255
if err != nil {
73-
return nil, err
56+
return sdk.TxResponse{}, err
7457
}
7558

7659
res, err := node.BroadcastTxSync(tx)
7760
if err != nil {
78-
return res, err
61+
return sdk.NewResponseFormatBroadcastTx(res), err
7962
}
8063

81-
return res, err
64+
return sdk.NewResponseFormatBroadcastTx(res), err
8265
}
8366

84-
// BroadcastTxAsync broadcasts transaction bytes to a Tendermint node
85-
// asynchronously.
86-
func (ctx CLIContext) BroadcastTxAsync(tx []byte) (*ctypes.ResultBroadcastTx, error) {
67+
// BroadcastTxAsync broadcasts transaction bytes to a Tendermint node asynchronously.
68+
func (ctx CLIContext) BroadcastTxAsync(tx []byte) (sdk.TxResponse, error) {
8769
node, err := ctx.GetNode()
8870
if err != nil {
89-
return nil, err
71+
return sdk.TxResponse{}, err
9072
}
9173

9274
res, err := node.BroadcastTxAsync(tx)
9375
if err != nil {
94-
return res, err
95-
}
96-
97-
return res, err
98-
}
99-
100-
func (ctx CLIContext) broadcastTxAsync(txBytes []byte) (*ctypes.ResultBroadcastTx, error) {
101-
res, err := ctx.BroadcastTxAsync(txBytes)
102-
if err != nil {
103-
return res, err
104-
}
105-
106-
if ctx.Output != nil {
107-
if ctx.OutputFormat == "json" {
108-
type toJSON struct {
109-
TxHash string
110-
}
111-
112-
resJSON := toJSON{res.Hash.String()}
113-
bz, err := ctx.Codec.MarshalJSON(resJSON)
114-
if err != nil {
115-
return res, err
116-
}
117-
118-
ctx.Output.Write(bz)
119-
io.WriteString(ctx.Output, "\n")
120-
} else {
121-
io.WriteString(ctx.Output, fmt.Sprintf("async tx sent (tx hash: %s)\n", res.Hash))
122-
}
123-
}
124-
125-
return res, nil
126-
}
127-
128-
func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcastTxCommit, error) {
129-
res, err := ctx.BroadcastTxAndAwaitCommit(txBytes)
130-
if err != nil {
131-
return res, err
132-
}
133-
134-
if ctx.OutputFormat == "json" {
135-
// Since JSON is intended for automated scripts, always include response in
136-
// JSON mode.
137-
type toJSON struct {
138-
Height int64
139-
TxHash string
140-
Response abci.ResponseDeliverTx
141-
}
142-
143-
if ctx.Output != nil {
144-
resJSON := toJSON{res.Height, res.Hash.String(), res.DeliverTx}
145-
bz, err := ctx.Codec.MarshalJSON(resJSON)
146-
if err != nil {
147-
return res, err
148-
}
149-
150-
ctx.Output.Write(bz)
151-
io.WriteString(ctx.Output, "\n")
152-
}
153-
154-
return res, nil
155-
}
156-
157-
if ctx.Output != nil {
158-
resStr := fmt.Sprintf("Committed at block %d (tx hash: %s)\n", res.Height, res.Hash.String())
159-
160-
if ctx.PrintResponse {
161-
resStr = fmt.Sprintf("Committed at block %d (tx hash: %s, response: %+v)\n",
162-
res.Height, res.Hash.String(), res.DeliverTx,
163-
)
164-
}
165-
166-
io.WriteString(ctx.Output, resStr)
76+
return sdk.NewResponseFormatBroadcastTx(res), err
16777
}
16878

169-
return res, nil
79+
return sdk.NewResponseFormatBroadcastTx(res), err
17080
}

0 commit comments

Comments
 (0)