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

Conversation

dreamer-zq
Copy link
Collaborator

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@dreamer-zq dreamer-zq requested a review from a team as a code owner June 8, 2022 10:50
@codecov
Copy link

codecov bot commented Jun 8, 2022

Codecov Report

Merging #12187 (dd666e8) into main (4c3b7af) will increase coverage by 0.01%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12187      +/-   ##
==========================================
+ Coverage   66.10%   66.12%   +0.01%     
==========================================
  Files         673      674       +1     
  Lines       71097    71155      +58     
==========================================
+ Hits        46999    47051      +52     
- Misses      21458    21462       +4     
- Partials     2640     2642       +2     
Impacted Files Coverage Δ
x/nft/keeper/nft_batch.go 87.50% <87.50%> (ø)
x/nft/keeper/nft.go 83.56% <100.00%> (+1.20%) ⬆️

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of these should use the Mint, Burn, Update, Transfer from the keeper instead of repeating logic. Did you have a reason not to?

@dreamer-zq
Copy link
Collaborator Author

dreamer-zq commented Jun 11, 2022

I think most of these should use the Mint, Burn, Update, Transfer from the keeper instead of repeating logic. Did you have a reason not to?

This is indeed the case. I do this now because some logic is repeated, such as class verification, which can reduce gas. Or add some xxxxWithNoCheck (for example: MintWithNoCheck, BatchMintWithNoCheck) methods, the verification logic is implemented by the upper layer, what do you think?

@julienrbrt
Copy link
Member

julienrbrt commented Jun 11, 2022

This is indeed the case. I do this now because some logic is repeated, such as class verification, which can reduce gas. Or add some xxxxWithNoCheck (for example: MintWithNoCheck, BatchMintWithNoCheck) methods, the verification logic is implemented by the upper layer, what do you think?

Alright, but the class verification logic is already in Mint, so if you remove it from BatchMint that shouldn't be an issue, right?

The following f.e. has no duplicate class verification, then.

// BatchMint defines a method for minting a batch of nfts
func (k Keeper) BatchMint(ctx sdk.Context,
	tokens []nft.NFT,
	receiver sdk.AccAddress,
) error {
	classIDs := make(map[string]bool, len(tokens))
	for _, token := range tokens {
		if !classIDs[token.ClassId] {
			return sdkerrors.Wrap(nft.ErrClassNotExists, token.ClassId)
		}

		if err := k.Mint(ctx, token, receiver); err != nil {
			return err
		}

		classIDs[token.ClassId] = true
	}
	return nil
}

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

I see now what you've meant about the repeating checks, these happen for methods with classID as argument (BatchTransfer and BatchBurn). Maybe a transferWithNoCheck and burnWithNoCheck used in Transfer, BatchTransfer, Burn, BatchBurn do indeed make sense for these, not sure 🤷🏾‍♂️

@dreamer-zq
Copy link
Collaborator Author

lgtm!

I see now what you've meant about the repeating checks, these happen for methods with classID as argument (BatchTransfer and BatchBurn). Maybe a transferWithNoCheck and burnWithNoCheck used in Transfer, BatchTransfer, Burn, BatchBurn do indeed make sense for these, not sure 🤷🏾‍♂️

Yes, I want to separate the verification logic, and let the upper application decide how to verify (transferWithNoCheck) or use Transfer directly (sdk is responsible for verification). This way the user has more flexibility, now do you think we should add the noCheck method to these methods? If you agree to this, I can continue to modify these

x/nft/keeper/nft.go Outdated Show resolved Hide resolved
@julienrbrt
Copy link
Member

Thanks @dreamer-zq, one last thing, can we add a changelog? :)

@julienrbrt
Copy link
Member

julienrbrt commented Jun 14, 2022

Alright, because of #12233 your tests are failing 🙉 can you please fix them?
➡️ s.app.NFTKeeper to s.nftKeeper should do it.

@julienrbrt julienrbrt added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 14, 2022
@julienrbrt julienrbrt merged commit d705a8b into cosmos:main Jun 15, 2022
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a spec update as well. please update docs prior to merging next time

@julienrbrt
Copy link
Member

julienrbrt commented Jun 15, 2022

Sorry, I forgot to check that. @dreamer-zq Could you submit a follow-up PR?

@dreamer-zq
Copy link
Collaborator Author

dreamer-zq commented Jun 16, 2022

This needs a spec update as well. please update docs prior to merging next time

Ok, Is it the documentation in x/nft/spec ? This change does not modify the relevant state, msg, or event. So what exactly should be changed? Is it adr-043-nft-module ?

@dreamer-zq dreamer-zq mentioned this pull request Jun 17, 2022
19 tasks
@dreamer-zq
Copy link
Collaborator Author

dreamer-zq commented Jun 17, 2022

Sorry, I forgot to check that. @dreamer-zq Could you submit a follow-up PR?
12293

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. C:x/nft
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants