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
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
9d751b4
in sync with @okwme/cosmos-nft
okwme Apr 15, 2019
b7c8c7f
remove tmp tx
okwme Apr 15, 2019
8d57122
structuring and minor changes
fedekunze Apr 15, 2019
29b170d
supply and client files
fedekunze Apr 15, 2019
53ddc52
adding cli client
okwme Apr 16, 2019
bf8864e
complete cli/tx and rest.go
okwme Apr 17, 2019
e018425
cleanup and restructuring
fedekunze Apr 19, 2019
4fc18b0
restructure rest folder
fedekunze Apr 22, 2019
2183f39
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into bi…
fedekunze Apr 28, 2019
a9aa360
minor updates on clients
fedekunze Apr 28, 2019
6018b16
update querier
fedekunze Apr 28, 2019
b438068
encoding for clients and other changes
fedekunze Apr 28, 2019
c904493
genesis, invariants, and keeper updates
fedekunze Apr 29, 2019
8ebfdc9
update types
fedekunze Apr 29, 2019
dcb7e04
make golangcibot happy
fedekunze Apr 29, 2019
65194cf
renamed and removed bank keeper
okwme May 2, 2019
6fe5e40
remove handlers for editmetadata, mint, burn, buy
okwme May 2, 2019
7f18f53
nft interface
fedekunze May 3, 2019
d782701
minor cleanup
fedekunze May 3, 2019
a3a5d27
sort collections and nfts
fedekunze May 3, 2019
0663ae2
balance and find
fedekunze May 3, 2019
c9db8a1
nft query and tx
fedekunze May 7, 2019
2b058a7
touch ups
okwme May 14, 2019
9c9bf23
uint in place of int
sabau May 15, 2019
eea3138
little fixes:
sabau May 15, 2019
8b76ccd
module generalization changes
fedekunze May 15, 2019
a7cb226
fixes
fedekunze May 15, 2019
d681e09
query with data
fedekunze May 15, 2019
29bcf13
minor updates and TODOs
fedekunze May 15, 2019
efbdfaf
fix CLI tx
fedekunze May 15, 2019
612c66e
golang bot fixes
fedekunze May 15, 2019
4fb5b32
handlers and txs done
fedekunze May 16, 2019
a48bf2f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into bi…
fedekunze May 16, 2019
300bb26
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into bi…
fedekunze May 16, 2019
e95299a
update module generalization
fedekunze May 16, 2019
ac0ec12
Added very basic tests which for some reason do not work
okwme May 20, 2019
cc3b825
fix test
sabau May 21, 2019
3c5252a
fixed test, now we should fix implementation, seems to fail
sabau May 21, 2019
71968ff
fix test, create new struct instead of changing the old one
sabau May 21, 2019
e84f147
fix handler with new logic
sabau May 21, 2019
872f614
let's make it compile
sabau May 21, 2019
e8dea9d
single failing test example, need to be fixed and extended
sabau May 21, 2019
11457a5
single failing test example, need to be fixed and extended
sabau May 22, 2019
c8d3da4
reverting work, still problems unmarshalling inside iterator from test
sabau May 22, 2019
2f46d0a
Setter in nft.go should return NFT instead of BaseNFT
sabau May 23, 2019
fa3d00c
remove TODOS
sabau May 23, 2019
0219084
comment out broken tests, we want at least a green mark here
sabau May 29, 2019
528384a
little fixes
sabau Jun 3, 2019
2f80a52
hopefully no conflict
okwme Jun 3, 2019
6b23fbd
Fixed marshall error
okwme Jun 3, 2019
08c07ae
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into bi…
fedekunze Jun 6, 2019
4efbaa8
minor changes for tests
tac0turtle Jun 6, 2019
789be16
Merge branch 'billy/nft' of https://github.com/cosmos/cosmos-sdk into…
tac0turtle Jun 6, 2019
0a6442d
change nft id to string, refactors
fedekunze Jun 6, 2019
edc4c92
messy pause
okwme Jun 7, 2019
430c581
slowly cleaning up beginning with keeper and keeper_tests
okwme Jun 7, 2019
541f254
Changes Balances to OWners add all necessary functions, updated Keepe…
okwme Jun 10, 2019
64431c4
pause dev to merge sdk master
okwme Jun 10, 2019
ea04c52
go.mod changes
okwme Jun 10, 2019
b916f06
Merge branch 'master' into billy/nft
okwme Jun 10, 2019
5f672ed
getting closer still need module.go
okwme Jun 10, 2019
02bf05b
builds!!!
okwme Jun 11, 2019
b970852
fix lint begin handler tests
okwme Jun 11, 2019
7b080a6
stableish
okwme Jun 11, 2019
a63a79a
re-order nft attributes, add back mint and burn msgs and handlers
okwme Jun 11, 2019
53a5cc0
add errors to minting the same NFT and burning an NFT that doesnt exist
okwme Jun 11, 2019
5e538b8
first querier test
okwme Jun 11, 2019
951fc8f
add simulations for nft msgs
fedekunze Jun 12, 2019
c55bdfe
Merge branch 'billy/nft' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Jun 12, 2019
1235ac4
handler tests check tags now (fixed a bug!)
okwme Jun 12, 2019
71801b6
update simulation
fedekunze Jun 12, 2019
44dc8a6
Merge branch 'billy/nft' of https://github.com/cosmos/cosmos-sdk into…
fedekunze Jun 12, 2019
1c5a238
generic handler
okwme Jun 12, 2019
23a6054
Merge branch 'billy/nft' of github.com:cosmos/cosmos-sdk into billy/nft
okwme Jun 12, 2019
c1d93a6
need to check if it compiles on another machine
okwme Jun 15, 2019
54866ee
fix weird interface error
okwme Jun 15, 2019
3129199
add back cli
okwme Jun 15, 2019
623f3b2
wtfff
okwme Jun 15, 2019
fda61b3
codec error fixed, logs removed. still returning empty arrays of IDs
okwme Jun 15, 2019
80e5bd2
Take empty input as yes answer
alessio Jun 16, 2019
9619b5c
Add pending log entry
alexanderbez Jun 16, 2019
830cf9b
Merge branch 'billy/nft' into billy/merge-alessio
okwme Jun 16, 2019
10a250b
merged in master
okwme Jun 16, 2019
dd8be62
marshall errors
okwme Jun 16, 2019
ef4377a
build commands
okwme Jun 16, 2019
8a35375
working!!!
okwme Jun 16, 2019
ed2e501
merge master
tac0turtle Jun 25, 2019
d1052fa
linting errors
tac0turtle Jun 25, 2019
5b246d4
remove unused func
tac0turtle Jun 25, 2019
eac7eab
pause
okwme Jun 25, 2019
840bc23
Merge branch 'billy/nft' of github.com:cosmos/cosmos-sdk into billy/nft
okwme Jun 25, 2019
5fb86c6
fix burn error
okwme Jun 25, 2019
d667021
fix burn error
okwme Jul 1, 2019
94c6285
merged with maser
okwme Jul 1, 2019
1f75cb2
tests for querier
okwme Jul 1, 2019
5325b8a
typo
okwme Jul 1, 2019
770f0ea
tests for NFT types
okwme Jul 2, 2019
0ce5886
module spec standard
fedekunze Jul 2, 2019
095b497
tests for Collection and Collections types
okwme Jul 2, 2019
7ba4cfa
Merge branch 'billy/nft' of github.com:cosmos/cosmos-sdk into billy/nft
okwme Jul 2, 2019
6a40091
merge w Fede
okwme Jul 2, 2019
a9b5fea
tests for Owner Type
okwme Jul 2, 2019
fba52ed
added genesis tests and beefed up keeper, querier, handler & types tests
okwme Jul 3, 2019
9236347
linting errors deadcode
okwme Jul 3, 2019
c9d7ccc
Merge branch 'master' into billy/nft
okwme Jul 3, 2019
39b134a
DONT COVER test_common.go
okwme Jul 3, 2019
b60c6be
add msg type tests
okwme Jul 3, 2019
a718146
merge master update msg types
okwme Jul 3, 2019
785019a
Update x/nft/internal/keeper/key.go
okwme Jul 8, 2019
e4c0afa
Update x/nft/genesis.go
okwme Jul 8, 2019
1edff5a
Update x/nft/client/cli/query.go
okwme Jul 8, 2019
907be89
Apply suggestions from code review
fedekunze Jul 11, 2019
609f220
cleanup and address comments
fedekunze Jul 16, 2019
e859bc0
typo
fedekunze Jul 16, 2019
4092bc7
cleanup events
fedekunze Jul 16, 2019
b5fd467
split events
fedekunze Jul 16, 2019
97240dd
more cleanup
fedekunze Jul 18, 2019
3d1521f
remove restrictions from default handlers
okwme Jul 21, 2019
547613b
not sure where these go mod changes came from
okwme Jul 21, 2019
66ffc12
performance misspelling
okwme Jul 21, 2019
1918f54
sim generated changes
okwme Jul 23, 2019
a3937ef
merged master
okwme Jul 23, 2019
ebc912c
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into bi…
fedekunze Jul 23, 2019
3c1c0e9
make format
fedekunze Jul 23, 2019
df5e900
add mint and burn sims
fedekunze Jul 23, 2019
887324d
move NFT interface to nft/exported
fedekunze Jul 23, 2019
8e71f2d
make format
fedekunze Jul 23, 2019
72aecc5
NFT spec
fedekunze Jul 23, 2019
6f579e0
Updates
fedekunze Jul 23, 2019
91fede0
more updates
fedekunze Jul 23, 2019
b602b6d
update specs readme
fedekunze Jul 23, 2019
b518f2a
fix sims
fedekunze Jul 23, 2019
ef93ff5
rest additions
okwme Jul 29, 2019
bfea0a7
Merge branch 'master' into billy/nft
okwme Jul 29, 2019
95b037f
rest additions
okwme Jul 29, 2019
dae51c1
fix invariant
okwme Jul 29, 2019
47c9403
minimal nft without name, description or image
okwme Jul 29, 2019
61b3f1d
sim
okwme Jul 29, 2019
6985b53
fix sim
okwme Jul 29, 2019
caf41a2
fix sim
okwme Jul 29, 2019
6a521d8
fix Update methods
okwme Jul 29, 2019
99edbb4
merged nft
okwme Jul 29, 2019
494c36a
nothing
okwme Jul 29, 2019
a05d45e
Merge branch 'master' into billy/nft
sabau Jul 30, 2019
6a3436d
simplify update and remove
sabau Jul 30, 2019
241b6db
remove test on memory location
sabau Jul 30, 2019
7c050b0
TEST to get logs, need to be removed
sabau Jul 30, 2019
f047a59
fix simulator editMetadata Msg type
okwme Jul 30, 2019
ff8807f
owner not found start with empty collection
sabau Jul 30, 2019
e46495f
artifacts on errors in case of failure, else, no artifacts
sabau Jul 30, 2019
6611089
add more invariant checks to handler_tests
okwme Jul 30, 2019
8ef485f
Merge branch 'billy/nft' of github.com:cosmos/cosmos-sdk into billy/nft
okwme Jul 30, 2019
1d62300
never forget to overwrite
okwme Jul 30, 2019
96acd6e
merge min-nft, metadata removed except tokenURI
okwme Jul 30, 2019
f99777f
Merge branch 'billy/nft' into billy-fedekunze/4735-nft-spec
okwme Jul 30, 2019
5366c07
merge and update spec
okwme Jul 30, 2019
2e1fbb6
Merge pull request #4766 from cosmos/billy-fedekunze/4735-nft-spec
okwme Jul 30, 2019
0d99d6f
Merge branch 'master' into billy/nft
okwme Jul 30, 2019
85104ca
colins feedback
okwme Jul 31, 2019
b00a362
Merge branch 'billy/nft' of github.com:cosmos/cosmos-sdk into billy/nft
okwme Jul 31, 2019
da87464
code coverage test
okwme Jul 31, 2019
322a40d
code coverage test
okwme Jul 31, 2019
b7834cc
code coverage test
okwme Jul 31, 2019
c5c33d5
spelling
okwme Jul 31, 2019
733de25
clean up client
okwme Jul 31, 2019
c1fa44e
testing code coverage
okwme Jul 31, 2019
6b5e0ed
testing code coverage
okwme Jul 31, 2019
a859dfd
testing code coverage
okwme Jul 31, 2019
575d991
testing code coverage
okwme Jul 31, 2019
c613491
testing code coverage
okwme Jul 31, 2019
e0e68cd
Update docs/spec/nft/README.md
fedekunze Aug 2, 2019
a0c3799
Apply suggestions from code review
fedekunze Aug 2, 2019
7f79b92
merge master
fedekunze Aug 2, 2019
5e47cc2
minor changes
fedekunze Aug 2, 2019
caec9f3
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into bi…
fedekunze Aug 11, 2019
81dd140
merge master; add sim decoder
fedekunze Aug 24, 2019
151f309
integration tests and fixes
fedekunze Aug 24, 2019
e44c1db
minor golangCI fixes
fedekunze Aug 24, 2019
ccf6a52
Merge branch 'master' into billy/nft
rigelrozanski Aug 26, 2019
832de38
Update simapp/app.go
rigelrozanski Aug 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions x/nfts/client/cli/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cli

