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

NFT Module #4209

Merged
merged 180 commits into from
Aug 26, 2019
Merged

NFT Module #4209

merged 180 commits into from
Aug 26, 2019

Conversation

fedekunze
Copy link
Collaborator

@fedekunze fedekunze commented Apr 26, 2019

Closes #4046

Specification: #4766

Closes: #4809


  • Targeted PR against correct branch (see CONTRIBUTING.md)

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.

  • Wrote tests

  • Updated relevant documentation (docs/)

  • Added a relevant changelog entry: sdkch add [section] [stanza] [message]

  • rereviewed Files changed in the github PR explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

x/nfts/client/cli/query.go Outdated Show resolved Hide resolved
x/nfts/client/cli/query.go Outdated Show resolved Hide resolved
@fedekunze fedekunze requested a review from okwme April 28, 2019 23:15
x/nfts/keeper/key.go Outdated Show resolved Hide resolved
x/nfts/types/msgs.go Outdated Show resolved Hide resolved
x/nfts/types/msgs.go Outdated Show resolved Hide resolved
x/nfts/types/msgs.go Outdated Show resolved Hide resolved
x/nft/client/cli/query.go Outdated Show resolved Hide resolved
x/nft/client/cli/query.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

Mostly reviewed the spec. Beyond the typos I'm okay with this PR getting merged without the major indexing changes I've suggested so long as issues are opened such that NFT will be updated in future PRs.

After these comments are addressed (as well as merge conflicts) I recommend we merge NFT ASAP in order to include it in our on-going sdk maintenance as core changes are made.

docs/spec/SPEC-SPEC.md Outdated Show resolved Hide resolved
}
```

An `IDCollection` is similar to a `Collection` except instead of containing NFTs it only contains an array of `NFT` IDs. This saves storage by avoiding redundancy.
Copy link
Contributor

@rigelrozanski rigelrozanski Aug 2, 2019

Choose a reason for hiding this comment

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

EDIT:
we should most likely eliminate these structs if they are expected to be stored anywhere and simply replace them with indexes on the NFT object see my next comment


couple things, a) in the above owner struct the field is of type IDCollections however you only define the IDCollection (singular) struct below, we should probably also include the line:

type IDCollections [] IDCollection 

just for clarity.

b) type Collection should probably expose a function GetIDCollections() IDCollections and similarly NFT should expose a function GetIDCollection() IDCollection. These functions are worth mentioning maybe? add this into the NFT type interface at maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

docs/spec/nft/01_concepts.md Outdated Show resolved Hide resolved
type IDCollection struct {
Denom string `json:"denom"`
IDs []string `json:"IDs"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yo. Okay so I think that the NFT design should be restructured to eliminate the:

  • Owner struct
  • IDCollection struct

