Skip to content

Commit

Permalink
Merge PR cosmos#5967: Fixed cliCtx in tx cli
Browse files Browse the repository at this point in the history
  • Loading branch information
sahith-narahari committed Apr 9, 2020
1 parent b5a6587 commit 192f259
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
4 changes: 4 additions & 0 deletions x/bank/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func NewSendTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetriever) *
}

msg := types.NewMsgSend(cliCtx.GetFromAddress(), toAddr, coins)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
},
}
Expand Down
6 changes: 5 additions & 1 deletion x/crisis/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ func NewMsgVerifyInvariantTxCmd(m codec.Marshaler, txg tx.Generator, ar tx.Accou
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)
txf := tx.NewFactoryFromCLI(inBuf).WithTxGenerator(txg).WithAccountRetriever(ar)

senderAddr := cliCtx.GetFromAddress()
moduleName, route := args[0], args[1]

msg := types.NewMsgVerifyInvariant(senderAddr, moduleName, route)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
},
}
Expand Down
8 changes: 4 additions & 4 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ $ %s tx distribution withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fx
txf := tx.NewFactoryFromCLI(inBuf).
WithTxGenerator(txg).
WithAccountRetriever(ar)
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

delAddr := cliCtx.GetFromAddress()
valAddr, err := sdk.ValAddressFromBech32(args[0])
Expand Down Expand Up @@ -152,7 +152,7 @@ $ %s tx distribution withdraw-all-rewards --from mykey
txf := tx.NewFactoryFromCLI(inBuf).
WithTxGenerator(txg).
WithAccountRetriever(ar)
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

delAddr := cliCtx.GetFromAddress()

Expand Down Expand Up @@ -193,7 +193,7 @@ $ %s tx distribution set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75
txf := tx.NewFactoryFromCLI(inBuf).
WithTxGenerator(txg).
WithAccountRetriever(ar)
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

delAddr := cliCtx.GetFromAddress()
withdrawAddr, err := sdk.AccAddressFromBech32(args[0])
Expand Down Expand Up @@ -242,7 +242,7 @@ Where proposal.json contains:
txf := tx.NewFactoryFromCLI(inBuf).
WithTxGenerator(txg).
WithAccountRetriever(ar)
cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

depositorAddr := cliCtx.GetFromAddress()
amount, err := sdk.ParseCoins(args[0])
Expand Down
6 changes: 5 additions & 1 deletion x/slashing/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ $ <appcli> tx slashing unjail --from mykey
WithTxGenerator(txg).
WithAccountRetriever(ar)

cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

valAddr := cliCtx.GetFromAddress()
msg := types.NewMsgUnjail(sdk.ValAddress(valAddr))
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
},
}
Expand Down
28 changes: 23 additions & 5 deletions x/staking/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewCreateValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRet
WithTxGenerator(txg).
WithAccountRetriever(ar)

cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

txf, msg, err := NewBuildCreateValidatorMsg(cliCtx, txf)
if err != nil {
Expand Down Expand Up @@ -101,7 +101,7 @@ func NewEditValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetri
WithTxGenerator(txg).
WithAccountRetriever(ar)

cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

valAddr := cliCtx.GetFromAddress()
description := types.NewDescription(
Expand Down Expand Up @@ -137,6 +137,9 @@ func NewEditValidatorCmd(m codec.Marshaler, txg tx.Generator, ar tx.AccountRetri
}

msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation)
if err := msg.ValidateBasic(); err != nil {
return err
}

// build and sign the transaction, then broadcast to Tendermint
return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
Expand Down Expand Up @@ -165,7 +168,7 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10
WithTxGenerator(txg).
WithAccountRetriever(ar)

cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

amount, err := sdk.ParseCoin(args[1])
if err != nil {
Expand All @@ -179,6 +182,10 @@ $ %s tx staking delegate cosmosvaloper1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm 10
}

msg := types.NewMsgDelegate(delAddr, valAddr, amount)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
},
}
Expand Down Expand Up @@ -209,7 +216,7 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
WithTxGenerator(txg).
WithAccountRetriever(ar)

cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)
delAddr := cliCtx.GetFromAddress()
valSrcAddr, err := sdk.ValAddressFromBech32(args[0])
if err != nil {
Expand All @@ -227,6 +234,10 @@ $ %s tx staking redelegate cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
}

msg := types.NewMsgBeginRedelegate(delAddr, valSrcAddr, valDstAddr, amount)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
},
}
Expand All @@ -253,7 +264,7 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s
WithTxGenerator(txg).
WithAccountRetriever(ar)

cliCtx := context.NewCLIContextWithInputAndFrom(inBuf, args[0]).WithMarshaler(m)
cliCtx := context.NewCLIContextWithInput(inBuf).WithMarshaler(m)

delAddr := cliCtx.GetFromAddress()
valAddr, err := sdk.ValAddressFromBech32(args[0])
Expand All @@ -267,6 +278,10 @@ $ %s tx staking unbond cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj 100s
}

msg := types.NewMsgUndelegate(delAddr, valAddr, amount)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTx(cliCtx, txf, msg)
},
}
Expand Down Expand Up @@ -315,6 +330,9 @@ func NewBuildCreateValidatorMsg(cliCtx context.CLIContext, txf tx.Factory) (tx.F
msg := types.NewMsgCreateValidator(
sdk.ValAddress(valAddr), pk, amount, description, commissionRates, minSelfDelegation,
)
if err := msg.ValidateBasic(); err != nil {
return txf, nil, err
}

if viper.GetBool(flags.FlagGenerateOnly) {
ip := viper.GetString(FlagIP)
Expand Down

0 comments on commit 192f259

Please sign in to comment.