import (
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/x/nfts"
)

const (
flagName = "name"
flagDescription = "description"
flagImage = "image"
flagTokenURI = "tokenURI"
)

func parseEditMetadataFlags() (nfts.MsgEditNFTMetadata, error) {
msg := nfts.MsgEditNFTMetadata{}

name := viper.GetString(flagName)
if name != "" {
msg.EditName = true
msg.Name = name
}

description := viper.GetString(flagDescription)
if description != "" {
msg.EditDescription = true
msg.Description = description
}

image := viper.GetString(flagImage)
if image != "" {
msg.EditImage = true
msg.Image = image
}

tokenURI := viper.GetString(flagTokenURI)
if tokenURI != "" {
msg.EditTokenURI = true
msg.TokenURI = tokenURI
}

return msg, nil
}
109 changes: 109 additions & 0 deletions x/nfts/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package cli

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/nfts"
"github.com/spf13/cobra"
)

// GetCmdQueryCollectionSupply queries the supply of a nft collection
func GetCmdQueryCollectionSupply(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "supply [denom]",
Short: "total supply of a collection of NFTs",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
denom := args[0]

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/supply/%s", queryRoute, denom), nil)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
fmt.Printf("could not query supply of %s\n", denom)
fmt.Print(err.Error())
return nil
}