We should instead by applying the use of secondary indexes similarly to how the staking module stores references to the same validators by: operator-address, consensus-address, power, etc. (see example https://github.com/cosmos/cosmos-sdk/blob/master/x/staking/keeper/validator.go#L70)
(see spec: https://github.com/cosmos/cosmos-sdk/blob/master/docs/spec/staking/01_state.md#validator)

This way we should be able to easily create functions on the NFTKeeper to get the NFTs efficiently without requiring these extra object. For example I'd suggest the keeper look like:

type NFTKeeper interface {
    GetNFTByID(string) NFT
    GetCollectionByDenom(string) []*NFT
    GetCollectionsByOwner(sdk.AccAddress) []Collection
}

Or something along those lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened the issue #4955


As all NFTs belong to a specific `Collection`, they are kept on store in an array
within each `Collection`. Every time an NFT that belongs to a collection is updated,
it needs to be updated on the corresponding NFT array on the corresponding `Collection`.
Copy link
Contributor

Choose a reason for hiding this comment

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

whoa - are you saying NFTs are stored in two places? that sounds like asking for trouble. We should most certainly only store pointer objects in the collection to avoid having to update both. (See my suggested code change to the spec).

Copy link
Contributor

Choose a reason for hiding this comment

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

docs/spec/nft/05_future_improvements.md Outdated Show resolved Hide resolved
docs/spec/nft/05_future_improvements.md Outdated Show resolved Hide resolved
docs/spec/nft/README.md Outdated Show resolved Hide resolved
fedekunze and others added 5 commits August 2, 2019 23:34
Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com>
Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com>
@tnachen
Copy link
Contributor

tnachen commented Aug 22, 2019

needs @rigelrozanski @alexanderbez review

@alexanderbez
Copy link
Contributor

I would not advise blocking this PR on my review (although I will still review). Please resolve CI and merge conflict issues and merge with preferably @rigelrozanski's approval.

simapp/sim_test.go Show resolved Hide resolved
simapp/sim_test.go Show resolved Hide resolved
simapp/sim_test.go Show resolved Hide resolved
x/nft/client/cli/query.go Outdated Show resolved Hide resolved
x/nft/simulation/operations/msgs.go Outdated Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
simapp/sim_test.go Show resolved Hide resolved
simapp/sim_test.go Show resolved Hide resolved
simapp/sim_test.go Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
x/nft/internal/keeper/querier_test.go Show resolved Hide resolved
x/nft/internal/types/owners_test.go Show resolved Hide resolved
@RiccardoM
Copy link
Contributor

Sorry for asking guys, but is this PR going to be merged anytime soon?

@fedekunze
Copy link
Collaborator Author

@RiccardoM yeah, @rigelrozanski just needs to approve + merge

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

Approved - indexing issue opened as an offshoot here (https://github.com/cosmos/cosmos-sdk/issues/4955)

simapp/app.go Outdated Show resolved Hide resolved
Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>
@rigelrozanski rigelrozanski merged commit eeb847c into master Aug 26, 2019
@rigelrozanski rigelrozanski deleted the billy/nft branch August 26, 2019 16:54
@fedekunze fedekunze mentioned this pull request Aug 27, 2019
4 tasks
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* in sync with @okwme/cosmos-nft

* remove tmp tx

* structuring and minor changes

* supply and client files

* adding cli client

* complete cli/tx and rest.go

* cleanup and restructuring

* restructure rest folder

* minor updates on clients

* update querier

* encoding for clients and other changes

* genesis, invariants, and keeper updates

* update types

* make golangcibot happy

* renamed and removed bank keeper

* remove handlers for editmetadata, mint, burn, buy

* nft interface

* minor cleanup

* sort collections and nfts

* balance and find

* nft query and tx

* touch ups

* uint in place of int

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* little fixes:
- fix error to err to avoid collision
- error handling

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* module generalization changes

* fixes

* query with data

* minor updates and TODOs

* fix CLI tx

* golang bot fixes

* handlers and txs done

* update module generalization

* Added very basic tests which for some reason do not work

* fix test

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* fixed test, now we should fix implementation, seems to fail

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* fix test, create new struct instead of changing the old one

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* fix handler with new logic

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* let's make it compile

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* single failing test example, need to be fixed and extended

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* single failing test example, need to be fixed and extended

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* reverting work, still problems unmarshalling inside iterator from test

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* Setter in nft.go should return NFT instead of BaseNFT

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* remove TODOS

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* comment out broken tests, we want at least a green mark here

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* little fixes

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* hopefully no conflict

* minor changes for tests

* change nft id to string, refactors

* messy pause

* Changes Balances to OWners add all necessary functions, updated Keeper with UpdateNFT as as well as MintNFT and made sure they all update Owners

* pause dev to merge sdk master

* go.mod changes

* getting closer still need module.go

* builds!!!

* fix lint begin handler tests

* stableish

* re-order nft attributes, add back mint and burn msgs and handlers

* add errors to minting the same NFT and burning an NFT that doesnt exist

* first querier test

* add simulations for nft msgs

* handler tests check tags now (fixed a bug!)

* update simulation

* generic handler

* need to check if it compiles on another machine

* fix weird interface error

* add back cli

* wtfff

* codec error fixed, logs removed. still returning empty arrays of IDs

* Take empty input as yes answer

Closes: cosmos#4564

* Add pending log entry

* merged in master

* marshall errors

* build commands

* working!!!

* linting errors

* remove unused func

* pause

* fix burn error

* fix burn error

* tests for querier

* typo

* tests for NFT types

* module spec standard

* tests for Collection and Collections types

* merge w Fede

* tests for Owner Type

* added genesis tests and beefed up keeper, querier, handler & types tests

* linting errors deadcode

* DONT COVER test_common.go

* add msg type tests

* Update x/nft/internal/keeper/key.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/nft/genesis.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/nft/client/cli/query.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Apply suggestions from code review

* typo

* cleanup events

* split events

* more cleanup

* remove restrictions from default handlers

* not sure where these go mod changes came from

* sim generated changes

* make format

* add mint and burn sims

* move NFT interface to nft/exported

* make format

* NFT spec

* Updates

* more updates

* update specs readme

* fix sims

* rest additions

* rest additions

* fix invariant

* minimal nft without name, description or image

* sim

* fix sim

* fix sim

* fix Update methods

* nothing

* simplify update and remove

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* remove test on memory location

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* TEST to get logs, need to be removed

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* fix simulator editMetadata Msg type

* owner not found start with empty collection

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* artifacts on errors in case of failure, else, no artifacts

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>

* add more invariant checks to handler_tests

* never forget to overwrite

* merge and update spec

* colins feedback

* code coverage test

* code coverage test

* code coverage test

* spelling

* clean up client

* testing code coverage

* testing code coverage

* testing code coverage

* testing code coverage

* testing code coverage

* Update docs/spec/nft/README.md

Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com>

* Apply suggestions from code review

Co-Authored-By: frog power 4000 <rigel.rozanski@gmail.com>

* minor changes

* integration tests and fixes

* minor golangCI fixes

* Update simapp/app.go

Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simulations gives little hint on why they fails NFT Module