sdkerros.wrap
This commit is contained in:
parent
80d15ffd1f
commit
7d4ff9950d
21
.github/workflows/lint.yml
vendored
21
.github/workflows/lint.yml
vendored
@ -52,7 +52,6 @@ jobs:
|
|||||||
ignore_path: .markdownlintignore
|
ignore_path: .markdownlintignore
|
||||||
# Check only if there are differences in the source code
|
# Check only if there are differences in the source code
|
||||||
if: env.GIT_DIFF
|
if: env.GIT_DIFF
|
||||||
|
|
||||||
python-lint:
|
python-lint:
|
||||||
name: Run flake8 on python integration tests
|
name: Run flake8 on python integration tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -69,23 +68,3 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
nix-shell -I nixpkgs=./nix -p test-env --run "make lint-py"
|
nix-shell -I nixpkgs=./nix -p test-env --run "make lint-py"
|
||||||
if: env.GIT_DIFF
|
if: env.GIT_DIFF
|
||||||
gomod2nix:
|
|
||||||
name: Check gomod2nix.toml file is up to date
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2.3.4
|
|
||||||
- uses: cachix/install-nix-action@v18
|
|
||||||
- uses: cachix/cachix-action@v12
|
|
||||||
with:
|
|
||||||
name: laconicd
|
|
||||||
- uses: technote-space/get-diff-action@v6.1.2
|
|
||||||
with:
|
|
||||||
PATTERNS: |
|
|
||||||
**/**.py
|
|
||||||
- name: run gomod2nix
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
nix run -f ./nix gomod2nix
|
|
||||||
git diff --no-ext-diff --exit-code
|
|
||||||
if: env.GIT_DIFF
|
|
||||||
|
@ -3,6 +3,7 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
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) {
|
func (q Querier) GetAuction(c context.Context, req *types.AuctionRequest) (*types.AuctionResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
if req.Id == "" {
|
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)
|
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) {
|
func (q Querier) GetBid(c context.Context, req *types.BidRequest) (*types.BidResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
if req.AuctionId == "" {
|
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 == "" {
|
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)
|
resp := q.Keeper.GetBid(ctx, req.AuctionId, req.Bidder)
|
||||||
return &types.BidResponse{Bid: &resp}, nil
|
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) {
|
func (q Querier) GetBids(c context.Context, req *types.BidsRequest) (*types.BidsResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
if req.AuctionId == "" {
|
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)
|
resp := q.Keeper.GetBids(ctx, req.AuctionId)
|
||||||
return &types.BidsResponse{Bids: resp}, nil
|
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) {
|
func (q Querier) AuctionsByBidder(c context.Context, req *types.AuctionsByBidderRequest) (*types.AuctionsByBidderResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
if req.BidderAddress == "" {
|
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)
|
resp := q.Keeper.QueryAuctionsByBidder(ctx, req.BidderAddress)
|
||||||
return &types.AuctionsByBidderResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
|
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) {
|
func (q Querier) AuctionsByOwner(c context.Context, req *types.AuctionsByOwnerRequest) (*types.AuctionsByOwnerResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
if req.OwnerAddress == "" {
|
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)
|
resp := q.Keeper.QueryAuctionsByOwner(ctx, req.OwnerAddress)
|
||||||
return &types.AuctionsByOwnerResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
|
return &types.AuctionsByOwnerResponse{Auctions: &types.Auctions{Auctions: resp}}, nil
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
"github.com/cerc-io/laconicd/x/auction/types"
|
"github.com/cerc-io/laconicd/x/auction/types"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
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.
|
// Generate auction Id.
|
||||||
account := k.accountKeeper.GetAccount(ctx, signerAddress)
|
account := k.accountKeeper.GetAccount(ctx, signerAddress)
|
||||||
if account == nil {
|
if account == nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "Account not found.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "Account not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
auctionID := types.AuctionID{
|
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) {
|
func (k Keeper) CommitBid(ctx sdk.Context, msg types.MsgCommitBid) (*types.Bid, error) {
|
||||||
if !k.HasAuction(ctx, msg.AuctionId) {
|
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)
|
auction := k.GetAuction(ctx, msg.AuctionId)
|
||||||
if auction.Status != types.AuctionStatusCommitPhase {
|
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)
|
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.
|
// RevealBid reeals a bid committed earlier.
|
||||||
func (k Keeper) RevealBid(ctx sdk.Context, msg types.MsgRevealBid) (*types.Auction, error) {
|
func (k Keeper) RevealBid(ctx sdk.Context, msg types.MsgRevealBid) (*types.Auction, error) {
|
||||||
if !k.HasAuction(ctx, msg.AuctionId) {
|
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)
|
auction := k.GetAuction(ctx, msg.AuctionId)
|
||||||
if auction.Status != types.AuctionStatusRevealPhase {
|
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)
|
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()) {
|
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())
|
bid := k.GetBid(ctx, auction.Id, signerAddress.String())
|
||||||
if bid.Status != types.BidStatusCommitted {
|
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)
|
revealBytes, err := hex.DecodeString(msg.Reveal)
|
||||||
if err != nil {
|
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)
|
cid, err := wnsUtils.CIDFromJSONBytes(revealBytes)
|
||||||
if err != nil {
|
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 {
|
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{}
|
var reveal map[string]interface{}
|
||||||
err = json.Unmarshal(revealBytes, &reveal)
|
err = json.Unmarshal(revealBytes, &reveal)
|
||||||
if err != nil {
|
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")
|
chainID, err := wnsUtils.GetAttributeAsString(reveal, "chainId")
|
||||||
if err != nil || chainID != ctx.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")
|
auctionID, err := wnsUtils.GetAttributeAsString(reveal, "auctionId")
|
||||||
if err != nil || auctionID != msg.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")
|
bidderAddress, err := wnsUtils.GetAttributeAsString(reveal, "bidderAddress")
|
||||||
if err != nil {
|
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() {
|
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")
|
bidAmountStr, err := wnsUtils.GetAttributeAsString(reveal, "bidAmount")
|
||||||
if err != nil {
|
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)
|
bidAmount, err := sdk.ParseCoinNormalized(bidAmountStr)
|
||||||
if err != nil {
|
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) {
|
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.
|
// Lock bid amount.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
@ -32,19 +33,19 @@ func (msg MsgCreateAuction) Type() string { return "create" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgCreateAuction) ValidateBasic() error {
|
func (msg MsgCreateAuction) ValidateBasic() error {
|
||||||
if msg.Signer == "" {
|
if msg.Signer == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.CommitsDuration <= 0 {
|
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 {
|
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() {
|
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
|
return nil
|
||||||
@ -79,15 +80,15 @@ func (msg MsgCommitBid) Type() string { return "commit" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgCommitBid) ValidateBasic() error {
|
func (msg MsgCommitBid) ValidateBasic() error {
|
||||||
if msg.Signer == "" {
|
if msg.Signer == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.AuctionId == "" {
|
if msg.AuctionId == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.CommitHash == "" {
|
if msg.CommitHash == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid commit hash.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -122,15 +123,15 @@ func (msg MsgRevealBid) Type() string { return "reveal" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgRevealBid) ValidateBasic() error {
|
func (msg MsgRevealBid) ValidateBasic() error {
|
||||||
if msg.Signer == "" {
|
if msg.Signer == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer address.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.AuctionId == "" {
|
if msg.AuctionId == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid auction ID.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Reveal == "" {
|
if msg.Reveal == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid reveal data.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -3,6 +3,7 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
"github.com/cerc-io/laconicd/x/bond/types"
|
"github.com/cerc-io/laconicd/x/bond/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
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)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
bondID := req.GetId()
|
bondID := req.GetId()
|
||||||
if len(bondID) == 0 {
|
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())
|
bond := q.Keeper.GetBond(ctx, req.GetId())
|
||||||
return &types.QueryGetBondByIDResponse{Bond: &bond}, nil
|
return &types.QueryGetBondByIDResponse{Bond: &bond}, nil
|
||||||
@ -40,7 +41,7 @@ func (q Querier) GetBondsByOwner(c context.Context, req *types.QueryGetBondsByOw
|
|||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
owner := req.GetOwner()
|
owner := req.GetOwner()
|
||||||
if len(owner) == 0 {
|
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)
|
bonds := q.Keeper.QueryBondsByOwner(ctx, owner)
|
||||||
return &types.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
|
return &types.QueryGetBondsByOwnerResponse{Bonds: bonds}, nil
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
"github.com/cerc-io/laconicd/x/bond/types"
|
"github.com/cerc-io/laconicd/x/bond/types"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
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 {
|
for _, coin := range coins {
|
||||||
balance := k.bankKeeper.HasBalance(ctx, ownerAddress, coin)
|
balance := k.bankKeeper.HasBalance(ctx, ownerAddress, coin)
|
||||||
if !balance {
|
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}
|
bond := types.Bond{Id: bondID, Owner: ownerAddress.String(), Balance: coins}
|
||||||
if bond.Balance.IsAnyGT(maxBondAmount) {
|
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.
|
// 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.
|
// RefillBond refills an existing bond.
|
||||||
func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
|
func (k Keeper) RefillBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
|
||||||
if !k.HasBond(ctx, id) {
|
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)
|
bond := k.GetBond(ctx, id)
|
||||||
if bond.Owner != ownerAddress.String() {
|
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.
|
// Check if account has funds.
|
||||||
for _, coin := range coins {
|
for _, coin := range coins {
|
||||||
if !k.bankKeeper.HasBalance(ctx, ownerAddress, coin) {
|
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...)
|
updatedBalance := bond.Balance.Add(coins...)
|
||||||
if updatedBalance.IsAnyGT(maxBondAmount) {
|
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.
|
// 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.
|
// WithdrawBond withdraws funds from a bond.
|
||||||
func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
|
func (k Keeper) WithdrawBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress, coins sdk.Coins) (*types.Bond, error) {
|
||||||
if !k.HasBond(ctx, id) {
|
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)
|
bond := k.GetBond(ctx, id)
|
||||||
if bond.Owner != ownerAddress.String() {
|
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...)
|
updatedBalance, isNeg := bond.Balance.SafeSub(coins...)
|
||||||
if isNeg {
|
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.
|
// 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.
|
// CancelBond cancels a bond, returning funds to the owner.
|
||||||
func (k Keeper) CancelBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress) (*types.Bond, error) {
|
func (k Keeper) CancelBond(ctx sdk.Context, id string, ownerAddress sdk.AccAddress) (*types.Bond, error) {
|
||||||
if !k.HasBond(ctx, id) {
|
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)
|
bond := k.GetBond(ctx, id)
|
||||||
if bond.Owner != ownerAddress.String() {
|
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.
|
// Check if bond is used in other modules.
|
||||||
for _, usageKeeper := range k.usageKeepers {
|
for _, usageKeeper := range k.usageKeepers {
|
||||||
if usageKeeper.UsesBond(ctx, id) {
|
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.
|
// 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 {
|
func (k Keeper) TransferCoinsToModuleAccount(ctx sdk.Context, id, moduleAccount string, coins sdk.Coins) error {
|
||||||
if !k.HasBond(ctx, id) {
|
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)
|
bondObj := k.GetBond(ctx, id)
|
||||||
@ -340,13 +341,13 @@ func (k Keeper) TransferCoinsToModuleAccount(ctx sdk.Context, id, moduleAccount
|
|||||||
|
|
||||||
if isNeg {
|
if isNeg {
|
||||||
// Check if bond has sufficient funds.
|
// 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.
|
// Move funds from bond module to record rent module.
|
||||||
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, moduleAccount, coins)
|
err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, moduleAccount, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Error transferring funds.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update bond balance.
|
// Update bond balance.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
@ -28,10 +29,10 @@ func (msg MsgCreateBond) Type() string { return "create" }
|
|||||||
|
|
||||||
func (msg MsgCreateBond) ValidateBasic() error {
|
func (msg MsgCreateBond) ValidateBasic() error {
|
||||||
if len(msg.Signer) == 0 {
|
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() {
|
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -64,13 +65,13 @@ func (msg MsgRefillBond) Type() string { return "refill" }
|
|||||||
|
|
||||||
func (msg MsgRefillBond) ValidateBasic() error {
|
func (msg MsgRefillBond) ValidateBasic() error {
|
||||||
if len(msg.Id) == 0 {
|
if len(msg.Id) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
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() {
|
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -103,13 +104,13 @@ func (msg MsgWithdrawBond) Type() string { return "withdraw" }
|
|||||||
|
|
||||||
func (msg MsgWithdrawBond) ValidateBasic() error {
|
func (msg MsgWithdrawBond) ValidateBasic() error {
|
||||||
if len(msg.Id) == 0 {
|
if len(msg.Id) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
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() {
|
if len(msg.Coins) == 0 || !msg.Coins.IsValid() {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, "Invalid amount.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -141,10 +142,10 @@ func (msg MsgCancelBond) Type() string { return "cancel" }
|
|||||||
|
|
||||||
func (msg MsgCancelBond) ValidateBasic() error {
|
func (msg MsgCancelBond) ValidateBasic() error {
|
||||||
if len(msg.Id) == 0 {
|
if len(msg.Id) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, msg.Id)
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package keeper
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
"github.com/cerc-io/laconicd/x/registry/types"
|
"github.com/cerc-io/laconicd/x/registry/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
@ -48,7 +49,7 @@ func (q Querier) GetRecord(c context.Context, req *types.QueryRecordByIDRequest)
|
|||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
id := req.GetId()
|
id := req.GetId()
|
||||||
if !q.Keeper.HasRecord(ctx, id) {
|
if !q.Keeper.HasRecord(ctx, id) {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "Record not found.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "Record not found.")
|
||||||
}
|
}
|
||||||
record := q.Keeper.GetRecord(ctx, id)
|
record := q.Keeper.GetRecord(ctx, id)
|
||||||
return &types.QueryRecordByIDResponse{Record: record}, nil
|
return &types.QueryRecordByIDResponse{Record: record}, nil
|
||||||
@ -86,11 +87,11 @@ func (q Querier) LookupCrn(c context.Context, req *types.QueryLookupCrn) (*types
|
|||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
crn := req.GetCrn()
|
crn := req.GetCrn()
|
||||||
if !q.Keeper.HasNameRecord(ctx, crn) {
|
if !q.Keeper.HasNameRecord(ctx, crn) {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "CRN not found.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "CRN not found.")
|
||||||
}
|
}
|
||||||
nameRecord := q.Keeper.GetNameRecord(ctx, crn)
|
nameRecord := q.Keeper.GetNameRecord(ctx, crn)
|
||||||
if nameRecord == nil {
|
if nameRecord == nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "name record not found.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "name record not found.")
|
||||||
}
|
}
|
||||||
return &types.QueryLookupCrnResponse{Name: nameRecord}, nil
|
return &types.QueryLookupCrnResponse{Name: nameRecord}, nil
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ func (q Querier) ResolveCrn(c context.Context, req *types.QueryResolveCrn) (*typ
|
|||||||
crn := req.GetCrn()
|
crn := req.GetCrn()
|
||||||
record := q.Keeper.ResolveCRN(ctx, crn)
|
record := q.Keeper.ResolveCRN(ctx, crn)
|
||||||
if record == nil {
|
if record == nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "record not found.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, "record not found.")
|
||||||
}
|
}
|
||||||
return &types.QueryResolveCrnResponse{Record: record}, nil
|
return &types.QueryResolveCrnResponse{Record: record}, nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
auctionkeeper "github.com/cerc-io/laconicd/x/auction/keeper"
|
auctionkeeper "github.com/cerc-io/laconicd/x/auction/keeper"
|
||||||
bondkeeper "github.com/cerc-io/laconicd/x/bond/keeper"
|
bondkeeper "github.com/cerc-io/laconicd/x/bond/keeper"
|
||||||
"github.com/cerc-io/laconicd/x/registry/helpers"
|
"github.com/cerc-io/laconicd/x/registry/helpers"
|
||||||
@ -240,7 +241,7 @@ func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*type
|
|||||||
resourceSignBytes, _ := record.GetSignBytes()
|
resourceSignBytes, _ := record.GetSignBytes()
|
||||||
cid, err := record.GetCID()
|
cid, err := record.GetCID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid record JSON")
|
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid record JSON")
|
||||||
}
|
}
|
||||||
|
|
||||||
record.ID = cid
|
record.ID = cid
|
||||||
@ -255,13 +256,13 @@ func (k Keeper) ProcessSetRecord(ctx sdk.Context, msg types.MsgSetRecord) (*type
|
|||||||
pubKey, err := legacy.PubKeyFromBytes(helpers.BytesFromBase64(sig.PubKey))
|
pubKey, err := legacy.PubKeyFromBytes(helpers.BytesFromBase64(sig.PubKey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error decoding pubKey from bytes: ", err)
|
fmt.Println("Error decoding pubKey from bytes: ", err)
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid public key.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Invalid public key.")
|
||||||
}
|
}
|
||||||
|
|
||||||
sigOK := pubKey.VerifySignature(resourceSignBytes, helpers.BytesFromBase64(sig.Sig))
|
sigOK := pubKey.VerifySignature(resourceSignBytes, helpers.BytesFromBase64(sig.Sig))
|
||||||
if !sigOK {
|
if !sigOK {
|
||||||
fmt.Println("Signature mismatch: ", sig.PubKey)
|
fmt.Println("Signature mismatch: ", sig.PubKey)
|
||||||
return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Invalid signature.")
|
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Invalid signature.")
|
||||||
}
|
}
|
||||||
record.Owners = append(record.Owners, pubKey.Address().String())
|
record.Owners = append(record.Owners, pubKey.Address().String())
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
auctiontypes "github.com/cerc-io/laconicd/x/auction/types"
|
auctiontypes "github.com/cerc-io/laconicd/x/auction/types"
|
||||||
"github.com/cerc-io/laconicd/x/registry/helpers"
|
"github.com/cerc-io/laconicd/x/registry/helpers"
|
||||||
"github.com/cerc-io/laconicd/x/registry/types"
|
"github.com/cerc-io/laconicd/x/registry/types"
|
||||||
@ -112,12 +113,12 @@ func (k Keeper) updateBlockChangeSetForName(ctx sdk.Context, crn string) {
|
|||||||
func (k Keeper) getAuthority(ctx sdk.Context, crn string) (string, *url.URL, *types.NameAuthority, error) {
|
func (k Keeper) getAuthority(ctx sdk.Context, crn string) (string, *url.URL, *types.NameAuthority, error) {
|
||||||
parsedCRN, err := url.Parse(crn)
|
parsedCRN, err := url.Parse(crn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid CRN.")
|
return "", nil, nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid CRN.")
|
||||||
}
|
}
|
||||||
|
|
||||||
name := parsedCRN.Host
|
name := parsedCRN.Host
|
||||||
if !k.HasNameAuthority(ctx, name) {
|
if !k.HasNameAuthority(ctx, name) {
|
||||||
return name, nil, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
|
return name, nil, nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
|
||||||
}
|
}
|
||||||
authority := k.GetNameAuthority(ctx, name)
|
authority := k.GetNameAuthority(ctx, name)
|
||||||
return name, parsedCRN, &authority, nil
|
return name, parsedCRN, &authority, nil
|
||||||
@ -131,19 +132,19 @@ func (k Keeper) checkCRNAccess(ctx sdk.Context, signer sdk.AccAddress, crn strin
|
|||||||
|
|
||||||
formattedCRN := fmt.Sprintf("crn://%s%s", name, parsedCRN.RequestURI())
|
formattedCRN := fmt.Sprintf("crn://%s%s", name, parsedCRN.RequestURI())
|
||||||
if formattedCRN != crn {
|
if formattedCRN != crn {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid CRN.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid CRN.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if authority.OwnerAddress != signer.String() {
|
if authority.OwnerAddress != signer.String() {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if authority.Status != types.AuthorityActive {
|
if authority.Status != types.AuthorityActive {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Authority is not active.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Authority is not active.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if authority.BondId == "" || len(authority.BondId) == 0 {
|
if authority.BondId == "" || len(authority.BondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Authority bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Authority bond not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if authority.OwnerPublicKey == "" {
|
if authority.OwnerPublicKey == "" {
|
||||||
@ -323,13 +324,13 @@ func (k Keeper) ProcessReserveSubAuthority(ctx sdk.Context, name string, msg typ
|
|||||||
|
|
||||||
// Check if parent authority exists.
|
// Check if parent authority exists.
|
||||||
if !k.HasNameAuthority(ctx, parent) {
|
if !k.HasNameAuthority(ctx, parent) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Parent authority not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Parent authority not found.")
|
||||||
}
|
}
|
||||||
parentAuthority := k.GetNameAuthority(ctx, parent)
|
parentAuthority := k.GetNameAuthority(ctx, parent)
|
||||||
|
|
||||||
// Sub-authority creator needs to be the owner of the parent authority.
|
// Sub-authority creator needs to be the owner of the parent authority.
|
||||||
if parentAuthority.OwnerAddress != msg.Signer {
|
if parentAuthority.OwnerAddress != msg.Signer {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Access denied.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub-authority owner defaults to parent authority owner.
|
// Sub-authority owner defaults to parent authority owner.
|
||||||
@ -362,17 +363,17 @@ func (k Keeper) createAuthority(ctx sdk.Context, name string, owner string, isRo
|
|||||||
if k.HasNameAuthority(ctx, name) {
|
if k.HasNameAuthority(ctx, name) {
|
||||||
authority := k.GetNameAuthority(ctx, name)
|
authority := k.GetNameAuthority(ctx, name)
|
||||||
if authority.Status != types.AuthorityExpired {
|
if authority.Status != types.AuthorityExpired {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name already reserved.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Name already reserved.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ownerAddress, err := sdk.AccAddressFromBech32(owner)
|
ownerAddress, err := sdk.AccAddressFromBech32(owner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid owner address.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid owner address.")
|
||||||
}
|
}
|
||||||
ownerAccount := k.accountKeeper.GetAccount(ctx, ownerAddress)
|
ownerAccount := k.accountKeeper.GetAccount(ctx, ownerAddress)
|
||||||
if ownerAccount == nil {
|
if ownerAccount == nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "Account not found.")
|
return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "Account not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
authority := types.NameAuthority{
|
authority := types.NameAuthority{
|
||||||
@ -430,11 +431,11 @@ func (k Keeper) ProcessReserveAuthority(ctx sdk.Context, msg types.MsgReserveAut
|
|||||||
crn := fmt.Sprintf("crn://%s", msg.GetName())
|
crn := fmt.Sprintf("crn://%s", msg.GetName())
|
||||||
parsedCrn, err := url.Parse(crn)
|
parsedCrn, err := url.Parse(crn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid name")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid name")
|
||||||
}
|
}
|
||||||
name := parsedCrn.Host
|
name := parsedCrn.Host
|
||||||
if fmt.Sprintf("crn://%s", name) != crn {
|
if fmt.Sprintf("crn://%s", name) != crn {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Invalid name")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Invalid name")
|
||||||
}
|
}
|
||||||
if strings.Contains(name, ".") {
|
if strings.Contains(name, ".") {
|
||||||
return k.ProcessReserveSubAuthority(ctx, name, msg)
|
return k.ProcessReserveSubAuthority(ctx, name, msg)
|
||||||
@ -450,20 +451,20 @@ func (k Keeper) ProcessSetAuthorityBond(ctx sdk.Context, msg types.MsgSetAuthori
|
|||||||
name := msg.GetName()
|
name := msg.GetName()
|
||||||
signer := msg.GetSigner()
|
signer := msg.GetSigner()
|
||||||
if !k.HasNameAuthority(ctx, name) {
|
if !k.HasNameAuthority(ctx, name) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Name authority not found.")
|
||||||
}
|
}
|
||||||
authority := k.GetNameAuthority(ctx, name)
|
authority := k.GetNameAuthority(ctx, name)
|
||||||
if authority.OwnerAddress != signer {
|
if authority.OwnerAddress != signer {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Access denied")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Access denied")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
|
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
|
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
|
||||||
if bond.Owner != signer {
|
if bond.Owner != signer {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// No-op if bond hasn't changed.
|
// No-op if bond hasn't changed.
|
||||||
@ -496,7 +497,7 @@ func (k Keeper) ProcessDeleteName(ctx sdk.Context, msg types.MsgDeleteNameAuthor
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !k.HasNameRecord(ctx, msg.Crn) {
|
if !k.HasNameRecord(ctx, msg.Crn) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Name not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Name not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set CID to empty string.
|
// Set CID to empty string.
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
auctionkeeper "github.com/cerc-io/laconicd/x/auction/keeper"
|
auctionkeeper "github.com/cerc-io/laconicd/x/auction/keeper"
|
||||||
auctiontypes "github.com/cerc-io/laconicd/x/auction/types"
|
auctiontypes "github.com/cerc-io/laconicd/x/auction/types"
|
||||||
bondtypes "github.com/cerc-io/laconicd/x/bond/types"
|
bondtypes "github.com/cerc-io/laconicd/x/bond/types"
|
||||||
@ -158,7 +159,7 @@ func (k RecordKeeper) QueryRecordsByBond(ctx sdk.Context, bondID string) []types
|
|||||||
// ProcessRenewRecord renews a record.
|
// ProcessRenewRecord renews a record.
|
||||||
func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) error {
|
func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) error {
|
||||||
if !k.HasRecord(ctx, msg.RecordId) {
|
if !k.HasRecord(ctx, msg.RecordId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if renewal is required (i.e. expired record marked as deleted).
|
// Check if renewal is required (i.e. expired record marked as deleted).
|
||||||
@ -169,7 +170,7 @@ func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !record.Deleted || expiryTime.After(ctx.BlockTime()) {
|
if !record.Deleted || expiryTime.After(ctx.BlockTime()) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Renewal not required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Renewal not required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
recordType := record.ToRecordType()
|
recordType := record.ToRecordType()
|
||||||
@ -184,23 +185,23 @@ func (k Keeper) ProcessRenewRecord(ctx sdk.Context, msg types.MsgRenewRecord) er
|
|||||||
// ProcessAssociateBond associates a record with a bond.
|
// ProcessAssociateBond associates a record with a bond.
|
||||||
func (k Keeper) ProcessAssociateBond(ctx sdk.Context, msg types.MsgAssociateBond) error {
|
func (k Keeper) ProcessAssociateBond(ctx sdk.Context, msg types.MsgAssociateBond) error {
|
||||||
if !k.HasRecord(ctx, msg.RecordId) {
|
if !k.HasRecord(ctx, msg.RecordId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
|
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if already associated with a bond.
|
// Check if already associated with a bond.
|
||||||
record := k.GetRecord(ctx, msg.RecordId)
|
record := k.GetRecord(ctx, msg.RecordId)
|
||||||
if record.BondId != "" || len(record.BondId) != 0 {
|
if record.BondId != "" || len(record.BondId) != 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond already exists.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond already exists.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the bond owner can associate a record with the bond.
|
// Only the bond owner can associate a record with the bond.
|
||||||
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
|
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
|
||||||
if msg.Signer != bond.Owner {
|
if msg.Signer != bond.Owner {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
||||||
}
|
}
|
||||||
|
|
||||||
record.BondId = msg.BondId
|
record.BondId = msg.BondId
|
||||||
@ -218,20 +219,20 @@ func (k Keeper) ProcessAssociateBond(ctx sdk.Context, msg types.MsgAssociateBond
|
|||||||
// ProcessDissociateBond dissociates a record from its bond.
|
// ProcessDissociateBond dissociates a record from its bond.
|
||||||
func (k Keeper) ProcessDissociateBond(ctx sdk.Context, msg types.MsgDissociateBond) error {
|
func (k Keeper) ProcessDissociateBond(ctx sdk.Context, msg types.MsgDissociateBond) error {
|
||||||
if !k.HasRecord(ctx, msg.RecordId) {
|
if !k.HasRecord(ctx, msg.RecordId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Record not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if associated with a bond.
|
// Check if associated with a bond.
|
||||||
record := k.GetRecord(ctx, msg.RecordId)
|
record := k.GetRecord(ctx, msg.RecordId)
|
||||||
bondID := record.BondId
|
bondID := record.BondId
|
||||||
if bondID == "" || len(bondID) == 0 {
|
if bondID == "" || len(bondID) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the bond owner can dissociate a record from the bond.
|
// Only the bond owner can dissociate a record from the bond.
|
||||||
bond := k.bondKeeper.GetBond(ctx, bondID)
|
bond := k.bondKeeper.GetBond(ctx, bondID)
|
||||||
if msg.Signer != bond.Owner {
|
if msg.Signer != bond.Owner {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear bond ID.
|
// Clear bond ID.
|
||||||
@ -245,13 +246,13 @@ func (k Keeper) ProcessDissociateBond(ctx sdk.Context, msg types.MsgDissociateBo
|
|||||||
// ProcessDissociateRecords dissociates all records associated with a given bond.
|
// ProcessDissociateRecords dissociates all records associated with a given bond.
|
||||||
func (k Keeper) ProcessDissociateRecords(ctx sdk.Context, msg types.MsgDissociateRecords) error {
|
func (k Keeper) ProcessDissociateRecords(ctx sdk.Context, msg types.MsgDissociateRecords) error {
|
||||||
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
|
if !k.bondKeeper.HasBond(ctx, msg.BondId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Bond not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the bond owner can dissociate all records from the bond.
|
// Only the bond owner can dissociate all records from the bond.
|
||||||
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
|
bond := k.bondKeeper.GetBond(ctx, msg.BondId)
|
||||||
if msg.Signer != bond.Owner {
|
if msg.Signer != bond.Owner {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond owner mismatch.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dissociate all records from the bond.
|
// Dissociate all records from the bond.
|
||||||
@ -269,22 +270,22 @@ func (k Keeper) ProcessDissociateRecords(ctx sdk.Context, msg types.MsgDissociat
|
|||||||
// ProcessReAssociateRecords switches records from and old to new bond.
|
// ProcessReAssociateRecords switches records from and old to new bond.
|
||||||
func (k Keeper) ProcessReAssociateRecords(ctx sdk.Context, msg types.MsgReAssociateRecords) error {
|
func (k Keeper) ProcessReAssociateRecords(ctx sdk.Context, msg types.MsgReAssociateRecords) error {
|
||||||
if !k.bondKeeper.HasBond(ctx, msg.OldBondId) {
|
if !k.bondKeeper.HasBond(ctx, msg.OldBondId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Old bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Old bond not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !k.bondKeeper.HasBond(ctx, msg.NewBondId) {
|
if !k.bondKeeper.HasBond(ctx, msg.NewBondId) {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "New bond not found.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "New bond not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only the bond owner can re-associate all records.
|
// Only the bond owner can re-associate all records.
|
||||||
oldBond := k.bondKeeper.GetBond(ctx, msg.OldBondId)
|
oldBond := k.bondKeeper.GetBond(ctx, msg.OldBondId)
|
||||||
if msg.Signer != oldBond.Owner {
|
if msg.Signer != oldBond.Owner {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Old bond owner mismatch.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Old bond owner mismatch.")
|
||||||
}
|
}
|
||||||
|
|
||||||
newBond := k.bondKeeper.GetBond(ctx, msg.NewBondId)
|
newBond := k.bondKeeper.GetBond(ctx, msg.NewBondId)
|
||||||
if msg.Signer != newBond.Owner {
|
if msg.Signer != newBond.Owner {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "New bond owner mismatch.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "New bond owner mismatch.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-associate all records.
|
// Re-associate all records.
|
||||||
|
@ -3,6 +3,7 @@ package types
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
@ -32,15 +33,15 @@ func (msg MsgSetName) Type() string { return "set-name" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgSetName) ValidateBasic() error {
|
func (msg MsgSetName) ValidateBasic() error {
|
||||||
if msg.Crn == "" {
|
if msg.Crn == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "CRN is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CRN is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Cid == "" {
|
if msg.Cid == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -76,11 +77,11 @@ func (msg MsgReserveAuthority) Type() string { return "reserve-authority" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgReserveAuthority) ValidateBasic() error {
|
func (msg MsgReserveAuthority) ValidateBasic() error {
|
||||||
if len(msg.Name) == 0 {
|
if len(msg.Name) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -116,15 +117,15 @@ func (msg MsgSetAuthorityBond) Type() string { return "authority-bond" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgSetAuthorityBond) ValidateBasic() error {
|
func (msg MsgSetAuthorityBond) ValidateBasic() error {
|
||||||
if len(msg.Name) == 0 {
|
if len(msg.Name) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "name is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.BondId) == 0 {
|
if len(msg.BondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "bond id is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -159,16 +160,16 @@ func (msg MsgDeleteNameAuthority) Type() string { return "delete-name" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgDeleteNameAuthority) ValidateBasic() error {
|
func (msg MsgDeleteNameAuthority) ValidateBasic() error {
|
||||||
if len(msg.Crn) == 0 {
|
if len(msg.Crn) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "crn is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "crn is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := url.Parse(msg.Crn)
|
_, err := url.Parse(msg.Crn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid crn.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid crn.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
errorsmod "cosmossdk.io/errors"
|
||||||
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
@ -34,17 +35,17 @@ func (msg MsgSetRecord) Type() string { return "set-record" }
|
|||||||
|
|
||||||
func (msg MsgSetRecord) ValidateBasic() error {
|
func (msg MsgSetRecord) ValidateBasic() error {
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, msg.Signer)
|
||||||
}
|
}
|
||||||
owners := msg.Payload.Record.Owners
|
owners := msg.Payload.Record.Owners
|
||||||
for _, owner := range owners {
|
for _, owner := range owners {
|
||||||
if owner == "" {
|
if owner == "" {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Record owner not set.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Record owner not set.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.BondId) == 0 {
|
if len(msg.BondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "Bond ID is required.")
|
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Bond ID is required.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -83,11 +84,11 @@ func (msg MsgRenewRecord) Type() string { return "renew-record" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgRenewRecord) ValidateBasic() error {
|
func (msg MsgRenewRecord) ValidateBasic() error {
|
||||||
if len(msg.RecordId) == 0 {
|
if len(msg.RecordId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -123,13 +124,13 @@ func (msg MsgAssociateBond) Type() string { return "associate-bond" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgAssociateBond) ValidateBasic() error {
|
func (msg MsgAssociateBond) ValidateBasic() error {
|
||||||
if len(msg.RecordId) == 0 {
|
if len(msg.RecordId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
||||||
}
|
}
|
||||||
if len(msg.BondId) == 0 {
|
if len(msg.BondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -164,10 +165,10 @@ func (msg MsgDissociateBond) Type() string { return "dissociate-bond" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgDissociateBond) ValidateBasic() error {
|
func (msg MsgDissociateBond) ValidateBasic() error {
|
||||||
if len(msg.RecordId) == 0 {
|
if len(msg.RecordId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "record id is required.")
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -202,10 +203,10 @@ func (msg MsgDissociateRecords) Type() string { return "dissociate-records" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgDissociateRecords) ValidateBasic() error {
|
func (msg MsgDissociateRecords) ValidateBasic() error {
|
||||||
if len(msg.BondId) == 0 {
|
if len(msg.BondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "bond id is required.")
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -241,13 +242,13 @@ func (msg MsgReAssociateRecords) Type() string { return "reassociate-records" }
|
|||||||
// ValidateBasic Implements Msg.
|
// ValidateBasic Implements Msg.
|
||||||
func (msg MsgReAssociateRecords) ValidateBasic() error {
|
func (msg MsgReAssociateRecords) ValidateBasic() error {
|
||||||
if len(msg.OldBondId) == 0 {
|
if len(msg.OldBondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "old-bond-id is required.")
|
||||||
}
|
}
|
||||||
if len(msg.NewBondId) == 0 {
|
if len(msg.NewBondId) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "new-bond-id is required.")
|
||||||
}
|
}
|
||||||
if len(msg.Signer) == 0 {
|
if len(msg.Signer) == 0 {
|
||||||
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user