// var out nfts.NFT
// cdc.MustUnmarshalJSON(res, &out)
// return cliCtx.PrintOutput(out)
},
}
}

// GetCmdQueryBalance queries all the NFTs owned by an account
func GetCmdQueryBalance(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "balance [accountAddress] [denom]",
Short: "get the NFTs owned by an account address",
Long: "get the NFTs owned by an account address", // TODO: finish this
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
account := args[0]

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/balance/%s", queryRoute, account), nil)
if err != nil {
fmt.Printf("could not query %s balance of account %s \n", denom, account)
fmt.Print(err.Error())
return nil
}

var out nfts.QueryResBalance
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}

// GetCmdQueryNFTs queries all the NFTs from a collection
func GetCmdQueryNFTs(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "collection [denom]",
Short: "get all the NFTs from a given collection",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
denom := args[0]
tokenID := args[1]

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/collection/%s", queryRoute, denom, tokenID), nil)
if err != nil {
fmt.Printf("could not query owner of %s #%s\n", denom, tokenID)
fmt.Print(err.Error())
return nil
}

var out nfts.QueryResOwnerOf
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}

// GetCmdQueryNFT queries a single NFTs from a collection
func GetCmdQueryNFT(queryRoute string, cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "nft [denom] [ID]",
Short: "query a single NFT from a collection",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)
denom := args[0]
ID := args[1]
fedekunze marked this conversation as resolved.
Show resolved Hide resolved

