Skip to content

Commit

Permalink
x/ibc: fix missing return statement (cosmos#6099)
Browse files Browse the repository at this point in the history
* enable the wsl linter

Fix various wsl-related warnings.

x/ibc/04-channel/keeper/handshake.go: fix missing return statement in ChanOpenTry().

* goimports -w files

* remove unknown linter references

* run make format

* Revert "run make format"

This reverts commit f810b62.

* run make format
  • Loading branch information
Alessio Treglia authored Apr 30, 2020
1 parent b854c48 commit 2879c07
Show file tree
Hide file tree
Showing 36 changed files with 183 additions and 75 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ linters:
- unconvert
- unused
- misspell
- wsl

issues:
exclude-rules:
Expand Down
23 changes: 15 additions & 8 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const (

var (
_ abci.Application = (*BaseApp)(nil)

// mainConsensusParamsKey defines a key to store the consensus params in the
// main store.
mainConsensusParamsKey = []byte("consensus_params")
)

type (
Expand Down Expand Up @@ -104,7 +100,6 @@ type BaseApp struct { // nolint: maligned
func NewBaseApp(
name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, options ...func(*BaseApp),
) *BaseApp {

app := &BaseApp{
logger: logger,
name: name,
Expand All @@ -116,6 +111,7 @@ func NewBaseApp(
txDecoder: txDecoder,
fauxMerkleMode: false,
}

for _, option := range options {
option(app)
}
Expand Down Expand Up @@ -279,6 +275,7 @@ func (app *BaseApp) Router() sdk.Router {
// any routes modified which would cause unexpected routing behavior.
panic("Router() on sealed BaseApp")
}

return app.router
}

Expand Down Expand Up @@ -326,18 +323,21 @@ func (app *BaseApp) GetConsensusParams(ctx sdk.Context) *abci.ConsensusParams {

if app.paramStore.Has(ctx, ParamStoreKeyBlockParams) {
var bp abci.BlockParams

app.paramStore.Get(ctx, ParamStoreKeyBlockParams, &bp)
cp.Block = &bp
}

if app.paramStore.Has(ctx, ParamStoreKeyEvidenceParams) {
var ep abci.EvidenceParams

app.paramStore.Get(ctx, ParamStoreKeyEvidenceParams, &ep)
cp.Evidence = &ep
}

if app.paramStore.Has(ctx, ParamStoreKeyValidatorParams) {
var vp abci.ValidatorParams

app.paramStore.Get(ctx, ParamStoreKeyValidatorParams, &vp)
cp.Validator = &vp
}
Expand All @@ -350,6 +350,7 @@ func (app *BaseApp) StoreConsensusParams(ctx sdk.Context, cp *abci.ConsensusPara
if app.paramStore == nil {
panic("cannot store consensus params with no params store set")
}

if cp == nil {
return
}
Expand All @@ -369,6 +370,7 @@ func (app *BaseApp) getMaximumBlockGas(ctx sdk.Context) uint64 {
}

maxGas := cp.Block.MaxGas

switch {
case maxGas < -1:
panic(fmt.Sprintf("invalid maximum block gas: %d", maxGas))
Expand Down Expand Up @@ -431,6 +433,7 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) sdk.Context
if mode == runTxModeReCheck {
ctx = ctx.WithIsReCheckTx(true)
}

if mode == runTxModeSimulate {
ctx, _ = ctx.CacheContext()
}
Expand Down Expand Up @@ -534,8 +537,10 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.
}

if app.anteHandler != nil {
var anteCtx sdk.Context
var msCache sdk.CacheMultiStore
var (
anteCtx sdk.Context
msCache sdk.CacheMultiStore
)

// Cache wrap context before AnteHandler call in case it aborts.
// This is required for both CheckTx and DeliverTx.
Expand All @@ -545,8 +550,8 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.
// writes do not happen if aborted/failed. This may have some
// performance benefits, but it'll be more difficult to get right.
anteCtx, msCache = app.cacheTxContext(ctx, txBytes)

newCtx, err := app.anteHandler(anteCtx, tx, mode == runTxModeSimulate)

if !newCtx.IsZero() {
// At this point, newCtx.MultiStore() is cache-wrapped, or something else
// replaced by the AnteHandler. We want the original multistore, not one
Expand Down Expand Up @@ -603,6 +608,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s

msgRoute := msg.Route()
handler := app.router.Route(ctx, msgRoute)

if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i)
}
Expand All @@ -622,6 +628,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
// Note: Each message result's data must be length-prefixed in order to
// separate each result.
events = events.AppendEvents(msgEvents)

data = append(data, msgResult.Data...)
msgLogs = append(msgLogs, sdk.NewABCIMessageLog(uint16(i), msgResult.Log, msgEvents))
}
Expand Down
15 changes: 11 additions & 4 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ the flag --nosort is set.
cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation")
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
cmd.Flags().String(flagKeyAlgo, string(hd.Secp256k1Type), "Key signing algorithm to generate keys for")

return cmd
}

Expand All @@ -94,6 +95,7 @@ func getKeybase(transient bool, buf io.Reader) (keyring.Keyring, error) {
func runAddCmd(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := getKeybase(viper.GetBool(flags.FlagDryRun), inBuf)

if err != nil {
return err
}
Expand Down Expand Up @@ -131,6 +133,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
if err2 != nil {
return err2
}

if !response {
return errors.New("aborted")
}
Expand All @@ -155,6 +158,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
if err != nil {
return err
}

pks = append(pks, k.GetPubKey())
}

Expand All @@ -171,6 +175,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
}

cmd.PrintErrf("Key %q saved to disk.\n", name)

return nil
}
}
Expand All @@ -180,10 +185,11 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
if err != nil {
return err
}
_, err = kb.SavePubKey(name, pk, algo.Name())
if err != nil {

if _, err := kb.SavePubKey(name, pk, algo.Name()); err != nil {
return err
}

return nil
}

Expand All @@ -202,6 +208,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
if viper.GetBool(flags.FlagUseLedger) {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
info, err := kb.SaveLedgerKey(name, hd.Secp256k1, bech32PrefixAccAddr, coinType, account, index)

if err != nil {
return err
}
Expand All @@ -210,8 +217,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keyring, inBuf *buf
}

// Get bip39 mnemonic
var mnemonic string
var bip39Passphrase string
var mnemonic, bip39Passphrase string

if interactive || viper.GetBool(flagRecover) {
bip39Message := "Enter your bip39 mnemonic"
Expand Down Expand Up @@ -314,6 +320,7 @@ func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemo
if err != nil {
return err
}

cmd.PrintErrln(string(jsonString))
default:
return fmt.Errorf("invalid output format %s", output)
Expand Down
19 changes: 14 additions & 5 deletions client/keys/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ type bech32Output struct {

func newBech32Output(bs []byte) bech32Output {
out := bech32Output{Formats: make([]string, len(bech32Prefixes))}

for i, prefix := range bech32Prefixes {
bech32Addr, err := bech32.ConvertAndEncode(prefix, bs)
if err != nil {
panic(err)
}

out.Formats[i] = bech32Addr
}

Expand Down Expand Up @@ -87,12 +89,15 @@ hexadecimal into bech32 cosmos prefixed format and vice versa.
func parseKey(cmd *cobra.Command, args []string) error {
addr := strings.TrimSpace(args[0])
outstream := cmd.OutOrStdout()

if len(addr) == 0 {
return errors.New("couldn't parse empty input")
}

if !(runFromBech32(outstream, addr) || runFromHex(outstream, addr)) {
return errors.New("couldn't find valid bech32 nor hex data")
}

return nil
}

Expand All @@ -102,7 +107,9 @@ func runFromBech32(w io.Writer, bech32str string) bool {
if err != nil {
return false
}

displayParseKeyInfo(w, newHexOutput(hrp, bz))

return true
}

Expand All @@ -112,31 +119,33 @@ func runFromHex(w io.Writer, hexstr string) bool {
if err != nil {
return false
}

displayParseKeyInfo(w, newBech32Output(bz))

return true
}

func displayParseKeyInfo(w io.Writer, stringer fmt.Stringer) {
var out []byte
var err error
var (
err error
out []byte
)

switch viper.Get(cli.OutputFlag) {
case OutputFormatText:
out, err = yaml.Marshal(&stringer)

case OutputFormatJSON:

if viper.GetBool(flags.FlagIndentResponse) {
out, err = KeysCdc.MarshalJSONIndent(stringer, "", " ")
} else {
out = KeysCdc.MustMarshalJSON(stringer)
}

}

if err != nil {
panic(err)
}

fmt.Fprintln(w, string(out))
_, _ = fmt.Fprintln(w, string(out))
}
6 changes: 4 additions & 2 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error {

buf := bufio.NewReader(os.Stdin)
ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr)

if err != nil || !ok {
_, _ = fmt.Fprintf(os.Stderr, "%s\n", "cancelled transaction")
return err
Expand All @@ -168,7 +169,6 @@ func BroadcastTx(ctx context.CLIContext, txf Factory, msgs ...sdk.Msg) error {
func WriteGeneratedTxResponse(
ctx context.CLIContext, w http.ResponseWriter, txg Generator, br rest.BaseReq, msgs ...sdk.Msg,
) {

gasAdj, ok := rest.ParseFloat64OrReturnBadRequest(w, br.GasAdjustment, flags.DefaultGasAdjustment)
if !ok {
return
Expand Down Expand Up @@ -231,6 +231,7 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (ClientTx, error) {
}

fees := txf.fees

if !txf.gasPrices.IsZero() {
if !fees.IsZero() {
return nil, errors.New("cannot provide both fees and gas prices")
Expand All @@ -241,6 +242,7 @@ func BuildUnsignedTx(txf Factory, msgs ...sdk.Msg) (ClientTx, error) {
// Derive the fees based on the provided gas prices, where
// fee = ceil(gasPrice * gasLimit).
fees = make(sdk.Coins, len(txf.gasPrices))

for i, gp := range txf.gasPrices {
fee := gp.Amount.Mul(glDec)
fees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt())
Expand Down Expand Up @@ -294,7 +296,6 @@ func BuildSimTx(txf Factory, msgs ...sdk.Msg) ([]byte, error) {
func CalculateGas(
queryFunc func(string, []byte) ([]byte, int64, error), txf Factory, msgs ...sdk.Msg,
) (sdk.SimulationResponse, uint64, error) {

txBytes, err := BuildSimTx(txf, msgs...)
if err != nil {
return sdk.SimulationResponse{}, 0, err
Expand Down Expand Up @@ -334,6 +335,7 @@ func PrepareFactory(ctx context.CLIContext, txf Factory) (Factory, error) {
if initNum == 0 {
txf = txf.WithAccountNumber(num)
}

if initSeq == 0 {
txf = txf.WithSequence(seq)
}
Expand Down
4 changes: 2 additions & 2 deletions codec/amino_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMars
ac.amino.MustUnmarshalBinaryLengthPrefixed(bz, ptr)
}

func (ac *AminoCodec) MarshalJSON(o interface{}) ([]byte, error) { // nolint: stdmethods
func (ac *AminoCodec) MarshalJSON(o interface{}) ([]byte, error) {
return ac.amino.MarshalJSON(o)
}

func (ac *AminoCodec) MustMarshalJSON(o interface{}) []byte {
return ac.amino.MustMarshalJSON(o)
}

func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error { // nolint: stdmethods
func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error {
return ac.amino.UnmarshalJSON(bz, ptr)
}

Expand Down
4 changes: 2 additions & 2 deletions codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ type (
}

JSONMarshaler interface {
MarshalJSON(o interface{}) ([]byte, error) // nolint: stdmethods
MarshalJSON(o interface{}) ([]byte, error)
MustMarshalJSON(o interface{}) []byte

UnmarshalJSON(bz []byte, ptr interface{}) error // nolint: stdmethods
UnmarshalJSON(bz []byte, ptr interface{}) error
MustUnmarshalJSON(bz []byte, ptr interface{})
}

Expand Down
4 changes: 2 additions & 2 deletions codec/hybrid_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (hc *HybridCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMar
hc.proto.MustUnmarshalBinaryLengthPrefixed(bz, ptr)
}

func (hc *HybridCodec) MarshalJSON(o interface{}) ([]byte, error) { // nolint: stdmethods
func (hc *HybridCodec) MarshalJSON(o interface{}) ([]byte, error) {
return hc.amino.MarshalJSON(o)
}

func (hc *HybridCodec) MustMarshalJSON(o interface{}) []byte {
return hc.amino.MustMarshalJSON(o)
}

func (hc *HybridCodec) UnmarshalJSON(bz []byte, ptr interface{}) error { // nolint: stdmethods
func (hc *HybridCodec) UnmarshalJSON(bz []byte, ptr interface{}) error {
return hc.amino.UnmarshalJSON(bz, ptr)
}

Expand Down
Loading

0 comments on commit 2879c07

Please sign in to comment.