Skip to content

Commit

Permalink
Merge PR cosmos#4678: Clean YAML output
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushijain23 authored and alexanderbez committed Jul 5, 2019
1 parent 2fdbf63 commit 1a7f31f
Show file tree
Hide file tree
Showing 65 changed files with 452 additions and 394 deletions.
4 changes: 2 additions & 2 deletions x/auth/client/rest/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

// BroadcastReq defines a tx broadcasting request.
type BroadcastReq struct {
Tx types.StdTx `json:"tx"`
Mode string `json:"mode"`
Tx types.StdTx `json:"tx" yaml:"tx"`
Mode string `json:"mode" yaml:"mode"`
}

// BroadcastTxRequest implements a tx broadcasting handler that is responsible
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/rest/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// EncodeResp defines a tx encoding response.
type EncodeResp struct {
Tx string `json:"tx"`
Tx string `json:"tx" yaml:"tx"`
}

// EncodeTxRequestHandlerFn returns the encode tx REST handler. In particular,
Expand Down
2 changes: 1 addition & 1 deletion x/auth/client/utils/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// GasEstimateResponse defines a response definition for tx gas estimation.
type GasEstimateResponse struct {
GasEstimate uint64 `json:"gas_estimate"`
GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"`
}

func (gr GasEstimateResponse) String() string {
Expand Down
6 changes: 2 additions & 4 deletions x/auth/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ type testInput struct {
// moduleAccount defines an account for modules that holds coins on a pool
type moduleAccount struct {
*types.BaseAccount
Name string `json:"name"` // name of the module
Permission string `json:"permission"` // permission of module account (minter/burner/holder)
Name string `json:"name" yaml:"name"` // name of the module
Permission string `json:"permission" yaml"permission"` // permission of module account (minter/burner/holder)
}


// GetName returns the the name of the holder's module
func (ma moduleAccount) GetName() string {
return ma.Name
Expand All @@ -40,7 +39,6 @@ func (ma moduleAccount) GetPermission() string {
return ma.Permission
}


func setupTestInput() testInput {
db := dbm.NewMemDB()

Expand Down
10 changes: 5 additions & 5 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ var _ exported.Account = (*BaseAccount)(nil)
// However one doesn't have to use BaseAccount as long as your struct
// implements Account.
type BaseAccount struct {
Address sdk.AccAddress `json:"address"`
Coins sdk.Coins `json:"coins"`
PubKey crypto.PubKey `json:"public_key"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
}

// NewBaseAccount creates a new BaseAccount object
Expand Down
2 changes: 1 addition & 1 deletion x/auth/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// GenesisState - all auth state that must be provided at genesis
type GenesisState struct {
Params Params `json:"params"`
Params Params `json:"params" yaml:"params"`
}

// NewGenesisState - Create a new genesis state
Expand Down
10 changes: 5 additions & 5 deletions x/auth/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ var _ subspace.ParamSet = &Params{}

// Params defines the parameters for the auth module.
type Params struct {
MaxMemoCharacters uint64 `json:"max_memo_characters"`
TxSigLimit uint64 `json:"tx_sig_limit"`
TxSizeCostPerByte uint64 `json:"tx_size_cost_per_byte"`
SigVerifyCostED25519 uint64 `json:"sig_verify_cost_ed25519"`
SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1"`
MaxMemoCharacters uint64 `json:"max_memo_characters" yaml:"max_memo_characters"`
TxSigLimit uint64 `json:"tx_sig_limit" yaml:"tx_sig_limit"`
TxSizeCostPerByte uint64 `json:"tx_size_cost_per_byte" yaml:"tx_size_cost_per_byte"`
SigVerifyCostED25519 uint64 `json:"sig_verify_cost_ed25519" yaml:"sig_verify_cost_ed25519"`
SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1" yaml:"sig_verify_cost_secp256k1"`
}

// NewParams creates a new Params object
Expand Down
12 changes: 6 additions & 6 deletions x/auth/types/stdsignmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
// a Msg with the other requirements for a StdSignDoc before
// it is signed. For use in the CLI.
type StdSignMsg struct {
ChainID string `json:"chain_id"`
AccountNumber uint64 `json:"account_number"`
Sequence uint64 `json:"sequence"`
Fee StdFee `json:"fee"`
Msgs []sdk.Msg `json:"msgs"`
Memo string `json:"memo"`
ChainID string `json:"chain_id" yaml:"chain_id"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
Fee StdFee `json:"fee" yaml:"fee"`
Msgs []sdk.Msg `json:"msgs" yaml:"msgs"`
Memo string `json:"memo" yaml:"memo"`
}

// get message bytes
Expand Down
58 changes: 44 additions & 14 deletions x/auth/types/stdtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/multisig"
yaml "gopkg.in/yaml.v2"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -20,10 +21,10 @@ var (
// StdTx is a standard way to wrap a Msg with Fee and Signatures.
// NOTE: the first signature is the fee payer (Signatures must not be nil).
type StdTx struct {
Msgs []sdk.Msg `json:"msg"`
Fee StdFee `json:"fee"`
Signatures []StdSignature `json:"signatures"`
Memo string `json:"memo"`
Msgs []sdk.Msg `json:"msg" yaml:"msg"`
Fee StdFee `json:"fee" yaml:"fee"`
Signatures []StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}

func NewStdTx(msgs []sdk.Msg, fee StdFee, sigs []StdSignature, memo string) StdTx {
Expand Down Expand Up @@ -112,8 +113,8 @@ func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures }
// gas to be used by the transaction. The ratio yields an effective "gasprice",
// which must be above some miminum to be accepted into the mempool.
type StdFee struct {
Amount sdk.Coins `json:"amount"`
Gas uint64 `json:"gas"`
Amount sdk.Coins `json:"amount" yaml:"amount"`
Gas uint64 `json:"gas" yaml:"gas"`
}

// NewStdFee returns a new instance of StdFee
Expand Down Expand Up @@ -157,12 +158,12 @@ func (fee StdFee) GasPrices() sdk.DecCoins {
// and the Sequence numbers for each signature (prevent
// inchain replay and enforce tx ordering per account).
type StdSignDoc struct {
AccountNumber uint64 `json:"account_number"`
ChainID string `json:"chain_id"`
Fee json.RawMessage `json:"fee"`
Memo string `json:"memo"`
Msgs []json.RawMessage `json:"msgs"`
Sequence uint64 `json:"sequence"`
AccountNumber uint64 `json:"account_number" yaml:"account_number"`
ChainID string `json:"chain_id" yaml:"chain_id"`
Fee json.RawMessage `json:"fee" yaml:"fee"`
Memo string `json:"memo" yaml:"memo"`
Msgs []json.RawMessage `json:"msgs" yaml:"msgs"`
Sequence uint64 `json:"sequence" yaml:"sequence"`
}

// StdSignBytes returns the bytes to sign for a transaction.
Expand All @@ -187,8 +188,8 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms

// StdSignature represents a sig
type StdSignature struct {
crypto.PubKey `json:"pub_key"` // optional
Signature []byte `json:"signature"`
crypto.PubKey `json:"pub_key" yaml:"pub_key"` // optional
Signature []byte `json:"signature" yaml:"signature"`
}

// DefaultTxDecoder logic for standard transaction decoding
Expand Down Expand Up @@ -217,3 +218,32 @@ func DefaultTxEncoder(cdc *codec.Codec) sdk.TxEncoder {
return cdc.MarshalBinaryLengthPrefixed(tx)
}
}

// MarshalYAML returns the YAML representation of the signature.
func (ss StdSignature) MarshalYAML() (interface{}, error) {
var (
bz []byte
pubkey string
err error
)

if ss.PubKey != nil {
pubkey, err = sdk.Bech32ifyAccPub(ss.PubKey)
if err != nil {
return nil, err
}
}

bz, err = yaml.Marshal(struct {
PubKey string
Signature string
}{
PubKey: pubkey,
Signature: fmt.Sprintf("%s", ss.Signature),
})
if err != nil {
return nil, err
}

return string(bz), err
}
29 changes: 29 additions & 0 deletions x/auth/types/stdtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
yaml "gopkg.in/yaml.v2"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -133,3 +134,31 @@ func TestDefaultTxEncoder(t *testing.T) {
require.NoError(t, err)
require.Equal(t, cdcBytes, encoderBytes)
}

func TestStdSignatureMarshalYAML(t *testing.T) {
_, pubKey, _ := KeyTestPubAddr()

testCases := []struct {
sig StdSignature
output string
}{
{
StdSignature{},
"|\n pubkey: \"\"\n signature: \"\"\n",
},
{
StdSignature{PubKey: pubKey, Signature: []byte("dummySig")},
fmt.Sprintf("|\n pubkey: %s\n signature: dummySig\n", sdk.MustBech32ifyAccPub(pubKey)),
},
{
StdSignature{PubKey: pubKey, Signature: nil},
fmt.Sprintf("|\n pubkey: %s\n signature: \"\"\n", sdk.MustBech32ifyAccPub(pubKey)),
},
}

for i, tc := range testCases {
bz, err := yaml.Marshal(tc.sig)
require.NoError(t, err)
require.Equal(t, tc.output, string(bz), "test case #%d", i)
}
}
4 changes: 2 additions & 2 deletions x/bank/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {

// SendReq defines the properties of a send request's body.
type SendReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Amount sdk.Coins `json:"amount"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
Amount sdk.Coins `json:"amount" yaml:"amount"`
}

// SendRequestHandlerFn - http request handler to send coins to a address.
Expand Down
2 changes: 1 addition & 1 deletion x/bank/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// GenesisState is the bank state that must be provided at genesis.
type GenesisState struct {
SendEnabled bool `json:"send_enabled"`
SendEnabled bool `json:"send_enabled" yaml:"send_enabled"`
}

// NewGenesisState creates a new genesis state.
Expand Down
18 changes: 9 additions & 9 deletions x/bank/internal/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const RouterKey = ModuleName

// MsgSend - high level transaction of the coin module
type MsgSend struct {
FromAddress sdk.AccAddress `json:"from_address"`
ToAddress sdk.AccAddress `json:"to_address"`
Amount sdk.Coins `json:"amount"`
FromAddress sdk.AccAddress `json:"from_address" yaml:"from_address"`
ToAddress sdk.AccAddress `json:"to_address" yaml:"to_address"`
Amount sdk.Coins `json:"amount" yaml:"amount"`
}

var _ sdk.Msg = MsgSend{}
Expand Down Expand Up @@ -56,8 +56,8 @@ func (msg MsgSend) GetSigners() []sdk.AccAddress {

// MsgMultiSend - high level transaction of the coin module
type MsgMultiSend struct {
Inputs []Input `json:"inputs"`
Outputs []Output `json:"outputs"`
Inputs []Input `json:"inputs" yaml:"inputs"`
Outputs []Output `json:"outputs" yaml:"outputs"`
}

var _ sdk.Msg = MsgMultiSend{}
Expand Down Expand Up @@ -103,8 +103,8 @@ func (msg MsgMultiSend) GetSigners() []sdk.AccAddress {

// Input models transaction input
type Input struct {
Address sdk.AccAddress `json:"address"`
Coins sdk.Coins `json:"coins"`
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
}

// ValidateBasic - validate transaction input
Expand All @@ -131,8 +131,8 @@ func NewInput(addr sdk.AccAddress, coins sdk.Coins) Input {

// Output models transaction outputs
type Output struct {
Address sdk.AccAddress `json:"address"`
Coins sdk.Coins `json:"coins"`
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
}

// ValidateBasic - validate transaction output
Expand Down
2 changes: 1 addition & 1 deletion x/crisis/internal/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// GenesisState - crisis genesis state
type GenesisState struct {
ConstantFee sdk.Coin `json:"constant_fee"`
ConstantFee sdk.Coin `json:"constant_fee" yaml:"constant_fee"`
}

// NewGenesisState creates a new GenesisState object
Expand Down
6 changes: 3 additions & 3 deletions x/crisis/internal/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

// MsgVerifyInvariant - message struct to verify a particular invariance
type MsgVerifyInvariant struct {
Sender sdk.AccAddress `json:"sender"`
InvariantModuleName string `json:"invariant_module_name"`
InvariantRoute string `json:"invariant_route"`
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
InvariantModuleName string `json:"invariant_module_name" yaml:"invariant_module_name"`
InvariantRoute string `json:"invariant_route" yaml:"invariant_route"`
}

// ensure Msg interface compliance at compile time
Expand Down
10 changes: 5 additions & 5 deletions x/distribution/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
type (
// CommunityPoolSpendProposalJSON defines a CommunityPoolSpendProposal with a deposit
CommunityPoolSpendProposalJSON struct {
Title string `json:"title"`
Description string `json:"description"`
Recipient sdk.AccAddress `json:"recipient"`
Amount sdk.Coins `json:"amount"`
Deposit sdk.Coins `json:"deposit"`
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Recipient sdk.AccAddress `json:"recipient" yaml:"recipient"`
Amount sdk.Coins `json:"amount" yaml:"amount"`
Deposit sdk.Coins `json:"deposit" yaml:"deposit"`
}
)

Expand Down
6 changes: 3 additions & 3 deletions x/distribution/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func delegatorWithdrawalAddrHandlerFn(cliCtx context.CLIContext, queryRoute stri
// ValidatorDistInfo defines the properties of
// validator distribution information response.
type ValidatorDistInfo struct {
OperatorAddress sdk.AccAddress `json:"operator_address"`
SelfBondRewards sdk.DecCoins `json:"self_bond_rewards"`
ValidatorCommission types.ValidatorAccumulatedCommission `json:"val_commission"`
OperatorAddress sdk.AccAddress `json:"operator_address" yaml:"operator_address"`
SelfBondRewards sdk.DecCoins `json:"self_bond_rewards" yaml:"self_bond_rewards"`
ValidatorCommission types.ValidatorAccumulatedCommission `json:"val_commission" yaml:"val_commission"`
}

// NewValidatorDistInfo creates a new instance of ValidatorDistInfo.
Expand Down
6 changes: 3 additions & 3 deletions x/distribution/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, queryRoute strin

type (
withdrawRewardsReq struct {
BaseReq rest.BaseReq `json:"base_req"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
}

setWithdrawalAddrReq struct {
BaseReq rest.BaseReq `json:"base_req"`
WithdrawAddress sdk.AccAddress `json:"withdraw_address"`
BaseReq rest.BaseReq `json:"base_req" yaml:"base_req"`
WithdrawAddress sdk.AccAddress `json:"withdraw_address" yaml:"withdraw_address"`
}
)

Expand Down
Loading

0 comments on commit 1a7f31f

Please sign in to comment.