res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/nft/%s/%s", queryRoute, denom, tokenID), nil)
if err != nil {
fmt.Printf("could not query owner of %s #%s\n", denom, tokenID)
fmt.Print(err.Error())
return nil
}

var out nfts.QueryResOwnerOf
cdc.MustUnmarshalJSON(res, &out)
return cliCtx.PrintOutput(out)
},
}
}
184 changes: 184 additions & 0 deletions x/nfts/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package cli

import (
"strconv"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
"github.com/cosmos/cosmos-sdk/x/nfts"
"github.com/spf13/cobra"
)

// GetCmdTransferNFT is the CLI command for sending a TransferNFT transaction
func GetCmdTransferNFT(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "transfer [sender] [recipient] [denom] [tokenID]",
Short: "transfer a token of some denom with some tokenID to some recipient",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))

// TODO: Does this need to be true? What does it mean to have an account that doesn't exist?
// If it just means having a balance in some token then no, an account doens't need to "exist".
if err := cliCtx.EnsureAccountExists(); err != nil {
return err
}

tokenID, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
}

msg := nfts.NewMsgTransferNFT(cliCtx.GetFromAddress(), sdk.AccAddress(args[0]), nfts.Denom(args[1]), nfts.TokenID(tokenID))
err = msg.ValidateBasic()
if err != nil {
return err
}

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
},
}
}

// GetCmdEditNFTMetadata is the CLI command for a EditNFTMetadata transaction
func GetCmdEditNFTMetadata(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "edit-metadata [denom] [tokenID]",
Short: "transfer a token of some denom with some tokenID to some recipient",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {

msg, err := parseEditMetadataFlags()
if err != nil {
return err
}

cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))

