Skip to content

Commit

Permalink
fix lint (#101)
Browse files Browse the repository at this point in the history
* sdkerrors.Wrap

* sdkerrors.Wrap

* upgrade dependenices
  • Loading branch information
0xbala-k authored Mar 15, 2023
1 parent 42fdc97 commit 763dab7
Show file tree
Hide file tree
Showing 16 changed files with 552 additions and 228 deletions.
25 changes: 10 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ require (
github.com/holiman/uint256 v1.2.1
github.com/improbable-eng/grpc-web v0.15.0
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-ipld-cbor v0.0.6
github.com/ipld/go-ipld-prime v0.18.0
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/multiformats/go-multihash v0.2.0
github.com/onsi/ginkgo/v2 v2.5.1
github.com/onsi/gomega v1.24.1
github.com/pkg/errors v0.9.1
Expand All @@ -45,8 +43,8 @@ require (
github.com/tendermint/tm-db v0.6.7
github.com/tyler-smith/go-bip39 v1.1.0
github.com/vektah/gqlparser/v2 v2.5.1
golang.org/x/net v0.4.0
golang.org/x/text v0.5.0
golang.org/x/net v0.7.0
golang.org/x/text v0.7.0
google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c
google.golang.org/grpc v1.51.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
Expand All @@ -67,7 +65,7 @@ require (
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/aws/aws-sdk-go v1.40.45 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
Expand Down Expand Up @@ -123,7 +121,7 @@ require (
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.6.1 // indirect
github.com/hashicorp/go-getter v1.7.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
Expand All @@ -133,9 +131,6 @@ require (
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/ipfs/go-block-format v0.0.2 // indirect
github.com/ipfs/go-ipfs-util v0.0.1 // indirect
github.com/ipfs/go-ipld-format v0.0.1 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
Expand All @@ -154,13 +149,14 @@ require (
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/multiformats/go-base32 v0.0.3 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multibase v0.0.3 // indirect
github.com/multiformats/go-multihash v0.2.0 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
Expand Down Expand Up @@ -191,18 +187,17 @@ require (
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.103.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
417 changes: 367 additions & 50 deletions go.sum

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions x/auction/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

Expand All @@ -26,7 +27,7 @@ func (q Querier) Auctions(c context.Context, req *types.AuctionsRequest) (*types
func (q Querier) GetAuction(c context.Context, req *types.AuctionRequest) (*types.AuctionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.Id == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
}

resp := q.Keeper.GetAuction(ctx, req.Id)
Expand All @@ -37,10 +38,10 @@ func (q Querier) GetAuction(c context.Context, req *types.AuctionRequest) (*type
func (q Querier) GetBid(c context.Context, req *types.BidRequest) (*types.BidResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.AuctionId == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
}
if req.Bidder == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
}
resp := q.Keeper.GetBid(ctx, req.AuctionId, req.Bidder)
return &types.BidResponse{Bid: &resp}, nil
Expand All @@ -50,7 +51,7 @@ func (q Querier) GetBid(c context.Context, req *types.BidRequest) (*types.BidRes
func (q Querier) GetBids(c context.Context, req *types.BidsRequest) (*types.BidsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.AuctionId == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "auction ID is required")
}
resp := q.Keeper.GetBids(ctx, req.AuctionId)
return &types.BidsResponse{Bids: resp}, nil
Expand All @@ -60,7 +61,7 @@ func (q Querier) GetBids(c context.Context, req *types.BidsRequest) (*types.Bids
func (q Querier) AuctionsByBidder(c context.Context, req *types.AuctionsByBidderRequest) (*types.AuctionsByBidderResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.BidderAddress == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bidder address is required")
}
resp := q.Keeper.QueryAuctionsByBidder(ctx, req.BidderAddress)
return &types.AuctionsByBidderResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
Expand All @@ -70,7 +71,7 @@ func (q Querier) AuctionsByBidder(c context.Context, req *types.AuctionsByBidder
func (q Querier) AuctionsByOwner(c context.Context, req *types.AuctionsByOwnerRequest) (*types.AuctionsByOwnerResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
if req.OwnerAddress == "" {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "owner address is required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner address is required")
}
resp := q.Keeper.QueryAuctionsByOwner(ctx, req.OwnerAddress)
return &types.AuctionsByOwnerResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
Expand Down
37 changes: 19 additions & 18 deletions x/auction/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/auction/types"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -306,7 +307,7 @@ func (k Keeper) CreateAuction(ctx sdk.Context, msg types.MsgCreateAuction) (*typ
// Generate auction Id.
account := k.accountKeeper.GetAccount(ctx, signerAddress)
if account == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "Account not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "Account not found.")
}

auctionID := types.AuctionID{
Expand Down Expand Up @@ -340,12 +341,12 @@ func (k Keeper) CreateAuction(ctx sdk.Context, msg types.MsgCreateAuction) (*typ

func (k Keeper) CommitBid(ctx sdk.Context, msg types.MsgCommitBid) (*types.Bid, error) {
if !k.HasAuction(ctx, msg.AuctionId) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
}

auction := k.GetAuction(ctx, msg.AuctionId)
if auction.Status != types.AuctionStatusCommitPhase {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in commit phase.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in commit phase.")
}

signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
Expand Down Expand Up @@ -390,12 +391,12 @@ func (k Keeper) CommitBid(ctx sdk.Context, msg types.MsgCommitBid) (*types.Bid,
// RevealBid reeals a bid committed earlier.
func (k Keeper) RevealBid(ctx sdk.Context, msg types.MsgRevealBid) (*types.Auction, error) {
if !k.HasAuction(ctx, msg.AuctionId) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction not found.")
}

auction := k.GetAuction(ctx, msg.AuctionId)
if auction.Status != types.AuctionStatusRevealPhase {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in reveal phase.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Auction is not in reveal phase.")
}

signerAddress, err := sdk.AccAddressFromBech32(msg.Signer)
Expand All @@ -404,65 +405,65 @@ func (k Keeper) RevealBid(ctx sdk.Context, msg types.MsgRevealBid) (*types.Aucti
}

if !k.HasBid(ctx, msg.AuctionId, signerAddress.String()) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bid not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid not found.")
}

bid := k.GetBid(ctx, auction.Id, signerAddress.String())
if bid.Status != types.BidStatusCommitted {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bid not in committed state.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid not in committed state.")
}

revealBytes, err := hex.DecodeString(msg.Reveal)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal string.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal string.")
}

cid, err := wnsUtils.CIDFromJSONBytes(revealBytes)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal JSON.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal JSON.")
}

if bid.CommitHash != cid {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Commit hash mismatch.")
}

var reveal map[string]interface{}
err = json.Unmarshal(revealBytes, &reveal)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Reveal JSON unmarshal error.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal JSON unmarshal error.")
}

chainID, err := wnsUtils.GetAttributeAsString(reveal, "chainId")
if err != nil || chainID != ctx.ChainID() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal chainID.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal chainID.")
}

auctionID, err := wnsUtils.GetAttributeAsString(reveal, "auctionId")
if err != nil || auctionID != msg.AuctionId {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal auction Id.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal auction Id.")
}

bidderAddress, err := wnsUtils.GetAttributeAsString(reveal, "bidderAddress")
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid address.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid address.")
}

if bidderAddress != signerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Reveal bid address mismatch.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Reveal bid address mismatch.")
}

bidAmountStr, err := wnsUtils.GetAttributeAsString(reveal, "bidAmount")
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
}

bidAmount, err := sdk.ParseCoinNormalized(bidAmountStr)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid reveal bid amount.")
}

if bidAmount.IsLT(auction.MinimumBid) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bid is lower than minimum bid.")
}

// Lock bid amount.
Expand Down
21 changes: 11 additions & 10 deletions x/auction/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -32,19 +33,19 @@ func (msg MsgCreateAuction) Type() string { return "create" }
// ValidateBasic Implements Msg.
func (msg MsgCreateAuction) ValidateBasic() error {
if msg.Signer == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}

if msg.CommitsDuration <= 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "commit phase duration invalid.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "commit phase duration invalid.")
}

if msg.RevealsDuration <= 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "reveal phase duration invalid.")
}

