Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint CosmWasm v1 #1129

Merged
merged 2 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions cmd/secretd/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
},
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/secretd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions cmd/secretd/secret20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions go-cosmwasm/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go-cosmwasm/types/v1/msg_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions go-cosmwasm/types/v1/subcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion x/compute/internal/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand Down
2 changes: 1 addition & 1 deletion x/compute/internal/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion x/compute/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down