diff --git a/PENDING.md b/PENDING.md index dc5351877..109e18ab5 100644 --- a/PENDING.md +++ b/PENDING.md @@ -14,6 +14,7 @@ BREAKING CHANGES - [\#3465](https://github.com/cosmos/cosmos-sdk/issues/3465) `gaiacli rest-server` switched back to insecure mode by default: - `--insecure` flag is removed. - `--tls` is now used to enable secure layer. + - [\#3451](https://github.com/cosmos/cosmos-sdk/pull/3451) `gaiacli` now returns transactions in plain text including tags. * Gaia * [\#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 - [\#3345](https://github.com/cosmos/cosmos-sdk/issues/3345) Upgrade ledger-cosmos-go dependency to v0.9.3 to pull https://github.com/ZondaX/ledger-cosmos-go/commit/ed9aa39ce8df31bad1448c72d3d226bf2cb1a8d1 in order to fix a derivation path issue that causes `gaiacli keys add --recover` to malfunction. - - [\#3419](https://github.com/cosmos/cosmos-sdk/pull/3419) Fix `q distr slashes` panic + - [\#3419](https://github.com/cosmos/cosmos-sdk/pull/3419) Fix `q distr slashes` panic - [\#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 passed on the command line. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 6a6cc7960..2c24a57b1 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -630,7 +630,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re // Append Data and Tags data = append(data, msgResult.Data...) - tags = append(tags, sdk.MakeTag(sdk.TagAction, []byte(msg.Type()))) + tags = append(tags, sdk.MakeTag(sdk.TagAction, msg.Type())) tags = append(tags, msgResult.Tags...) // Stop execution and return on first failed message. diff --git a/client/context/broadcast.go b/client/context/broadcast.go index c844e519d..21a88d99d 100644 --- a/client/context/broadcast.go +++ b/client/context/broadcast.go @@ -1,170 +1,80 @@ package context import ( - "fmt" - "io" - "github.com/pkg/errors" - abci "github.com/tendermint/tendermint/abci/types" - ctypes "github.com/tendermint/tendermint/rpc/core/types" + sdk "github.com/cosmos/cosmos-sdk/types" ) -// TODO: This should get deleted eventually, and perhaps -// ctypes.ResultBroadcastTx be stripped of unused fields, and -// ctypes.ResultBroadcastTxCommit returned for tendermint RPC BroadcastTxSync. -// -// The motivation is that we want a unified type to return, and the better -// option is the one that can hold CheckTx/DeliverTx responses optionally. -func resultBroadcastTxToCommit(res *ctypes.ResultBroadcastTx) *ctypes.ResultBroadcastTxCommit { - return &ctypes.ResultBroadcastTxCommit{ - Hash: res.Hash, - // NOTE: other fields are unused for async. - } -} - // BroadcastTx broadcasts a transactions either synchronously or asynchronously // based on the context parameters. The result of the broadcast is parsed into // an intermediate structure which is logged if the context has a logger // defined. -func (ctx CLIContext) BroadcastTx(txBytes []byte) (*ctypes.ResultBroadcastTxCommit, error) { +func (ctx CLIContext) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) { if ctx.Async { - res, err := ctx.broadcastTxAsync(txBytes) - if err != nil { - return nil, err + if res, err = ctx.BroadcastTxAsync(txBytes); err != nil { + return } - - resCommit := resultBroadcastTxToCommit(res) - return resCommit, err + return } - return ctx.broadcastTxCommit(txBytes) + if res, err = ctx.BroadcastTxAndAwaitCommit(txBytes); err != nil { + return + } + + return } // BroadcastTxAndAwaitCommit broadcasts transaction bytes to a Tendermint node // and waits for a commit. -func (ctx CLIContext) BroadcastTxAndAwaitCommit(tx []byte) (*ctypes.ResultBroadcastTxCommit, error) { +func (ctx CLIContext) BroadcastTxAndAwaitCommit(tx []byte) (sdk.TxResponse, error) { node, err := ctx.GetNode() if err != nil { - return nil, err + return sdk.TxResponse{}, err } res, err := node.BroadcastTxCommit(tx) if err != nil { - return res, err + return sdk.NewResponseFormatBroadcastTxCommit(res), err } if !res.CheckTx.IsOK() { - return res, errors.Errorf(res.CheckTx.Log) + return sdk.NewResponseFormatBroadcastTxCommit(res), errors.Errorf(res.CheckTx.Log) } if !res.DeliverTx.IsOK() { - return res, errors.Errorf(res.DeliverTx.Log) + return sdk.NewResponseFormatBroadcastTxCommit(res), errors.Errorf(res.DeliverTx.Log) } - return res, err + return sdk.NewResponseFormatBroadcastTxCommit(res), err } -// BroadcastTxSync broadcasts transaction bytes to a Tendermint node -// synchronously. -func (ctx CLIContext) BroadcastTxSync(tx []byte) (*ctypes.ResultBroadcastTx, error) { +// BroadcastTxSync broadcasts transaction bytes to a Tendermint node synchronously. +func (ctx CLIContext) BroadcastTxSync(tx []byte) (sdk.TxResponse, error) { node, err := ctx.GetNode() if err != nil { - return nil, err + return sdk.TxResponse{}, err } res, err := node.BroadcastTxSync(tx) if err != nil { - return res, err + return sdk.NewResponseFormatBroadcastTx(res), err } - return res, err + return sdk.NewResponseFormatBroadcastTx(res), err } -// BroadcastTxAsync broadcasts transaction bytes to a Tendermint node -// asynchronously. -func (ctx CLIContext) BroadcastTxAsync(tx []byte) (*ctypes.ResultBroadcastTx, error) { +// BroadcastTxAsync broadcasts transaction bytes to a Tendermint node asynchronously. +func (ctx CLIContext) BroadcastTxAsync(tx []byte) (sdk.TxResponse, error) { node, err := ctx.GetNode() if err != nil { - return nil, err + return sdk.TxResponse{}, err } res, err := node.BroadcastTxAsync(tx) if err != nil { - return res, err + return sdk.NewResponseFormatBroadcastTx(res), err } - return res, err -} - -func (ctx CLIContext) broadcastTxAsync(txBytes []byte) (*ctypes.ResultBroadcastTx, error) { - res, err := ctx.BroadcastTxAsync(txBytes) - if err != nil { - return res, err - } - - if ctx.Output != nil { - if ctx.OutputFormat == "json" { - type toJSON struct { - TxHash string - } - - resJSON := toJSON{res.Hash.String()} - bz, err := ctx.Codec.MarshalJSON(resJSON) - if err != nil { - return res, err - } - - ctx.Output.Write(bz) - io.WriteString(ctx.Output, "\n") - } else { - io.WriteString(ctx.Output, fmt.Sprintf("async tx sent (tx hash: %s)\n", res.Hash)) - } - } - - return res, nil -} - -func (ctx CLIContext) broadcastTxCommit(txBytes []byte) (*ctypes.ResultBroadcastTxCommit, error) { - res, err := ctx.BroadcastTxAndAwaitCommit(txBytes) - if err != nil { - return res, err - } - - if ctx.OutputFormat == "json" { - // Since JSON is intended for automated scripts, always include response in - // JSON mode. - type toJSON struct { - Height int64 - TxHash string - Response abci.ResponseDeliverTx - } - - if ctx.Output != nil { - resJSON := toJSON{res.Height, res.Hash.String(), res.DeliverTx} - bz, err := ctx.Codec.MarshalJSON(resJSON) - if err != nil { - return res, err - } - - ctx.Output.Write(bz) - io.WriteString(ctx.Output, "\n") - } - - return res, nil - } - - if ctx.Output != nil { - resStr := fmt.Sprintf("Committed at block %d (tx hash: %s)\n", res.Height, res.Hash.String()) - - if ctx.PrintResponse { - resStr = fmt.Sprintf("Committed at block %d (tx hash: %s, response: %+v)\n", - res.Height, res.Hash.String(), res.DeliverTx, - ) - } - - io.WriteString(ctx.Output, resStr) - } - - return res, nil + return sdk.NewResponseFormatBroadcastTx(res), err } diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 0a2e72b05..c9842c7eb 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -12,11 +12,8 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" - ctypes "github.com/tendermint/tendermint/rpc/core/types" - - "github.com/cosmos/cosmos-sdk/client" + client "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/rest" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/cmd/gaia/app" "github.com/cosmos/cosmos-sdk/crypto/keys/mintkey" @@ -170,8 +167,7 @@ func TestCoinSend(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) // query sender acc = getAccount(t, port, addr) @@ -232,8 +228,7 @@ func TestCoinSend(t *testing.T) { require.Nil(t, err) tests.WaitForHeight(resultTx.Height+1, port) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) acc = getAccount(t, port, addr) expectedBalance = expectedBalance.Minus(fees[0]) @@ -348,11 +343,10 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) { require.Equal(t, http.StatusOK, res.StatusCode, body) // check if tx was committed - var resultTx ctypes.ResultBroadcastTxCommit + var resultTx sdk.TxResponse require.Nil(t, cdc.UnmarshalJSON([]byte(body), &resultTx)) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) - require.Equal(t, gasEstimate, resultTx.DeliverTx.GasWanted) + require.Equal(t, uint32(0), resultTx.Code) + require.Equal(t, gasEstimate, resultTx.GasWanted) } func TestTxs(t *testing.T) { @@ -360,7 +354,7 @@ func TestTxs(t *testing.T) { cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}) defer cleanup() - var emptyTxs []tx.Info + var emptyTxs []sdk.TxResponse txs := getTransactions(t, port) require.Equal(t, emptyTxs, txs) @@ -380,14 +374,13 @@ func TestTxs(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx is queryable - tx := getTransaction(t, port, resultTx.Hash.String()) - require.Equal(t, resultTx.Hash, tx.Hash) + tx := getTransaction(t, port, resultTx.TxHash) + require.Equal(t, resultTx.TxHash, tx.TxHash) // query sender txs = getTransactions(t, port, fmt.Sprintf("sender=%s", addr.String())) require.Len(t, txs, 1) require.Equal(t, resultTx.Height, txs[0].Height) - fmt.Println(txs[0]) // query recipient txs = getTransactions(t, port, fmt.Sprintf("recipient=%s", receiveAddr.String())) @@ -465,8 +458,7 @@ func TestBonding(t *testing.T) { resultTx := doDelegate(t, port, name1, pw, addr, operAddrs[0], 60, fees) tests.WaitForHeight(resultTx.Height+1, port) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) // query tx txs := getTransactions(t, port, @@ -507,8 +499,7 @@ func TestBonding(t *testing.T) { resultTx = doUndelegate(t, port, name1, pw, addr, operAddrs[0], 30, fees) tests.WaitForHeight(resultTx.Height+1, port) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) // sender should have not received any coins as the unbonding has only just begun acc = getAccount(t, port, addr) @@ -537,8 +528,7 @@ func TestBonding(t *testing.T) { resultTx = doBeginRedelegation(t, port, name1, pw, addr, operAddrs[0], operAddrs[1], 30, fees) tests.WaitForHeight(resultTx.Height+1, port) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) // verify balance after paying fees acc = getAccount(t, port, addr) @@ -618,11 +608,10 @@ func TestSubmitProposal(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) var proposalID uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID) + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID) // verify balance acc = getAccount(t, port, addr) @@ -651,11 +640,10 @@ func TestDeposit(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) var proposalID uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID) + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID) // verify balance acc = getAccount(t, port, addr) @@ -704,11 +692,10 @@ func TestVote(t *testing.T) { tests.WaitForHeight(resultTx.Height+1, port) // check if tx was committed - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) var proposalID uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID) + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID) // verify balance acc = getAccount(t, port, addr) @@ -802,18 +789,18 @@ func TestProposalsQuery(t *testing.T) { // Addr1 proposes (and deposits) proposals #1 and #2 resultTx := doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit, fees) var proposalID1 uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID1) + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID1) tests.WaitForHeight(resultTx.Height+1, port) resultTx = doSubmitProposal(t, port, seeds[0], names[0], passwords[0], addrs[0], halfMinDeposit, fees) var proposalID2 uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID2) + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID2) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 proposes (and deposits) proposals #3 resultTx = doSubmitProposal(t, port, seeds[1], names[1], passwords[1], addrs[1], halfMinDeposit, fees) var proposalID3 uint64 - cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.DeliverTx.GetData(), &proposalID3) + cdc.MustUnmarshalBinaryLengthPrefixed(resultTx.Data, &proposalID3) tests.WaitForHeight(resultTx.Height+1, port) // Addr2 deposits on proposals #2 & #3 @@ -956,14 +943,12 @@ func TestDistributionFlow(t *testing.T) { // Delegate some coins resultTx := doDelegate(t, port, name1, pw, addr, valAddr, 60, fees) tests.WaitForHeight(resultTx.Height+1, port) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) // send some coins _, resultTx = doTransfer(t, port, seed, name1, memo, pw, addr, fees) tests.WaitForHeight(resultTx.Height+5, port) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) // Query outstanding rewards changed oustandingRewards := mustParseDecCoins("9.80stake") @@ -1013,6 +998,5 @@ func TestDistributionFlow(t *testing.T) { // Withdraw delegator's rewards resultTx = doWithdrawDelegatorAllRewards(t, port, seed, name1, pw, addr, fees) - require.Equal(t, uint32(0), resultTx.CheckTx.Code) - require.Equal(t, uint32(0), resultTx.DeliverTx.Code) + require.Equal(t, uint32(0), resultTx.Code) } diff --git a/client/lcd/test_helpers.go b/client/lcd/test_helpers.go index efef932a6..58b6319a6 100644 --- a/client/lcd/test_helpers.go +++ b/client/lcd/test_helpers.go @@ -506,8 +506,8 @@ func getValidatorSets(t *testing.T, port string, height int, expectFail bool) rp } // GET /txs/{hash} get tx by hash -func getTransaction(t *testing.T, port string, hash string) tx.Info { - var tx tx.Info +func getTransaction(t *testing.T, port string, hash string) sdk.TxResponse { + var tx sdk.TxResponse res, body := Request(t, port, "GET", fmt.Sprintf("/txs/%s", hash), nil) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -519,8 +519,8 @@ func getTransaction(t *testing.T, port string, hash string) tx.Info { // POST /txs broadcast txs // GET /txs search transactions -func getTransactions(t *testing.T, port string, tags ...string) []tx.Info { - var txs []tx.Info +func getTransactions(t *testing.T, port string, tags ...string) []sdk.TxResponse { + var txs []sdk.TxResponse if len(tags) == 0 { return txs } @@ -667,13 +667,13 @@ func doSign(t *testing.T, port, name, password, chainID string, accnum, sequence } // POST /tx/broadcast Send a signed Tx -func doBroadcast(t *testing.T, port string, msg auth.StdTx) ctypes.ResultBroadcastTxCommit { +func doBroadcast(t *testing.T, port string, msg auth.StdTx) sdk.TxResponse { tx := broadcastReq{Tx: msg, Return: "block"} req, err := cdc.MarshalJSON(tx) require.Nil(t, err) res, body := Request(t, port, "POST", "/tx/broadcast", req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var resultTx ctypes.ResultBroadcastTxCommit + var resultTx sdk.TxResponse require.Nil(t, cdc.UnmarshalJSON([]byte(body), &resultTx)) return resultTx } @@ -686,7 +686,7 @@ type broadcastReq struct { // GET /bank/balances/{address} Get the account balances // POST /bank/accounts/{address}/transfers Send coins (build -> sign -> send) -func doTransfer(t *testing.T, port, seed, name, memo, password string, addr sdk.AccAddress, fees sdk.Coins) (receiveAddr sdk.AccAddress, resultTx ctypes.ResultBroadcastTxCommit) { +func doTransfer(t *testing.T, port, seed, name, memo, password string, addr sdk.AccAddress, fees sdk.Coins) (receiveAddr sdk.AccAddress, resultTx sdk.TxResponse) { res, body, receiveAddr := doTransferWithGas(t, port, seed, name, memo, password, addr, "", 1.0, false, false, fees) require.Equal(t, http.StatusOK, res.StatusCode, body) @@ -782,7 +782,7 @@ type sendReq struct { // POST /staking/delegators/{delegatorAddr}/delegations Submit delegation func doDelegate(t *testing.T, port, name, password string, - delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { + delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx sdk.TxResponse) { acc := getAccount(t, port, delAddr) accnum := acc.GetAccountNumber() sequence := acc.GetSequence() @@ -799,7 +799,7 @@ func doDelegate(t *testing.T, port, name, password string, res, body := Request(t, port, "POST", fmt.Sprintf("/staking/delegators/%s/delegations", delAddr.String()), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var result ctypes.ResultBroadcastTxCommit + var result sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &result) require.Nil(t, err) @@ -815,7 +815,7 @@ type msgDelegationsInput struct { // POST /staking/delegators/{delegatorAddr}/delegations Submit delegation func doUndelegate(t *testing.T, port, name, password string, - delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { + delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx sdk.TxResponse) { acc := getAccount(t, port, delAddr) accnum := acc.GetAccountNumber() @@ -834,7 +834,7 @@ func doUndelegate(t *testing.T, port, name, password string, res, body := Request(t, port, "POST", fmt.Sprintf("/staking/delegators/%s/unbonding_delegations", delAddr), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var result ctypes.ResultBroadcastTxCommit + var result sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &result) require.Nil(t, err) @@ -850,7 +850,7 @@ type msgUndelegateInput struct { // POST /staking/delegators/{delegatorAddr}/delegations Submit delegation func doBeginRedelegation(t *testing.T, port, name, password string, - delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { + delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount int64, fees sdk.Coins) (resultTx sdk.TxResponse) { acc := getAccount(t, port, delAddr) accnum := acc.GetAccountNumber() @@ -872,7 +872,7 @@ func doBeginRedelegation(t *testing.T, port, name, password string, res, body := Request(t, port, "POST", fmt.Sprintf("/staking/delegators/%s/redelegations", delAddr), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var result ctypes.ResultBroadcastTxCommit + var result sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &result) require.Nil(t, err) @@ -961,7 +961,7 @@ func getDelegatorValidator(t *testing.T, port string, delegatorAddr sdk.AccAddre } // GET /staking/delegators/{delegatorAddr}/txs Get all staking txs (i.e msgs) from a delegator -func getBondingTxs(t *testing.T, port string, delegatorAddr sdk.AccAddress, query string) []tx.Info { +func getBondingTxs(t *testing.T, port string, delegatorAddr sdk.AccAddress, query string) []sdk.TxResponse { var res *http.Response var body string @@ -972,7 +972,7 @@ func getBondingTxs(t *testing.T, port string, delegatorAddr sdk.AccAddress, quer } require.Equal(t, http.StatusOK, res.StatusCode, body) - var txs []tx.Info + var txs []sdk.TxResponse err := cdc.UnmarshalJSON([]byte(body), &txs) require.Nil(t, err) @@ -1083,7 +1083,7 @@ func getStakingParams(t *testing.T, port string) staking.Params { // ICS 22 - Gov // ---------------------------------------------------------------------- // POST /gov/proposals Submit a proposal -func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, amount int64, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { +func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, amount int64, fees sdk.Coins) (resultTx sdk.TxResponse) { acc := getAccount(t, port, proposerAddr) accnum := acc.GetAccountNumber() sequence := acc.GetSequence() @@ -1106,7 +1106,7 @@ func doSubmitProposal(t *testing.T, port, seed, name, password string, proposerA res, body := Request(t, port, "POST", "/gov/proposals", req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var results ctypes.ResultBroadcastTxCommit + var results sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &results) require.Nil(t, err) @@ -1178,7 +1178,7 @@ func getProposalsFilterStatus(t *testing.T, port string, status gov.ProposalStat } // POST /gov/proposals/{proposalId}/deposits Deposit tokens to a proposal -func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID uint64, amount int64, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { +func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID uint64, amount int64, fees sdk.Coins) (resultTx sdk.TxResponse) { acc := getAccount(t, port, proposerAddr) accnum := acc.GetAccountNumber() @@ -1198,7 +1198,7 @@ func doDeposit(t *testing.T, port, seed, name, password string, proposerAddr sdk res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/deposits", proposalID), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var results ctypes.ResultBroadcastTxCommit + var results sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &results) require.Nil(t, err) @@ -1232,7 +1232,7 @@ func getTally(t *testing.T, port string, proposalID uint64) gov.TallyResult { } // POST /gov/proposals/{proposalId}/votes Vote a proposal -func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID uint64, option string, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { +func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.AccAddress, proposalID uint64, option string, fees sdk.Coins) (resultTx sdk.TxResponse) { // get the account to get the sequence acc := getAccount(t, port, proposerAddr) accnum := acc.GetAccountNumber() @@ -1252,7 +1252,7 @@ func doVote(t *testing.T, port, seed, name, password string, proposerAddr sdk.Ac res, body := Request(t, port, "POST", fmt.Sprintf("/gov/proposals/%d/votes", proposalID), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var results ctypes.ResultBroadcastTxCommit + var results sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &results) require.Nil(t, err) @@ -1368,7 +1368,7 @@ func getSigningInfo(t *testing.T, port string, validatorPubKey string) slashing. // TODO: Test this functionality, it is not currently in any of the tests // POST /slashing/validators/{validatorAddr}/unjail Unjail a jailed validator func doUnjail(t *testing.T, port, seed, name, password string, - valAddr sdk.ValAddress, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { + valAddr sdk.ValAddress, fees sdk.Coins) (resultTx sdk.TxResponse) { chainID := viper.GetString(client.FlagChainID) baseReq := rest.NewBaseReq(name, password, "", chainID, "", "", 1, 1, fees, nil, false, false) @@ -1380,11 +1380,11 @@ func doUnjail(t *testing.T, port, seed, name, password string, res, body := Request(t, port, "POST", fmt.Sprintf("/slashing/validators/%s/unjail", valAddr.String()), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var results []ctypes.ResultBroadcastTxCommit + var results sdk.TxResponse err = cdc.UnmarshalJSON([]byte(body), &results) require.Nil(t, err) - return results[0] + return results } type unjailReq struct { @@ -1395,7 +1395,7 @@ type unjailReq struct { // POST /distribution/delegators/{delgatorAddr}/rewards Withdraw delegator rewards func doWithdrawDelegatorAllRewards(t *testing.T, port, seed, name, password string, - delegatorAddr sdk.AccAddress, fees sdk.Coins) (resultTx ctypes.ResultBroadcastTxCommit) { + delegatorAddr sdk.AccAddress, fees sdk.Coins) (resultTx sdk.TxResponse) { // get the account to get the sequence acc := getAccount(t, port, delegatorAddr) accnum := acc.GetAccountNumber() @@ -1411,7 +1411,7 @@ func doWithdrawDelegatorAllRewards(t *testing.T, port, seed, name, password stri res, body := Request(t, port, "POST", fmt.Sprintf("/distribution/delegators/%s/rewards", delegatorAddr), req) require.Equal(t, http.StatusOK, res.StatusCode, body) - var results ctypes.ResultBroadcastTxCommit + var results sdk.TxResponse cdc.MustUnmarshalJSON([]byte(body), &results) return results diff --git a/client/tx/query.go b/client/tx/query.go index 754b5ba96..cbf64f34e 100644 --- a/client/tx/query.go +++ b/client/tx/query.go @@ -5,19 +5,15 @@ import ( "fmt" "net/http" - "github.com/cosmos/cosmos-sdk/client/rest" - - "github.com/tendermint/tendermint/libs/common" - "github.com/gorilla/mux" "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/spf13/viper" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" + "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" @@ -100,26 +96,13 @@ func ValidateTxResult(cliCtx context.CLIContext, res *ctypes.ResultTx) error { return nil } -func formatTxResult(cdc *codec.Codec, res *ctypes.ResultTx) (Info, error) { +func formatTxResult(cdc *codec.Codec, res *ctypes.ResultTx) (sdk.TxResponse, error) { tx, err := parseTx(cdc, res.Tx) if err != nil { - return Info{}, err + return sdk.TxResponse{}, err } - return Info{ - Hash: res.Hash, - Height: res.Height, - Tx: tx, - Result: res.TxResult, - }, nil -} - -// Info is used to prepare info to display -type Info struct { - Hash common.HexBytes `json:"hash"` - Height int64 `json:"height"` - Tx sdk.Tx `json:"tx"` - Result abci.ResponseDeliverTx `json:"result"` + return sdk.NewResponseResultTx(res, tx), nil } func parseTx(cdc *codec.Codec, txBytes []byte) (sdk.Tx, error) { diff --git a/client/tx/search.go b/client/tx/search.go index 97beee075..91c3b32c4 100644 --- a/client/tx/search.go +++ b/client/tx/search.go @@ -106,7 +106,7 @@ $ gaiacli query txs --tags ':&:' --page 1 --limit 30 // SearchTxs performs a search for transactions for a given set of tags via // Tendermint RPC. It returns a slice of Info object containing txs and metadata. // An error is returned if the query fails. -func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string, page, limit int) ([]Info, error) { +func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string, page, limit int) ([]sdk.TxResponse, error) { if len(tags) == 0 { return nil, errors.New("must declare at least one tag to search") } @@ -153,9 +153,9 @@ func SearchTxs(cliCtx context.CLIContext, cdc *codec.Codec, tags []string, page, } // parse the indexed txs into an array of Info -func FormatTxResults(cdc *codec.Codec, res []*ctypes.ResultTx) ([]Info, error) { +func FormatTxResults(cdc *codec.Codec, res []*ctypes.ResultTx) ([]sdk.TxResponse, error) { var err error - out := make([]Info, len(res)) + out := make([]sdk.TxResponse, len(res)) for i := range res { out[i], err = formatTxResult(cdc, res[i]) if err != nil { @@ -173,7 +173,7 @@ func SearchTxRequestHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http. return func(w http.ResponseWriter, r *http.Request) { var tags []string var page, limit int - var txs []Info + var txs []sdk.TxResponse err := r.ParseForm() if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, sdk.AppendMsgToErr("could not parse query parameters", err.Error())) diff --git a/client/utils/utils.go b/client/utils/utils.go index b5ae87eab..0123f0952 100644 --- a/client/utils/utils.go +++ b/client/utils/utils.go @@ -69,7 +69,8 @@ func CompleteAndBroadcastTxCLI(txBldr authtxb.TxBuilder, cliCtx context.CLIConte } // broadcast to a Tendermint node - _, err = cliCtx.BroadcastTx(txBytes) + res, err := cliCtx.BroadcastTx(txBytes) + cliCtx.PrintOutput(res) return err } diff --git a/cmd/gaia/cli_test/cli_test.go b/cmd/gaia/cli_test/cli_test.go index 0b6d5790d..6c58b6bee 100644 --- a/cmd/gaia/cli_test/cli_test.go +++ b/cmd/gaia/cli_test/cli_test.go @@ -14,8 +14,6 @@ import ( "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/cmd/gaia/app" "github.com/cosmos/cosmos-sdk/tests" @@ -272,14 +270,10 @@ func TestGaiaCLIGasAuto(t *testing.T) { require.NotEmpty(t, stderr) require.True(t, success) cdc := app.MakeCodec() - sendResp := struct { - Height int64 - TxHash string - Response abci.ResponseDeliverTx - }{} + sendResp := sdk.TxResponse{} err := cdc.UnmarshalJSON([]byte(stdout), &sendResp) require.Nil(t, err) - require.True(t, sendResp.Response.GasWanted >= sendResp.Response.GasUsed) + require.True(t, sendResp.GasWanted >= sendResp.GasUsed) tests.WaitForNextNBlocksTM(1, f.Port) // Check state has changed accordingly @@ -684,14 +678,12 @@ func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) { success, stdout, _ = f.TxBroadcast(signedTxFile.Name()) require.True(t, success) - var result struct { - Response abci.ResponseDeliverTx - } + var result sdk.TxResponse // Unmarshal the response and ensure that gas was properly used require.Nil(t, app.MakeCodec().UnmarshalJSON([]byte(stdout), &result)) - require.True(t, msg.Fee.Gas >= uint64(result.Response.GasUsed)) - require.Equal(t, msg.Fee.Gas, uint64(result.Response.GasWanted)) + require.Equal(t, msg.Fee.Gas, uint64(result.GasUsed)) + require.Equal(t, msg.Fee.Gas, uint64(result.GasWanted)) tests.WaitForNextNBlocksTM(1, f.Port) // Ensure account state diff --git a/cmd/gaia/cli_test/test_helpers.go b/cmd/gaia/cli_test/test_helpers.go index b2288382f..93fae3689 100644 --- a/cmd/gaia/cli_test/test_helpers.go +++ b/cmd/gaia/cli_test/test_helpers.go @@ -14,7 +14,6 @@ import ( cmn "github.com/tendermint/tendermint/libs/common" "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/cmd/gaia/app" appInit "github.com/cosmos/cosmos-sdk/cmd/gaia/init" "github.com/cosmos/cosmos-sdk/codec" @@ -352,10 +351,10 @@ func (f *Fixtures) QueryAccount(address sdk.AccAddress, flags ...string) auth.Ba // gaiacli query txs // QueryTxs is gaiacli query txs -func (f *Fixtures) QueryTxs(page, limit int, tags ...string) []tx.Info { +func (f *Fixtures) QueryTxs(page, limit int, tags ...string) []sdk.TxResponse { cmd := fmt.Sprintf("gaiacli query txs --page=%d --limit=%d --tags='%s' %v", page, limit, queryTags(tags), f.Flags()) out, _ := tests.ExecuteT(f.T, cmd, "") - var txs []tx.Info + var txs []sdk.TxResponse cdc := app.MakeCodec() err := cdc.UnmarshalJSON([]byte(out), &txs) require.NoError(f.T, err, "out %v\n, err %v", out, err) diff --git a/types/result.go b/types/result.go index 924b73b49..f51de775b 100644 --- a/types/result.go +++ b/types/result.go @@ -1,6 +1,13 @@ package types -// Result is the union of ResponseDeliverTx and ResponseCheckTx. +import ( + "fmt" + "strings" + + ctypes "github.com/tendermint/tendermint/rpc/core/types" +) + +// Result is the union of ResponseFormat and ResponseCheckTx. type Result struct { // Code is the response code, is stored back on the chain. @@ -33,3 +40,104 @@ type Result struct { func (res Result) IsOK() bool { return res.Code.IsOK() } + +// Is a version of TxResponse where the tags are StringTags rather than []byte tags +type TxResponse struct { + Height int64 `json:"height"` + TxHash string `json:"txhash"` + Code uint32 `json:"code,omitempty"` + Data []byte `json:"data,omitempty"` + Log string `json:"log,omitempty"` + Info string `json:"info,omitempty"` + GasWanted int64 `json:"gas_wanted,omitempty"` + GasUsed int64 `json:"gas_used,omitempty"` + Tags StringTags `json:"tags,omitempty"` + Codespace string `json:"codespace,omitempty"` + Tx Tx `json:"tx,omitempty"` +} + +func NewResponseResultTx(res *ctypes.ResultTx, tx Tx) TxResponse { + return TxResponse{ + TxHash: res.Hash.String(), + Height: res.Height, + Code: res.TxResult.Code, + Data: res.TxResult.Data, + Log: res.TxResult.Log, + Info: res.TxResult.Info, + GasWanted: res.TxResult.GasWanted, + GasUsed: res.TxResult.GasUsed, + Tags: TagsToStringTags(res.TxResult.Tags), + Tx: tx, + } +} + +func NewResponseFormatBroadcastTxCommit(res *ctypes.ResultBroadcastTxCommit) TxResponse { + return TxResponse{ + Height: res.Height, + TxHash: res.Hash.String(), + Code: res.DeliverTx.Code, + Data: res.DeliverTx.Data, + Log: res.DeliverTx.Log, + Info: res.DeliverTx.Info, + GasWanted: res.DeliverTx.GasWanted, + GasUsed: res.DeliverTx.GasUsed, + Tags: TagsToStringTags(res.DeliverTx.Tags), + Codespace: res.DeliverTx.Codespace, + } +} + +func NewResponseFormatBroadcastTx(res *ctypes.ResultBroadcastTx) TxResponse { + return TxResponse{ + Code: res.Code, + Data: res.Data.Bytes(), + Log: res.Log, + TxHash: res.Hash.String(), + } +} + +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 != nil { + sb.WriteString(fmt.Sprintf(" Data: %s\n", string(r.Data))) + } + + if r.Log != "" { + sb.WriteString(fmt.Sprintf(" Log: %s\n", r.Log)) + } + + 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 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)) + } + + return strings.TrimSpace(sb.String()) +} diff --git a/types/tags.go b/types/tags.go index add0c0ad5..befabc36a 100644 --- a/types/tags.go +++ b/types/tags.go @@ -1,6 +1,9 @@ package types import ( + "fmt" + "strings" + cmn "github.com/tendermint/tendermint/libs/common" ) @@ -16,7 +19,7 @@ func EmptyTags() Tags { } // Append a single tag -func (t Tags) AppendTag(k string, v []byte) Tags { +func (t Tags) AppendTag(k string, v string) Tags { return append(t, MakeTag(k, v)) } @@ -41,15 +44,26 @@ func NewTags(tags ...interface{}) Tags { if i == len(tags) { break } - ret = append(ret, Tag{Key: []byte(tags[i].(string)), Value: tags[i+1].([]byte)}) + ret = append(ret, Tag{Key: toBytes(tags[i]), Value: toBytes(tags[i+1])}) i += 2 } return ret } +func toBytes(i interface{}) []byte { + switch x := i.(type) { + case []uint8: + return x + case string: + return []byte(x) + default: + panic(i) + } +} + // Make a tag from a key and a value -func MakeTag(k string, v []byte) Tag { - return Tag{Key: []byte(k), Value: v} +func MakeTag(k string, v string) Tag { + return Tag{Key: []byte(k), Value: []byte(v)} } //__________________________________________________ @@ -61,3 +75,41 @@ var ( TagDstValidator = "destination-validator" TagDelegator = "delegator" ) + +// A KVPair where the Key and Value are both strings, rather than []byte +type StringTag struct { + Key string `json:"key"` + Value string `json:"value,omitempty"` +} + +func (st StringTag) String() string { + return fmt.Sprintf("%s = %s", st.Key, st.Value) +} + +// A slice of StringTag +type StringTags []StringTag + +func (st StringTags) String() string { + var sb strings.Builder + for _, t := range st { + sb.WriteString(fmt.Sprintf(" - %s\n", t.String())) + } + return strings.TrimSpace(sb.String()) +} + +// Conversion function from a []byte tag to a string tag +func TagToStringTag(tag Tag) StringTag { + return StringTag{ + Key: string(tag.Key), + Value: string(tag.Value), + } +} + +// Conversion function from Tags to a StringTags +func TagsToStringTags(tags Tags) StringTags { + var stringTags StringTags + for _, tag := range tags { + stringTags = append(stringTags, TagToStringTag(tag)) + } + return stringTags +} diff --git a/types/tags_test.go b/types/tags_test.go index 77bb4041c..9ce59cf7f 100644 --- a/types/tags_test.go +++ b/types/tags_test.go @@ -7,11 +7,11 @@ import ( ) func TestAppendTags(t *testing.T) { - a := NewTags("a", []byte("1")) - b := NewTags("b", []byte("2")) + a := NewTags("a", "1") + b := NewTags("b", "2") c := a.AppendTags(b) - require.Equal(t, c, Tags{MakeTag("a", []byte("1")), MakeTag("b", []byte("2"))}) - require.Equal(t, c, Tags{MakeTag("a", []byte("1"))}.AppendTag("b", []byte("2"))) + require.Equal(t, c, Tags{MakeTag("a", "1"), MakeTag("b", "2")}) + require.Equal(t, c, Tags{MakeTag("a", "1")}.AppendTag("b", "2")) } func TestEmptyTags(t *testing.T) { @@ -20,16 +20,16 @@ func TestEmptyTags(t *testing.T) { } func TestNewTags(t *testing.T) { - b := NewTags("a", []byte("1")) - require.Equal(t, b, Tags{MakeTag("a", []byte("1"))}) + b := NewTags("a", "1") + require.Equal(t, b, Tags{MakeTag("a", "1")}) - require.Panics(t, func() { NewTags("a", []byte("1"), "b") }) + require.Panics(t, func() { NewTags("a", "1", "b") }) require.Panics(t, func() { NewTags("a", 1) }) require.Panics(t, func() { NewTags(1, 1) }) require.Panics(t, func() { NewTags(true, false) }) } func TestKVPairTags(t *testing.T) { - a := NewTags("a", []byte("1")) + a := NewTags("a", "1") require.Equal(t, a, Tags(a.ToKVPairs())) } diff --git a/x/bank/client/cli/broadcast.go b/x/bank/client/cli/broadcast.go index 1bcd811cd..48734e392 100644 --- a/x/bank/client/cli/broadcast.go +++ b/x/bank/client/cli/broadcast.go @@ -33,7 +33,8 @@ in place of an input filename, the command reads from standard input.`, return } - _, err = cliCtx.BroadcastTx(txBytes) + res, err := cliCtx.BroadcastTx(txBytes) + cliCtx.PrintOutput(res) return err }, } diff --git a/x/bank/keeper.go b/x/bank/keeper.go index 978507e5c..534facec5 100644 --- a/x/bank/keeper.go +++ b/x/bank/keeper.go @@ -248,7 +248,7 @@ func subtractCoins(ctx sdk.Context, ak auth.AccountKeeper, addr sdk.AccAddress, newCoins := oldCoins.Minus(amt) // should not panic as spendable coins was already checked err := setCoins(ctx, ak, addr, newCoins) - tags := sdk.NewTags(TagKeySender, []byte(addr.String())) + tags := sdk.NewTags(TagKeySender, addr.String()) return newCoins, tags, err } @@ -263,7 +263,7 @@ func addCoins(ctx sdk.Context, am auth.AccountKeeper, addr sdk.AccAddress, amt s } err := setCoins(ctx, am, addr, newCoins) - tags := sdk.NewTags(TagKeyRecipient, []byte(addr.String())) + tags := sdk.NewTags(TagKeyRecipient, addr.String()) return newCoins, tags, err } diff --git a/x/gov/handler.go b/x/gov/handler.go index 947ce5407..aee576dc2 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -27,7 +27,7 @@ func NewHandler(keeper Keeper) sdk.Handler { func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitProposal) sdk.Result { proposal := keeper.NewTextProposal(ctx, msg.Title, msg.Description, msg.ProposalType) proposalID := proposal.GetProposalID() - proposalIDBytes := []byte(fmt.Sprintf("%d", proposalID)) + proposalIDStr := fmt.Sprintf("%d", proposalID) err, votingStarted := keeper.AddDeposit(ctx, proposalID, msg.Proposer, msg.InitialDeposit) if err != nil { @@ -36,11 +36,11 @@ func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitPropos resTags := sdk.NewTags( tags.Proposer, []byte(msg.Proposer.String()), - tags.ProposalID, proposalIDBytes, + tags.ProposalID, proposalIDStr, ) if votingStarted { - resTags = resTags.AppendTag(tags.VotingPeriodStart, proposalIDBytes) + resTags = resTags.AppendTag(tags.VotingPeriodStart, proposalIDStr) } return sdk.Result{ @@ -55,14 +55,14 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) sdk.Result return err.Result() } - proposalIDBytes := []byte(fmt.Sprintf("%d", msg.ProposalID)) + proposalIDStr := fmt.Sprintf("%d", msg.ProposalID) resTags := sdk.NewTags( tags.Depositor, []byte(msg.Depositor.String()), - tags.ProposalID, proposalIDBytes, + tags.ProposalID, proposalIDStr, ) if votingStarted { - resTags = resTags.AppendTag(tags.VotingPeriodStart, proposalIDBytes) + resTags = resTags.AppendTag(tags.VotingPeriodStart, proposalIDStr) } return sdk.Result{ @@ -78,8 +78,8 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result { return sdk.Result{ Tags: sdk.NewTags( - tags.Voter, []byte(msg.Voter.String()), - tags.ProposalID, []byte(fmt.Sprintf("%d", msg.ProposalID)), + tags.Voter, msg.Voter.String(), + tags.ProposalID, fmt.Sprintf("%d", msg.ProposalID), ), } } @@ -99,7 +99,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags { keeper.DeleteProposal(ctx, proposalID) keeper.DeleteDeposits(ctx, proposalID) // delete any associated deposits (burned) - resTags = resTags.AppendTag(tags.ProposalID, []byte(fmt.Sprintf("%d", proposalID))) + resTags = resTags.AppendTag(tags.ProposalID, fmt.Sprintf("%d", proposalID)) resTags = resTags.AppendTag(tags.ProposalResult, tags.ActionProposalDropped) logger.Info( @@ -122,7 +122,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags { activeProposal := keeper.GetProposal(ctx, proposalID) passes, tallyResults := tally(ctx, keeper, activeProposal) - var tagValue []byte + var tagValue string if passes { keeper.RefundDeposits(ctx, activeProposal.GetProposalID()) activeProposal.SetStatus(StatusPassed) @@ -144,7 +144,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags { ), ) - resTags = resTags.AppendTag(tags.ProposalID, []byte(fmt.Sprintf("%d", proposalID))) + resTags = resTags.AppendTag(tags.ProposalID, fmt.Sprintf("%d", proposalID)) resTags = resTags.AppendTag(tags.ProposalResult, tagValue) } diff --git a/x/gov/tags/tags.go b/x/gov/tags/tags.go index a4b58d8b2..6f18b2596 100644 --- a/x/gov/tags/tags.go +++ b/x/gov/tags/tags.go @@ -6,9 +6,9 @@ import ( // Governance tags var ( - ActionProposalDropped = []byte("proposal-dropped") - ActionProposalPassed = []byte("proposal-passed") - ActionProposalRejected = []byte("proposal-rejected") + ActionProposalDropped = "proposal-dropped" + ActionProposalPassed = "proposal-passed" + ActionProposalRejected = "proposal-rejected" Action = sdk.TagAction Proposer = "proposer" diff --git a/x/slashing/handler.go b/x/slashing/handler.go index 2bed8db94..d0a26ff76 100644 --- a/x/slashing/handler.go +++ b/x/slashing/handler.go @@ -56,7 +56,7 @@ func handleMsgUnjail(ctx sdk.Context, msg MsgUnjail, k Keeper) sdk.Result { tags := sdk.NewTags( tags.Action, tags.ActionValidatorUnjailed, - tags.Validator, []byte(msg.ValidatorAddr.String()), + tags.Validator, msg.ValidatorAddr.String(), ) return sdk.Result{ diff --git a/x/slashing/tags/tags.go b/x/slashing/tags/tags.go index 9ab5a48bd..12c1d616f 100644 --- a/x/slashing/tags/tags.go +++ b/x/slashing/tags/tags.go @@ -6,7 +6,7 @@ import ( // Slashing tags var ( - ActionValidatorUnjailed = []byte("validator-unjailed") + ActionValidatorUnjailed = "validator-unjailed" Action = sdk.TagAction Validator = "validator" diff --git a/x/staking/client/rest/query.go b/x/staking/client/rest/query.go index 2ffefbda1..88e625194 100644 --- a/x/staking/client/rest/query.go +++ b/x/staking/client/rest/query.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/rest" "github.com/cosmos/cosmos-sdk/client/context" - "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" @@ -145,7 +144,7 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han isBondTx := contains(typesQuerySlice, "bond") isUnbondTx := contains(typesQuerySlice, "unbond") isRedTx := contains(typesQuerySlice, "redelegate") - var txs = []tx.Info{} + var txs = []sdk.TxResponse{} var actions []string switch { @@ -153,16 +152,16 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec) http.Han actions = append(actions, staking.MsgDelegate{}.Type()) case isUnbondTx: actions = append(actions, staking.MsgUndelegate{}.Type()) - actions = append(actions, string(tags.ActionCompleteUnbonding)) + actions = append(actions, tags.ActionCompleteUnbonding) case isRedTx: actions = append(actions, staking.MsgBeginRedelegate{}.Type()) - actions = append(actions, string(tags.ActionCompleteRedelegation)) + actions = append(actions, tags.ActionCompleteRedelegation) case noQuery: actions = append(actions, staking.MsgDelegate{}.Type()) actions = append(actions, staking.MsgUndelegate{}.Type()) - actions = append(actions, string(tags.ActionCompleteUnbonding)) + actions = append(actions, tags.ActionCompleteUnbonding) actions = append(actions, staking.MsgBeginRedelegate{}.Type()) - actions = append(actions, string(tags.ActionCompleteRedelegation)) + actions = append(actions, tags.ActionCompleteRedelegation) default: w.WriteHeader(http.StatusNoContent) return diff --git a/x/staking/client/rest/utils.go b/x/staking/client/rest/utils.go index c9e2ed9d9..3efd05d54 100644 --- a/x/staking/client/rest/utils.go +++ b/x/staking/client/rest/utils.go @@ -29,7 +29,7 @@ func contains(stringSlice []string, txType string) bool { } // queries staking txs -func queryTxs(node rpcclient.Client, cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) ([]tx.Info, error) { +func queryTxs(node rpcclient.Client, cliCtx context.CLIContext, cdc *codec.Codec, tag string, delegatorAddr string) ([]sdk.TxResponse, error) { page := 0 perPage := 100 prove := !cliCtx.TrustNode diff --git a/x/staking/handler.go b/x/staking/handler.go index 1b8813a19..3bf5ddf05 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -62,8 +62,8 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) ([]abci.ValidatorUpdate, sdk.T resTags.AppendTags(sdk.NewTags( tags.Action, ActionCompleteUnbonding, - tags.Delegator, []byte(dvPair.DelegatorAddr.String()), - tags.SrcValidator, []byte(dvPair.ValidatorAddr.String()), + tags.Delegator, dvPair.DelegatorAddr.String(), + tags.SrcValidator, dvPair.ValidatorAddr.String(), )) } @@ -78,9 +78,9 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) ([]abci.ValidatorUpdate, sdk.T resTags.AppendTags(sdk.NewTags( tags.Action, tags.ActionCompleteRedelegation, - tags.Delegator, []byte(dvvTriplet.DelegatorAddr.String()), - tags.SrcValidator, []byte(dvvTriplet.ValidatorSrcAddr.String()), - tags.DstValidator, []byte(dvvTriplet.ValidatorDstAddr.String()), + tags.Delegator, dvvTriplet.DelegatorAddr.String(), + tags.SrcValidator, dvvTriplet.ValidatorSrcAddr.String(), + tags.DstValidator, dvvTriplet.ValidatorDstAddr.String(), )) } @@ -145,9 +145,9 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k } tags := sdk.NewTags( - tags.DstValidator, []byte(msg.ValidatorAddr.String()), - tags.Moniker, []byte(msg.Description.Moniker), - tags.Identity, []byte(msg.Description.Identity), + tags.DstValidator, msg.ValidatorAddr.String(), + tags.Moniker, msg.Description.Moniker, + tags.Identity, msg.Description.Identity, ) return sdk.Result{ @@ -183,9 +183,9 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe k.SetValidator(ctx, validator) tags := sdk.NewTags( - tags.DstValidator, []byte(msg.ValidatorAddr.String()), - tags.Moniker, []byte(description.Moniker), - tags.Identity, []byte(description.Identity), + tags.DstValidator, msg.ValidatorAddr.String(), + tags.Moniker, description.Moniker, + tags.Identity, description.Identity, ) return sdk.Result{ @@ -213,8 +213,8 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper) } tags := sdk.NewTags( - tags.Delegator, []byte(msg.DelegatorAddr.String()), - tags.DstValidator, []byte(msg.ValidatorAddr.String()), + tags.Delegator, msg.DelegatorAddr.String(), + tags.DstValidator, msg.ValidatorAddr.String(), ) return sdk.Result{ @@ -230,9 +230,9 @@ func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keep finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(completionTime) tags := sdk.NewTags( - tags.Delegator, []byte(msg.DelegatorAddr.String()), - tags.SrcValidator, []byte(msg.ValidatorAddr.String()), - tags.EndTime, []byte(completionTime.Format(time.RFC3339)), + tags.Delegator, msg.DelegatorAddr.String(), + tags.SrcValidator, msg.ValidatorAddr.String(), + tags.EndTime, completionTime.Format(time.RFC3339), ) return sdk.Result{Data: finishTime, Tags: tags} @@ -247,10 +247,10 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg types.MsgBeginRedelegate, k k finishTime := types.MsgCdc.MustMarshalBinaryLengthPrefixed(completionTime) resTags := sdk.NewTags( - tags.Delegator, []byte(msg.DelegatorAddr.String()), - tags.SrcValidator, []byte(msg.ValidatorSrcAddr.String()), - tags.DstValidator, []byte(msg.ValidatorDstAddr.String()), - tags.EndTime, []byte(completionTime.Format(time.RFC3339)), + tags.Delegator, msg.DelegatorAddr.String(), + tags.SrcValidator, msg.ValidatorSrcAddr.String(), + tags.DstValidator, msg.ValidatorDstAddr.String(), + tags.EndTime, completionTime.Format(time.RFC3339), ) return sdk.Result{Data: finishTime, Tags: resTags} diff --git a/x/staking/tags/tags.go b/x/staking/tags/tags.go index e8f42d9e0..a99135171 100644 --- a/x/staking/tags/tags.go +++ b/x/staking/tags/tags.go @@ -6,8 +6,8 @@ import ( ) var ( - ActionCompleteUnbonding = []byte("complete-unbonding") - ActionCompleteRedelegation = []byte("complete-redelegation") + ActionCompleteUnbonding = "complete-unbonding" + ActionCompleteRedelegation = "complete-redelegation" Action = sdk.TagAction SrcValidator = sdk.TagSrcValidator