if !msg.MinimumBid.IsPositive() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum bid should be greater than zero.")
}

return nil
Expand Down Expand Up @@ -79,15 +80,15 @@ func (msg MsgCommitBid) Type() string { return "commit" }
// ValidateBasic Implements Msg.
func (msg MsgCommitBid) ValidateBasic() error {
if msg.Signer == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
}

if msg.AuctionId == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
}

if msg.CommitHash == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash.")
}

return nil
Expand Down Expand Up @@ -122,15 +123,15 @@ func (msg MsgRevealBid) Type() string { return "reveal" }
// ValidateBasic Implements Msg.
func (msg MsgRevealBid) ValidateBasic() error {
if msg.Signer == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
}

if msg.AuctionId == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
}

if msg.Reveal == "" {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data.")
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions x/bond/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"context"

errorsmod "cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/bond/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -30,7 +31,7 @@ func (q Querier) GetBondByID(c context.Context, req *types.QueryGetBondByIDReque
ctx := sdk.UnwrapSDKContext(c)
bondID := req.GetId()
if len(bondID) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id required")
}
bond := q.Keeper.GetBond(ctx, req.GetId())
return &types.QueryGetBondByIDResponse{Bond: &bond}, nil
Expand All @@ -40,7 +41,7 @@ func (q Querier) GetBondsByOwner(c context.Context, req *types.QueryGetBondsByOw
ctx := sdk.UnwrapSDKContext(c)
owner := req.GetOwner()
if len(owner) == 0 {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "owner id required")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner id required")
}
bonds := q.Keeper.QueryBondsByOwner(ctx, owner)
return &types.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
Expand Down
Loading

0 comments on commit 763dab7

Please sign in to comment.