tokenID, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

msg = nfts.NewMsgEditNFTMetadata(cliCtx.GetFromAddress(),
nfts.Denom(args[0]),
nfts.TokenID(tokenID),
msg.EditName,
msg.EditDescription,
msg.EditImage,
msg.EditTokenURI,
msg.Name,
msg.Description,
msg.Image,
msg.TokenURI,
)
err = msg.ValidateBasic()
if err != nil {
return err
}

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
},
}

cmd.Flags().String(flagName, "", "Name/title of nft")
cmd.Flags().String(flagDescription, "", "Description of nft")
cmd.Flags().String(flagImage, "", "Image uri of nft")
cmd.Flags().String(flagTokenURI, "", "URI for supplemental off-chain metadata (should return a JSON object)")

return cmd
}

// GetCmdMintNFT is the CLI command for a MintNFT transaction
func GetCmdMintNFT(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "mint [recipient] [denom] [tokenID]",
Short: "mints a token of some denom with some tokenID to some recipient",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {

metadata, err := parseEditMetadataFlags()
if err != nil {
return err
}

cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)
txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))

tokenID, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
}

msg := nfts.NewMsgMintNFT(cliCtx.GetFromAddress(),
sdk.AccAddress(args[0]),
nfts.TokenID(tokenID),
nfts.Denom(args[1]),
metadata.Name,
metadata.Description,
metadata.Image,
metadata.TokenURI,
)
err = msg.ValidateBasic()
if err != nil {
return err
}

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
},
}

cmd.Flags().String(flagName, "", "Name/title of nft")
cmd.Flags().String(flagDescription, "", "Description of nft")
cmd.Flags().String(flagImage, "", "Image uri of nft")
cmd.Flags().String(flagTokenURI, "", "URI for supplemental off-chain metadata (should return a JSON object)")

return cmd
}

// GetCmdBurnNFT is the CLI command for sending a BurnNFT transaction
func GetCmdBurnNFT(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "burn [denom] [tokenID]",
Short: "burn a token of some denom with some tokenID",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc).WithAccountDecoder(cdc)

txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))

// TODO: Does this need to be true? What does it mean to have an account that doesn't exist?
// If it just means having a balance in some token then no, an account doens't need to "exist".
if err := cliCtx.EnsureAccountExists(); err != nil {
return err
}

tokenID, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

msg := nfts.NewMsgBurnNFT(cliCtx.GetFromAddress(), nfts.TokenID(tokenID), nfts.Denom(args[1]))
err = msg.ValidateBasic()
if err != nil {
return err
}

cliCtx.PrintResponse = true

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}, false)
},
}
}
54 changes: 54 additions & 0 deletions x/nfts/client/module_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package client

import (
"github.com/cosmos/cosmos-sdk/client"
nftcmd "github.com/cosmos/cosmos-sdk/x/nfts/client/cli"
"github.com/spf13/cobra"

amino "github.com/tendermint/go-amino"
)

// ModuleClient exports all client functionality from this module
type ModuleClient struct {
storeKey string
cdc *amino.Codec
}

// NewModuleClient creates a new module client
func NewModuleClient(storeKey string, cdc *amino.Codec) ModuleClient {
return ModuleClient{storeKey, cdc}
}

// GetQueryCmd returns the cli query commands for this module
func (mc ModuleClient) GetQueryCmd() *cobra.Command {
// Group nameservice queries under a subcommand
nftQueryCmd := &cobra.Command{
Use: "nft",
Short: "Querying commands for the NFT module",
}

nftQueryCmd.AddCommand(client.GetCommands(
nftcmd.GetCmdQueryBalanceOf(mc.storeKey, mc.cdc),
nftcmd.GetCmdQueryOwnerOf(mc.storeKey, mc.cdc),
nftcmd.GetCmdQueryMetadata(mc.storeKey, mc.cdc),
)...)

return nftQueryCmd
}

// GetTxCmd returns the transaction commands for this module
func (mc ModuleClient) GetTxCmd() *cobra.Command {
nftTxCmd := &cobra.Command{
Use: "nft",
Short: "Non-FungibleToken transactions subcommands",
}

nftTxCmd.AddCommand(client.PostCommands(
nftcmd.GetCmdTransferNFT(mc.cdc),
nftcmd.GetCmdEditNFTMetadata(mc.cdc),
nftcmd.GetCmdMintNFT(mc.cdc),
nftcmd.GetCmdBurnNFT(mc.cdc),
)...)

return nftTxCmd
}
Loading