-
Notifications
You must be signed in to change notification settings - Fork 70
feat(nft): nft module #296
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
Open
angelorc
wants to merge
15
commits into
main
Choose a base branch
from
mvp/nft-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6e4788b
feat(nft): implement NFT minting functionality and related types
angelorc 628135e
fix(nft): correct collection denom creation and update test to log denom
angelorc e834bf6
fix(workflow): clean up branch definitions in interchaintest E2E work…
angelorc a658097
feat: add gRPC gateway support for NFT queries
angelorc ed1caf0
feat(nft): enhance NFT minting and querying functionality
angelorc d8a9e7f
refactor(nft): rename OwnersPrefix to NFTsByOwnerPrefix
angelorc 9b543d8
feat(nft): refactor NFT keeper methods to use context and add NFT tra…
angelorc 466b947
fix(nft): update query paths to use plural 'collections'
angelorc c5ed2f8
feat(nft): enhance NFT minting and metadata validation
angelorc dd85dc4
Remove NumTokens query handlers and associated code from NFT query se…
angelorc 42402ba
refactor(nft): update query and nft.proto
angelorc 4f2e29f
Remove description in NFT and Collection
angelorc abae283
Add MsgServer
angelorc 59b13f5
feat(nft): add authority
angelorc 45df9c0
feat(drop): implement drop module
angelorc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| syntax = "proto3"; | ||
| package bitsong.nft.v1beta1; | ||
|
|
||
| option go_package = "github.com/bitsongofficial/go-bitsong/x/nft/types"; | ||
|
|
||
| message Collection { | ||
| string symbol = 1; | ||
| string name = 2; | ||
| string description = 3; | ||
| string uri = 4; | ||
| string creator = 5; | ||
| string minter = 6; | ||
| uint64 num_tokens = 7; | ||
| // bool is_mutable | ||
| // update_autority (who can update name, description and uri if is_mutable = true) | ||
| } | ||
|
|
||
| message Nft { | ||
| string name = 1; | ||
| string description = 2; | ||
| string uri = 3; | ||
| // string owner = 5; | ||
| // seller_fee_bps | ||
| // payment_address | ||
| // bool is_mutable | ||
| // update_autority (who can update name, description and uri if is_mutable = true) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "cosmossdk.io/math" | ||
| "github.com/bitsongofficial/go-bitsong/x/nft/types" | ||
| tmcrypto "github.com/cometbft/cometbft/crypto" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
| ) | ||
|
|
||
| func (k Keeper) CreateCollection(ctx sdk.Context, creator sdk.AccAddress, coll types.Collection) (denom string, err error) { | ||
| denom, err = k.validateCollectionDenom(ctx, creator, coll.Symbol) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| // TODO: charge fee | ||
|
|
||
| metadata := banktypes.Metadata{ | ||
| DenomUnits: []*banktypes.DenomUnit{{ | ||
| Denom: denom, | ||
| Exponent: 0, | ||
| }}, | ||
| Base: denom, | ||
| Name: coll.Name, | ||
| Description: coll.Description, | ||
| Symbol: coll.Symbol, | ||
| Display: coll.Symbol, | ||
| URI: coll.Uri, | ||
| } | ||
|
|
||
| k.bk.SetDenomMetaData(ctx, metadata) | ||
|
|
||
| if err := k.setCollection(ctx, denom, coll); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return denom, nil | ||
| } | ||
|
|
||
| func (k Keeper) GetSupply(ctx sdk.Context, denom string) math.Int { | ||
| supply, err := k.Supply.Get(ctx, denom) | ||
| if err != nil { | ||
| return math.ZeroInt() | ||
| } | ||
|
|
||
| return supply | ||
| } | ||
|
|
||
| func (k Keeper) HasSupply(ctx sdk.Context, denom string) bool { | ||
| has, err := k.Supply.Has(ctx, denom) | ||
| return has && err == nil | ||
| } | ||
|
|
||
| func (k Keeper) setSupply(ctx sdk.Context, denom string, supply math.Int) error { | ||
| return k.Supply.Set(ctx, denom, supply) | ||
| } | ||
|
|
||
| func (k Keeper) incrementSupply(ctx sdk.Context, denom string) error { | ||
| supply := k.GetSupply(ctx, denom) | ||
| supply = supply.Add(math.NewInt(1)) | ||
|
|
||
| return k.setSupply(ctx, denom, supply) | ||
| } | ||
|
|
||
| func (k Keeper) createCollectionDenom(creator sdk.AccAddress, symbol string) string { | ||
| // TODO: if necessary add a salt field | ||
|
|
||
| bz := []byte(fmt.Sprintf("%s%s", creator.String(), symbol)) | ||
| return "nft" + tmcrypto.AddressHash(bz).String() | ||
| } | ||
|
|
||
| func (k Keeper) validateCollectionDenom(ctx sdk.Context, creator sdk.AccAddress, symbol string) (string, error) { | ||
| denom := k.createCollectionDenom(creator, symbol) | ||
|
|
||
| if err := sdk.ValidateDenom(denom); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if k.bk.HasSupply(ctx, symbol) { | ||
| return "", fmt.Errorf("denom %s already exists", denom) | ||
| } | ||
|
|
||
| _, exists := k.bk.GetDenomMetaData(ctx, denom) | ||
| if exists { | ||
| return "", types.ErrCollectionAlreadyExists | ||
| } | ||
angelorc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return denom, nil | ||
| } | ||
|
|
||
| func (k Keeper) setCollection(ctx sdk.Context, denom string, coll types.Collection) error { | ||
| return k.Collections.Set(ctx, denom, coll) | ||
| } | ||
|
|
||
| func (k Keeper) getCollection(ctx sdk.Context, denom string) (types.Collection, error) { | ||
| coll, err := k.Collections.Get(ctx, denom) | ||
| if err != nil { | ||
| return types.Collection{}, types.ErrCollectionNotFound | ||
| } | ||
|
|
||
| return coll, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/cometbft/cometbft/crypto/tmhash" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| ) | ||
|
|
||
| func TestKeeper_createCollectionDenom(t *testing.T) { | ||
| creator := sdk.AccAddress(tmhash.SumTruncated([]byte("creator"))) | ||
| symbol := "MYNFT" | ||
|
|
||
| expectedDenom := "nftF1D9FE89CCE1FAD3F83FFCBA6F496EFD30855C42" | ||
| k := Keeper{} | ||
|
|
||
| denom := k.createCollectionDenom(creator, symbol) | ||
| if denom != expectedDenom { | ||
| t.Errorf("expected %s, got %s", expectedDenom, denom) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| "cosmossdk.io/collections" | ||
| "cosmossdk.io/core/address" | ||
| "cosmossdk.io/core/store" | ||
| "cosmossdk.io/log" | ||
| "cosmossdk.io/math" | ||
| "github.com/bitsongofficial/go-bitsong/x/nft/types" | ||
| "github.com/cosmos/cosmos-sdk/codec" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| ) | ||
|
|
||
| type Keeper struct { | ||
| cdc codec.BinaryCodec | ||
| storeService store.KVStoreService | ||
| ac address.Codec | ||
| bk types.BankKeeper | ||
| logger log.Logger | ||
|
|
||
| Schema collections.Schema | ||
| Collections collections.Map[string, types.Collection] | ||
| Supply collections.Map[string, math.Int] | ||
| } | ||
|
|
||
| func NewKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService, ak types.AccountKeeper, bk types.BankKeeper, logger log.Logger) Keeper { | ||
| if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { | ||
| panic("the " + types.ModuleName + " module account has not been set") | ||
| } | ||
|
|
||
| logger = logger.With(log.ModuleKey, "x/"+types.ModuleName) | ||
|
|
||
| sb := collections.NewSchemaBuilder(storeService) | ||
|
|
||
| return Keeper{ | ||
| cdc: cdc, | ||
| storeService: storeService, | ||
| ac: ak.AddressCodec(), | ||
| bk: bk, | ||
| logger: logger, | ||
| // TODO: fix the store once we add queries | ||
| Collections: collections.NewMap(sb, types.CollectionsPrefix, "collections", collections.StringKey, codec.CollValue[types.Collection](cdc)), | ||
| Supply: collections.NewMap(sb, types.SupplyPrefix, "supply", collections.StringKey, sdk.IntValue), | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.