From 99f54abfb20d75226970fe40136be23bb9590724 Mon Sep 17 00:00:00 2001 From: Assaf Morami Date: Mon, 5 Sep 2022 23:59:51 +0300 Subject: [PATCH] golangci-lint run ./... --fix Co-authored-by: Jacob Gadikian --- cmd/secretd/attestation.go | 26 ++++++++---------- cmd/secretd/init.go | 2 +- cmd/secretd/secret20.go | 35 ++++++++++++++++++++++-- go-cosmwasm/lib.go | 10 +++---- go-cosmwasm/types/v1/msg_v1.go | 4 +-- go-cosmwasm/types/v1/subcall.go | 8 +++--- x/compute/internal/keeper/keeper.go | 2 +- x/compute/internal/keeper/relay.go | 2 +- x/compute/internal/keeper/test_common.go | 2 +- 9 files changed, 58 insertions(+), 33 deletions(-) diff --git a/cmd/secretd/attestation.go b/cmd/secretd/attestation.go index 0da159f10..22d6c0d5d 100644 --- a/cmd/secretd/attestation.go +++ b/cmd/secretd/attestation.go @@ -90,12 +90,12 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert } } - spidFile, err := Asset("spid.txt") //nolint + spidFile, err := Asset("spid.txt") if err != nil { return fmt.Errorf("failed to initialize enclave: %w", err) } - apiKeyFile, err := Asset("api_key.txt") //nolint + apiKeyFile, err := Asset("api_key.txt") if err != nil { return fmt.Errorf("failed to initialize enclave: %w", err) } @@ -136,12 +136,12 @@ blockchain. Writes the certificate in DER format to ~/attestation_cert regGenState := reg.GetGenesisStateFromAppState(cdc, appState) - spidFile, err := Asset("spid.txt") //nolint + spidFile, err := Asset("spid.txt") if err != nil { return fmt.Errorf("failed to initialize enclave: %w", err) } - apiKeyFile, err := Asset("api_key.txt") //nolint + apiKeyFile, err := Asset("api_key.txt") if err != nil { return fmt.Errorf("failed to initialize enclave: %w", err) } @@ -340,10 +340,8 @@ func ResetEnclave() *cobra.Command { if err != nil { return err } - } else { - if err != nil { - println(err.Error()) - } + } else if err != nil { + println(err.Error()) } // remove sgx_secrets @@ -361,10 +359,8 @@ func ResetEnclave() *cobra.Command { if err != nil { return err } - } else { - if err != nil { - println(err.Error()) - } + } else if err != nil { + println(err.Error()) } return nil }, @@ -431,12 +427,12 @@ Please report any issues with this command } } - spidFile, err := Asset("spid.txt") //nolint + spidFile, err := Asset("spid.txt") if err != nil { return fmt.Errorf("failed to initialize enclave: %w", err) } - apiKeyFile, err := Asset("api_key.txt") //nolint + apiKeyFile, err := Asset("api_key.txt") if err != nil { return fmt.Errorf("failed to initialize enclave: %w", err) } @@ -474,7 +470,7 @@ Please report any issues with this command return err } - if pulsarFlag { + if pulsarFlag { //nolint:gocritic regUrl = pulsarRegistrationService log.Println("Registering node on Pulsar testnet") } else if customRegUrl != "" { diff --git a/cmd/secretd/init.go b/cmd/secretd/init.go index 58c1f4225..b421b0d7d 100644 --- a/cmd/secretd/init.go +++ b/cmd/secretd/init.go @@ -93,7 +93,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { "9cdaa5856e0245ecd73bd464308fb990fbc53b57@scrt-seed-03.scrtlabs.com:26656", // SCRT Labs 3 } // Override default settings in config.toml - config.P2P.Seeds = strings.Join(seeds[:], ",") + config.P2P.Seeds = strings.Join(seeds, ",") } config.P2P.MaxNumInboundPeers = 320 diff --git a/cmd/secretd/secret20.go b/cmd/secretd/secret20.go index 3a5663de7..a1578c7c4 100644 --- a/cmd/secretd/secret20.go +++ b/cmd/secretd/secret20.go @@ -73,6 +73,9 @@ func S20TransferHistoryCmd() *cobra.Command { Args: cobra.RangeArgs(3, 5), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -89,7 +92,7 @@ func S20TransferHistoryCmd() *cobra.Command { return errors.New("viewing key must not be empty") } - var page uint64 = 0 + var page uint64 var pageSize uint64 = 10 if len(args) >= 4 { @@ -132,6 +135,9 @@ Unlike the transfers query, this query shows all kinds of transactions with the Args: cobra.RangeArgs(3, 5), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -148,7 +154,7 @@ Unlike the transfers query, this query shows all kinds of transactions with the return errors.New("viewing key must not be empty") } - var page uint64 = 0 + var page uint64 var pageSize uint64 = 10 if len(args) >= 4 { @@ -191,6 +197,9 @@ key yet, use the "create-viewing-key" command. Otherwise, you can still see your Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) error { cliCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -248,7 +257,9 @@ func s20TransferCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { ////inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) - + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { return err @@ -289,6 +300,9 @@ This way you can perform balance and transaction history queries without waiting RunE: func(cmd *cobra.Command, args []string) error { // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -327,6 +341,9 @@ you're doing`, RunE: func(cmd *cobra.Command, args []string) error { // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -356,6 +373,9 @@ func s20DepositCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -389,6 +409,9 @@ func s20Redeem() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -425,6 +448,9 @@ If no callback provided, this is identical to 'transfer'.`, RunE: func(cmd *cobra.Command, args []string) error { // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { @@ -470,6 +496,9 @@ WARNING! This action is irreversible and permanent! use at your own risk`, RunE: func(cmd *cobra.Command, args []string) error { // inBuf := bufio.NewReader(cmd.InOrStdin()) cliCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } contractAddr, err := addressFromBechOrLabel(args[0], cliCtx) if err != nil { diff --git a/go-cosmwasm/lib.go b/go-cosmwasm/lib.go index bf83e12a5..197096c7d 100644 --- a/go-cosmwasm/lib.go +++ b/go-cosmwasm/lib.go @@ -275,7 +275,7 @@ func (w *Wasmer) Execute( // handle v0.10 response if resp.V010 != nil { - if resp.V010.Err != nil { + if resp.V010.Err != nil { //nolint:gocritic return v1types.DataWithInternalReplyInfo{ InternalMsgId: resp.InternalMsgId, InternaReplyEnclaveSig: resp.InternaReplyEnclaveSig, @@ -296,7 +296,7 @@ func (w *Wasmer) Execute( // handle v1 response if resp.V1 != nil { - if resp.V1.Err != nil { + if resp.V1.Err != nil { //nolint:gocritic return v1types.DataWithInternalReplyInfo{ InternalMsgId: resp.InternalMsgId, InternaReplyEnclaveSig: resp.InternaReplyEnclaveSig, @@ -316,7 +316,7 @@ func (w *Wasmer) Execute( } if resp.IBCBasic != nil { - if resp.IBCBasic.Err != nil { + if resp.IBCBasic.Err != nil { //nolint:gocritic return nil, gasUsed, fmt.Errorf("%+v", resp.IBCBasic.Err) } else if resp.IBCBasic.Ok != nil { return resp.IBCBasic.Ok, gasUsed, nil @@ -326,7 +326,7 @@ func (w *Wasmer) Execute( } if resp.IBCPacketReceive != nil { - if resp.IBCPacketReceive.Err != nil { + if resp.IBCPacketReceive.Err != nil { //nolint:gocritic return nil, gasUsed, fmt.Errorf("%+v", resp.IBCPacketReceive.Err) } else if resp.IBCPacketReceive.Ok != nil { return resp.IBCPacketReceive.Ok, gasUsed, nil @@ -336,7 +336,7 @@ func (w *Wasmer) Execute( } if resp.IBCChannelOpen != nil { - if resp.IBCChannelOpen.Err != nil { + if resp.IBCChannelOpen.Err != nil { //nolint:gocritic return nil, gasUsed, fmt.Errorf("%+v", resp.IBCChannelOpen.Err) } else if resp.IBCChannelOpen.Ok != nil { // ibc_channel_open actually returns no data diff --git a/go-cosmwasm/types/v1/msg_v1.go b/go-cosmwasm/types/v1/msg_v1.go index c72d52d9e..d6f52350a 100644 --- a/go-cosmwasm/types/v1/msg_v1.go +++ b/go-cosmwasm/types/v1/msg_v1.go @@ -146,7 +146,7 @@ func (v VoteOption) MarshalJSON() ([]byte, error) { return json.Marshal(v.String()) } -func (s *VoteOption) UnmarshalJSON(b []byte) error { +func (v *VoteOption) UnmarshalJSON(b []byte) error { var j string err := json.Unmarshal(b, &j) if err != nil { @@ -157,7 +157,7 @@ func (s *VoteOption) UnmarshalJSON(b []byte) error { if !ok { return fmt.Errorf("invalid vote option '%s'", j) } - *s = voteOption + *v = voteOption return nil } diff --git a/go-cosmwasm/types/v1/subcall.go b/go-cosmwasm/types/v1/subcall.go index 7732e600a..2d4048a61 100644 --- a/go-cosmwasm/types/v1/subcall.go +++ b/go-cosmwasm/types/v1/subcall.go @@ -32,11 +32,11 @@ func (r replyOn) String() string { return fromReplyOn[r] } -func (s replyOn) MarshalJSON() ([]byte, error) { - return json.Marshal(s.String()) +func (r replyOn) MarshalJSON() ([]byte, error) { + return json.Marshal(r.String()) } -func (s *replyOn) UnmarshalJSON(b []byte) error { +func (r *replyOn) UnmarshalJSON(b []byte) error { var j string err := json.Unmarshal(b, &j) if err != nil { @@ -47,7 +47,7 @@ func (s *replyOn) UnmarshalJSON(b []byte) error { if !ok { return fmt.Errorf("invalid reply_on value '%s'", j) } - *s = voteOption + *r = voteOption return nil } diff --git a/x/compute/internal/keeper/keeper.go b/x/compute/internal/keeper/keeper.go index 7c0d653bf..da6cd6a0b 100644 --- a/x/compute/internal/keeper/keeper.go +++ b/x/compute/internal/keeper/keeper.go @@ -262,7 +262,7 @@ func V010MsgToV1SubMsg(contractAddress string, msg v010wasmTypes.CosmosMsg) (v1w ReplyOn: v1wasmTypes.ReplyNever, } - if msg.Bank != nil { + if msg.Bank != nil { //nolint:gocritic if msg.Bank.Send.FromAddress != contractAddress { return v1wasmTypes.SubMsg{}, fmt.Errorf("contract doesn't have permission to send funds from another account (using BankMsg)") } diff --git a/x/compute/internal/keeper/relay.go b/x/compute/internal/keeper/relay.go index 2bef5b8e7..1cadd5334 100644 --- a/x/compute/internal/keeper/relay.go +++ b/x/compute/internal/keeper/relay.go @@ -166,7 +166,7 @@ func (k Keeper) OnCloseChannel( err = k.parseThenHandleIBCBasicContractResponse(ctx, contractAddress, msgBz, res) if err != nil { - sdkerrors.Wrap(err, "ibc-close-channel") + return sdkerrors.Wrap(err, "ibc-close-channel") } return nil } diff --git a/x/compute/internal/keeper/test_common.go b/x/compute/internal/keeper/test_common.go index 5deeb41c0..f75880a42 100644 --- a/x/compute/internal/keeper/test_common.go +++ b/x/compute/internal/keeper/test_common.go @@ -696,7 +696,7 @@ func fundAccounts(ctx sdk.Context, am authkeeper.AccountKeeper, bk bankkeeper.Ke am.SetAccount(ctx, baseAcct) } -var keyCounter uint64 = 0 +var keyCounter uint64 // we need to make this deterministic (same every test run), as encoded address size and thus gas cost, // depends on the actual bytes (due to ugly CanonicalAddress encoding)