sdkerrors.Wrap

This commit is contained in:
0xmuralik 2023-03-15 10:22:38 +05:30
parent 42fdc97c1c
commit b8d6300e4d
8 changed files with 103 additions and 97 deletions

View File

@ -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"
@ -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)
@ -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
@ -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
@ -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
@ -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

View File

@ -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"
@ -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{
@ -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)
@ -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)
@ -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.

View File

@ -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"
)
@ -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
@ -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
@ -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

View File

@ -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"
@ -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
@ -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

View File

@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
errorsmod "cosmossdk.io/errors"
"github.com/cerc-io/laconicd/x/bond/types"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
@ -113,7 +114,7 @@ func (k Keeper) CreateBond(ctx sdk.Context, ownerAddress sdk.AccAddress, coins s
for _, coin := range coins {
balance := k.bankKeeper.HasBalance(ctx, ownerAddress, coin)
if !balance {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "failed to create bond; Insufficient funds")
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "failed to create bond; Insufficient funds")
}
}
@ -129,7 +130,7 @@ func (k Keeper) CreateBond(ctx sdk.Context, ownerAddress sdk.AccAddress, coins s
bond := types.Bond{Id: bondID, Owner: ownerAddress.String(), Balance: coins}
if bond.Balance.IsAnyGT(maxBondAmount) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
}
// Move funds into the bond account module.
@ -221,18 +222,18 @@ func (k Keeper) QueryBondsByOwner(ctx sdk.Context, ownerAddress string) []types.
// RefillBond refills an existing bond.
func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
if !k.HasBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
bond := k.GetBond(ctx, id)
if bond.Owner != ownerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
}
// Check if account has funds.
for _, coin := range coins {
if !k.bankKeeper.HasBalance(ctx, ownerAddress, coin) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
}
}
@ -240,7 +241,7 @@ func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddre
updatedBalance := bond.Balance.Add(coins...)
if updatedBalance.IsAnyGT(maxBondAmount) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Max bond amount exceeded.")
}
// Move funds into the bond account module.
@ -259,17 +260,17 @@ func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddre
// WithdrawBond withdraws funds from a bond.
func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
if !k.HasBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
bond := k.GetBond(ctx, id)
if bond.Owner != ownerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
}
updatedBalance, isNeg := bond.Balance.SafeSub(coins...)
if isNeg {
return nil, sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient bond balance.")
return nil, errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient bond balance.")
}
// Move funds from the bond into the account.
@ -288,18 +289,18 @@ func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAdd
// CancelBond cancels a bond, returning funds to the owner.
func (k Keeper) CancelBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress) (*types.Bond, error) {
if !k.HasBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
}
bond := k.GetBond(ctx, id)
if bond.Owner != ownerAddress.String() {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
}
// Check if bond is used in other modules.
for _, usageKeeper := range k.usageKeepers {
if usageKeeper.UsesBond(ctx, id) {
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("Bond in use by the '%s' module.", usageKeeper.ModuleName()))
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, fmt.Sprintf("Bond in use by the '%s' module.", usageKeeper.ModuleName()))
}
}
@ -330,7 +331,7 @@ func (k Keeper) GetBondModuleBalances(ctx sdk.Context) sdk.Coins {
// TransferCoinsToModuleAccount moves funds from the bonds module account to another module account.
func (k Keeper) TransferCoinsToModuleAccount(ctx sdk.Context, id, moduleAccount string, coins sdk.Coins) error {
if !k.HasBond(ctx, id) {
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond not found.")
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond not found.")
}
bondObj := k.GetBond(ctx, id)
@ -340,13 +341,13 @@ func (k Keeper) TransferCoinsToModuleAccount(ctx sdk.Context, id, moduleAccount
if isNeg {
// Check if bond has sufficient funds.
return sdkerrors.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
return errorsmod.Wrap(sdkerrors.ErrInsufficientFunds, "Insufficient funds.")
}
// Move funds from bond module to record rent module.
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, moduleAccount, coins)
if err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.")
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.")
}
// Update bond balance.

View File

@ -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"
)
@ -28,10 +29,10 @@ func (msg MsgCreateBond) Type() string { return "create" }
func (msg MsgCreateBond) ValidateBasic() error {
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
@ -64,13 +65,13 @@ func (msg MsgRefillBond) Type() string { return "refill" }
func (msg MsgRefillBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
@ -103,13 +104,13 @@ func (msg MsgWithdrawBond) Type() string { return "withdraw" }
func (msg MsgWithdrawBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
}
return nil
}
@ -141,10 +142,10 @@ func (msg MsgCancelBond) Type() string { return "cancel" }
func (msg MsgCancelBond) ValidateBasic() error {
if len(msg.Id) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
}
if len(msg.Signer) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
}
return nil
}

View File

