* 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: #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>
250 lines
6.3 KiB
Go
250 lines
6.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
"github.com/cosmos/cosmos-sdk/x/nft/exported"
|
|
"github.com/cosmos/cosmos-sdk/x/nft/internal/types"
|
|
)
|
|
|
|
// GetQueryCmd returns the cli query commands for this module
|
|
func GetQueryCmd(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
nftQueryCmd := &cobra.Command{
|
|
Use: types.ModuleName,
|
|
Short: "Querying commands for the NFT module",
|
|
}
|
|
|
|
nftQueryCmd.AddCommand(client.GetCommands(
|
|
GetCmdQueryCollectionSupply(queryRoute, cdc),
|
|
GetCmdQueryOwner(queryRoute, cdc),
|
|
GetCmdQueryCollection(queryRoute, cdc),
|
|
GetCmdQueryDenoms(queryRoute, cdc),
|
|
GetCmdQueryNFT(queryRoute, cdc),
|
|
)...)
|
|
|
|
return nftQueryCmd
|
|
}
|
|
|
|
// 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",
|
|
Long: strings.TrimSpace(
|
|
fmt.Sprintf(`Get the total count of NFTs that match a certain denomination.
|
|
|
|
Example:
|
|
$ %s query %s supply crypto-kitties
|
|
`, version.ClientName, types.ModuleName,
|
|
),
|
|
),
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
denom := args[0]
|
|
|
|
params := types.NewQueryCollectionParams(denom)
|
|
bz, err := cdc.MarshalJSON(params)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/supply/%s", queryRoute, denom), bz)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var out exported.NFT
|
|
err = cdc.UnmarshalJSON(res, &out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return cliCtx.PrintOutput(out)
|
|
},
|
|
}
|
|
}
|
|
|
|
// GetCmdQueryOwner queries all the NFTs owned by an account
|
|
func GetCmdQueryOwner(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "owner [accountAddress] [denom]",
|
|
Short: "get the NFTs owned by an account address",
|
|
Long: strings.TrimSpace(
|
|
fmt.Sprintf(`Get the NFTs owned by an account address optionally filtered by the denom of the NFTs.
|
|
|
|
Example:
|
|
$ %s query %s owner cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p
|
|
$ %s query %s owner cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cripto-kitties
|
|
`, version.ClientName, types.ModuleName, version.ClientName, types.ModuleName,
|
|
),
|
|
),
|
|
Args: cobra.RangeArgs(1, 2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
address, err := sdk.AccAddressFromBech32(args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
denom := ""
|
|
if len(args) == 2 {
|
|
denom = args[1]
|
|
}
|
|
|
|
params := types.NewQueryBalanceParams(address, denom)
|
|
bz, err := cdc.MarshalJSON(params)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var res []byte
|
|
if denom == "" {
|
|
res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/owner", queryRoute), bz)
|
|
} else {
|
|
res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/ownerByDenom", queryRoute), bz)
|
|
}
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var out types.Owner
|
|
err = cdc.UnmarshalJSON(res, &out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return cliCtx.PrintOutput(out)
|
|
},
|
|
}
|
|
}
|
|
|
|
// GetCmdQueryCollection queries all the NFTs from a collection
|
|
func GetCmdQueryCollection(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "collection [denom]",
|
|
Short: "get all the NFTs from a given collection",
|
|
Long: strings.TrimSpace(
|
|
fmt.Sprintf(`Get a list of all NFTs from a given collection.
|
|
|
|
Example:
|
|
$ %s query %s collection cripto-kitties
|
|
`, version.ClientName, types.ModuleName,
|
|
),
|
|
),
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
denom := args[0]
|
|
|
|
params := types.NewQueryCollectionParams(denom)
|
|
bz, err := cdc.MarshalJSON(params)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/collection", queryRoute), bz)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var out types.Collection
|
|
err = cdc.UnmarshalJSON(res, &out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return cliCtx.PrintOutput(out)
|
|
},
|
|
}
|
|
}
|
|
|
|
type stringArray []string
|
|
|
|
func (s stringArray) String() string { return strings.Join(s[:], ",") }
|
|
|
|
// GetCmdQueryDenoms queries all denoms
|
|
func GetCmdQueryDenoms(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "denoms",
|
|
Short: "queries all denominations of all collections of NFTs",
|
|
Long: strings.TrimSpace(
|
|
fmt.Sprintf(`Gets all denominations of all the available collections of NFTs that
|
|
are stored on the chain.
|
|
|
|
Example:
|
|
$ %s query %s denoms
|
|
`, version.ClientName, types.ModuleName,
|
|
),
|
|
),
|
|
Args: cobra.ExactArgs(0),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
|
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/denoms", queryRoute), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var out stringArray
|
|
err = cdc.UnmarshalJSON(res, &out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
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: "token [denom] [ID]",
|
|
Short: "query a single NFT from a collection",
|
|
Long: strings.TrimSpace(
|
|
fmt.Sprintf(`Get an NFT from a collection that has the given ID (SHA-256 hex hash).
|
|
|
|
Example:
|
|
$ %s query %s token cripto-kitties d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa
|
|
`, version.ClientName, types.ModuleName,
|
|
),
|
|
),
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
|
denom := args[0]
|
|
id := args[1]
|
|
|
|
params := types.NewQueryNFTParams(denom, id)
|
|
bz, err := cdc.MarshalJSON(params)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/nft", queryRoute), bz)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var out exported.NFT
|
|
err = cdc.UnmarshalJSON(res, &out)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return cliCtx.PrintOutput(out)
|
|
},
|
|
}
|
|
}
|