Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add batch operation for x/nft module #12187

Merged
merged 15 commits into from
Jun 15, 2022
Prev Previous commit
Next Next commit
private noCheck method
  • Loading branch information
Dreamer committed Jun 14, 2022
commit 953275ebbe88ab26dbf2dc0e33f562283a14174b
20 changes: 10 additions & 10 deletions x/nft/keeper/nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func (k Keeper) Mint(ctx sdk.Context, token nft.NFT, receiver sdk.AccAddress) er
return sdkerrors.Wrap(nft.ErrNFTExists, token.Id)
}

k.MintWithNoCheck(ctx, token, receiver)
k.mintWithNoCheck(ctx, token, receiver)
return nil
}

// MintWithNoCheck defines a method for minting a new nft
// mintWithNoCheck defines a method for minting a new nft
// Note: this method does not check whether the class already exists in nft.
// The upper-layer application needs to check it when it needs to use it.
func (k Keeper) MintWithNoCheck(ctx sdk.Context, token nft.NFT, receiver sdk.AccAddress) {
func (k Keeper) mintWithNoCheck(ctx sdk.Context, token nft.NFT, receiver sdk.AccAddress) {
k.setNFT(ctx, token)
k.setOwner(ctx, token.ClassId, token.Id, receiver)
k.incrTotalSupply(ctx, token.ClassId)
Expand All @@ -47,14 +47,14 @@ func (k Keeper) Burn(ctx sdk.Context, classID string, nftID string) error {
return sdkerrors.Wrap(nft.ErrNFTNotExists, nftID)
}

k.BurnWithNoCheck(ctx, classID, nftID)
k.burnWithNoCheck(ctx, classID, nftID)
return nil
}

// BurnWithNoCheck defines a method for burning a nft from a specific account.
// burnWithNoCheck defines a method for burning a nft from a specific account.
// Note: this method does not check whether the class already exists in nft.
// The upper-layer application needs to check it when it needs to use it
func (k Keeper) BurnWithNoCheck(ctx sdk.Context, classID string, nftID string) error {
func (k Keeper) burnWithNoCheck(ctx sdk.Context, classID string, nftID string) error {
owner := k.GetOwner(ctx, classID, nftID)
nftStore := k.getNFTStore(ctx, classID)
nftStore.Delete([]byte(nftID))
Expand All @@ -79,14 +79,14 @@ func (k Keeper) Update(ctx sdk.Context, token nft.NFT) error {
if !k.HasNFT(ctx, token.ClassId, token.Id) {
return sdkerrors.Wrap(nft.ErrNFTNotExists, token.Id)
}
k.UpdateWithNoCheck(ctx, token)
k.updateWithNoCheck(ctx, token)
return nil
}

// Update defines a method for updating an exist nft
// Note: this method does not check whether the class already exists in nft.
// The upper-layer application needs to check it when it needs to use it
func (k Keeper) UpdateWithNoCheck(ctx sdk.Context, token nft.NFT) {
func (k Keeper) updateWithNoCheck(ctx sdk.Context, token nft.NFT) {
k.setNFT(ctx, token)
}

Expand All @@ -105,14 +105,14 @@ func (k Keeper) Transfer(ctx sdk.Context,
return sdkerrors.Wrap(nft.ErrNFTNotExists, nftID)
}

k.TransferWithNoCheck(ctx, classID, nftID, receiver)
k.transferWithNoCheck(ctx, classID, nftID, receiver)
return nil
}

// Transfer defines a method for sending a nft from one account to another account.
// Note: this method does not check whether the class already exists in nft.
// The upper-layer application needs to check it when it needs to use it
func (k Keeper) TransferWithNoCheck(ctx sdk.Context,
func (k Keeper) transferWithNoCheck(ctx sdk.Context,
classID string,
nftID string,
receiver sdk.AccAddress,
Expand Down
8 changes: 4 additions & 4 deletions x/nft/keeper/nft_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (k Keeper) BatchMint(ctx sdk.Context,
}

julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
checked[token.ClassId] = true
k.MintWithNoCheck(ctx, token, receiver)
k.mintWithNoCheck(ctx, token, receiver)
}
return nil
}
Expand All @@ -37,7 +37,7 @@ func (k Keeper) BatchBurn(ctx sdk.Context, classID string, nftIDs []string) erro
if !k.HasNFT(ctx, classID, nftID) {
return sdkerrors.Wrap(nft.ErrNFTNotExists, nftID)
}
if err := k.BurnWithNoCheck(ctx, classID, nftID); err != nil {
if err := k.burnWithNoCheck(ctx, classID, nftID); err != nil {
return err
}
}
Expand All @@ -57,7 +57,7 @@ func (k Keeper) BatchUpdate(ctx sdk.Context, tokens []nft.NFT) error {
return sdkerrors.Wrap(nft.ErrNFTNotExists, token.Id)
}
checked[token.ClassId] = true
k.UpdateWithNoCheck(ctx, token)
k.updateWithNoCheck(ctx, token)
}
return nil
}
Expand All @@ -76,7 +76,7 @@ func (k Keeper) BatchTransfer(ctx sdk.Context,
if !k.HasNFT(ctx, classID, nftID) {
return sdkerrors.Wrap(nft.ErrNFTNotExists, nftID)
}
if err := k.TransferWithNoCheck(ctx, classID, nftID, receiver); err != nil {
if err := k.transferWithNoCheck(ctx, classID, nftID, receiver); err != nil {
return sdkerrors.Wrap(nft.ErrNFTNotExists, nftID)
}
}
Expand Down