@ -6,8 +6,8 @@ import (
sdkmath "cosmossdk.io/math"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
@ -91,61 +91,61 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.HomesteadBlock); err != nil {
return sdkerrors.Wrap(err, "homesteadBlock")
return errorsmod.Wrap(err, "homesteadBlock")
}
if err := validateBlock(cc.DAOForkBlock); err != nil {
return sdkerrors.Wrap(err, "daoForkBlock")
return errorsmod.Wrap(err, "daoForkBlock")
}
if err := validateBlock(cc.EIP150Block); err != nil {
return sdkerrors.Wrap(err, "eip150Block")
return errorsmod.Wrap(err, "eip150Block")
}
if err := validateHash(cc.EIP150Hash); err != nil {
return err
}
if err := validateBlock(cc.EIP155Block); err != nil {
return sdkerrors.Wrap(err, "eip155Block")
return errorsmod.Wrap(err, "eip155Block")
}
if err := validateBlock(cc.EIP158Block); err != nil {
return sdkerrors.Wrap(err, "eip158Block")
return errorsmod.Wrap(err, "eip158Block")
}
if err := validateBlock(cc.ByzantiumBlock); err != nil {
return sdkerrors.Wrap(err, "byzantiumBlock")
return errorsmod.Wrap(err, "byzantiumBlock")
}
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
return sdkerrors.Wrap(err, "constantinopleBlock")
return errorsmod.Wrap(err, "constantinopleBlock")
}
if err := validateBlock(cc.PetersburgBlock); err != nil {
return sdkerrors.Wrap(err, "petersburgBlock")
return errorsmod.Wrap(err, "petersburgBlock")
}
if err := validateBlock(cc.IstanbulBlock); err != nil {
return sdkerrors.Wrap(err, "istanbulBlock")
return errorsmod.Wrap(err, "istanbulBlock")
}
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "muirGlacierBlock")
return errorsmod.Wrap(err, "muirGlacierBlock")
}
if err := validateBlock(cc.BerlinBlock); err != nil {
return sdkerrors.Wrap(err, "berlinBlock")
return errorsmod.Wrap(err, "berlinBlock")
}
if err := validateBlock(cc.LondonBlock); err != nil {
return sdkerrors.Wrap(err, "londonBlock")
return errorsmod.Wrap(err, "londonBlock")
}
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "arrowGlacierBlock")
return errorsmod.Wrap(err, "arrowGlacierBlock")
}
if err := validateBlock(cc.MergeForkBlock); err != nil {
return sdkerrors.Wrap(err, "mergeForkBlock")
return errorsmod.Wrap(err, "mergeForkBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return sdkerrors.Wrap(err, "invalid config fork order")
return errorsmod.Wrap(err, "invalid config fork order")
}
return nil
}
func validateHash(hex string) error {
if hex != "" && strings.TrimSpace(hex) == "" {
return sdkerrors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
return errorsmod.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
}
return nil
@ -158,7 +158,7 @@ func validateBlock(block *sdkmath.Int) error {
}
if block.IsNegative() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
)
}

View File

@ -8,8 +8,8 @@ import (
"github.com/cerc-io/laconicd/x/evm/types"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
@ -90,61 +90,61 @@ func getBlockValue(block *sdkmath.Int) *big.Int {
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.HomesteadBlock); err != nil {
return sdkerrors.Wrap(err, "homesteadBlock")
return errorsmod.Wrap(err, "homesteadBlock")
}
if err := validateBlock(cc.DAOForkBlock); err != nil {
return sdkerrors.Wrap(err, "daoForkBlock")
return errorsmod.Wrap(err, "daoForkBlock")
}
if err := validateBlock(cc.EIP150Block); err != nil {
return sdkerrors.Wrap(err, "eip150Block")
return errorsmod.Wrap(err, "eip150Block")
}
if err := validateHash(cc.EIP150Hash); err != nil {
return err
}
if err := validateBlock(cc.EIP155Block); err != nil {
return sdkerrors.Wrap(err, "eip155Block")
return errorsmod.Wrap(err, "eip155Block")
}
if err := validateBlock(cc.EIP158Block); err != nil {
return sdkerrors.Wrap(err, "eip158Block")
return errorsmod.Wrap(err, "eip158Block")
}
if err := validateBlock(cc.ByzantiumBlock); err != nil {
return sdkerrors.Wrap(err, "byzantiumBlock")
return errorsmod.Wrap(err, "byzantiumBlock")
}
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
return sdkerrors.Wrap(err, "constantinopleBlock")
return errorsmod.Wrap(err, "constantinopleBlock")
}
if err := validateBlock(cc.PetersburgBlock); err != nil {
return sdkerrors.Wrap(err, "petersburgBlock")
return errorsmod.Wrap(err, "petersburgBlock")
}
if err := validateBlock(cc.IstanbulBlock); err != nil {
return sdkerrors.Wrap(err, "istanbulBlock")
return errorsmod.Wrap(err, "istanbulBlock")
}
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "muirGlacierBlock")
return errorsmod.Wrap(err, "muirGlacierBlock")
}
if err := validateBlock(cc.BerlinBlock); err != nil {
return sdkerrors.Wrap(err, "berlinBlock")
return errorsmod.Wrap(err, "berlinBlock")
}
if err := validateBlock(cc.LondonBlock); err != nil {
return sdkerrors.Wrap(err, "londonBlock")
return errorsmod.Wrap(err, "londonBlock")
}
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
return sdkerrors.Wrap(err, "arrowGlacierBlock")
return errorsmod.Wrap(err, "arrowGlacierBlock")
}
if err := validateBlock(cc.MergeForkBlock); err != nil {
return sdkerrors.Wrap(err, "mergeForkBlock")
return errorsmod.Wrap(err, "mergeForkBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return sdkerrors.Wrap(err, "invalid config fork order")
return errorsmod.Wrap(err, "invalid config fork order")
}
return nil
}
func validateHash(hex string) error {
if hex != "" && strings.TrimSpace(hex) == "" {
return sdkerrors.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
return errorsmod.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
}
return nil
@ -157,7 +157,7 @@ func validateBlock(block *sdkmath.Int) error {
}
if block.IsNegative() {
return sdkerrors.Wrapf(
return errorsmod.Wrapf(
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
)
}