Documentation
¶
Index ¶
- func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)
- func SupplyInvariant(k Keeper) sdk.Invariant
- type ConvertedNFTChecker
- type ExportIssue
- type ExportIssueKind
- type Keeper
- func (k Keeper) Authorize(ctx sdk.Context, denomID, tokenID string, owner sdk.AccAddress) error
- func (k Keeper) BurnNFT(goCtx context.Context, msg *types.MsgBurnNFT) (*types.MsgBurnNFTResponse, error)
- func (k Keeper) Collection(c context.Context, request *types.QueryCollectionRequest) (*types.QueryCollectionResponse, error)
- func (k Keeper) Denom(c context.Context, request *types.QueryDenomRequest) (*types.QueryDenomResponse, error)
- func (k Keeper) Denoms(c context.Context, req *types.QueryDenomsRequest) (*types.QueryDenomsResponse, error)
- func (k Keeper) EditNFT(goCtx context.Context, msg *types.MsgEditNFT) (*types.MsgEditNFTResponse, error)
- func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState
- func (k Keeper) ExportIssues(ctx sdk.Context) []ExportIssue
- func (k Keeper) ExportIssuesWithReport(ctx sdk.Context) []ExportIssue
- func (k Keeper) GetCollection(ctx sdk.Context, denomID string) (types.Collection, error)
- func (k Keeper) GetCollections(ctx sdk.Context) []types.Collection
- func (k Keeper) GetCollectionsWithReport(ctx sdk.Context) ([]types.Collection, []ExportIssue)
- func (k Keeper) GetDenomInfo(ctx sdk.Context, denomID string) (*types.Denom, error)
- func (k Keeper) GetNFT(ctx sdk.Context, denomID, tokenID string) (nft exported.NFT, err error)
- func (k Keeper) GetNFTs(ctx sdk.Context, denom string) (nfts []exported.NFT, err error)
- func (k Keeper) GetOwner(ctx sdk.Context, classID, nftID string) sdk.AccAddress
- func (k Keeper) GetTotalSupply(ctx sdk.Context, denomID string) uint64
- func (k Keeper) GetTotalSupplyOfOwner(ctx sdk.Context, id string, owner sdk.AccAddress) (supply uint64)
- func (k Keeper) HasDenom(ctx sdk.Context, denomID string) bool
- func (k Keeper) HasNFT(ctx sdk.Context, denomID, tokenID string) bool
- func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState)
- func (k Keeper) IsConvertedNFT(ctx sdk.Context, classID, nftID string) bool
- func (k Keeper) IssueDenom(goCtx context.Context, msg *types.MsgIssueDenom) (*types.MsgIssueDenomResponse, error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) MintNFT(goCtx context.Context, msg *types.MsgMintNFT) (*types.MsgMintNFTResponse, error)
- func (k Keeper) NFT(c context.Context, request *types.QueryNFTRequest) (*types.QueryNFTResponse, error)
- func (k Keeper) NFTkeeper() nftkeeper.Keeper
- func (k Keeper) NFTsOfOwner(c context.Context, request *types.QueryNFTsOfOwnerRequest) (*types.QueryNFTsOfOwnerResponse, error)
- func (k Keeper) RemoveNFT(ctx sdk.Context, denomID, tokenID string, owner sdk.AccAddress) error
- func (k Keeper) SaveCollection(ctx sdk.Context, collection types.Collection) error
- func (k Keeper) SaveDenom(ctx sdk.Context, id, name, schema, symbol string, creator sdk.AccAddress, ...) error
- func (k Keeper) SaveNFT(ctx sdk.Context, ...) error
- func (k *Keeper) SetConvertedNFTChecker(checker ConvertedNFTChecker)
- func (k Keeper) Supply(c context.Context, request *types.QuerySupplyRequest) (*types.QuerySupplyResponse, error)
- func (k Keeper) TransferDenom(goCtx context.Context, msg *types.MsgTransferDenom) (*types.MsgTransferDenomResponse, error)
- func (k Keeper) TransferDenomOwner(ctx sdk.Context, denomID string, srcOwner, dstOwner sdk.AccAddress) error
- func (k Keeper) TransferNFT(goCtx context.Context, msg *types.MsgTransferNFT) (*types.MsgTransferNFTResponse, error)
- func (k Keeper) TransferOwnership(ctx sdk.Context, ...) error
- func (k Keeper) UpdateNFT(ctx sdk.Context, ...) error
- type Migrator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterInvariants ¶
func RegisterInvariants(ir sdk.InvariantRegistry, k Keeper)
RegisterInvariants registers all supply invariants
NOTHING CALLS THIS AT RUNTIME. It satisfies module.HasInvariants (x/collection/module/module.go), but the only thing that would invoke it -- module.Manager.RegisterInvariants -- is a deliberate no-op in cosmos-sdk v0.53.8 (types/module/module.go:454-457). app/app.go's call therefore registers zero routes and every crisis entry point asserts an empty set; app/app.go lists the sites.
The supply check is observed on the export path instead (GetCollectionsWithReport -> export log). Wiring it into x/crisis is a decision, not a cleanup: see app/invariants_wiring_test.go.
func SupplyInvariant ¶
SupplyInvariant checks that each class' stored total-supply counter matches the number of NFTs it holds.
It reports the ExportIssueSupplyMismatch records produced by the export walk rather than re-deriving the comparison, so the invariant and the export diagnostic can never disagree about what a broken supply is. That walk is the module's only costly operation, so the invariant is not run periodically.
Types ¶
type ConvertedNFTChecker ¶ added in v0.5.0
type ConvertedNFTChecker interface {
// IsConvertedNFT reports whether (classID, nftID) has a contract-side
// counterpart, i.e. whether burning the native NFT would strand a token
// that the conversion left escrowed in a module account.
IsConvertedNFT(ctx sdk.Context, classID, nftID string) bool
}
ConvertedNFTChecker reports whether a native NFT is paired with a token held by an ERC721 or CW721 contract.
It is an interface supplied by the app at wiring time: x/collection owns the native half of a conversion but not the contract-side bookkeeping, and it must not import x/erc721 or x/cw721 -- both depend on collection, so importing back would invert the dependency.
type ExportIssue ¶ added in v0.5.0
type ExportIssue struct {
ClassID string
Kind ExportIssueKind
Detail string
}
ExportIssue is one recoverable problem encountered during genesis export. It is surfaced to the caller so a degradation is reported explicitly instead of hiding behind a successful-looking export.
func (ExportIssue) String ¶ added in v0.5.0
func (i ExportIssue) String() string
type ExportIssueKind ¶ added in v0.5.0
type ExportIssueKind string
ExportIssueKind classifies a recoverable problem found while exporting module state.
const ( // ExportIssueNFTListFailed means the NFT list of a class could not be read, // so neither the class nor its NFTs could be exported. ExportIssueNFTListFailed ExportIssueKind = "nft_list_failed" // ExportIssueClassMetadata means a class' metadata blob could not be // decoded: only its base class fields could be exported. ExportIssueClassMetadata ExportIssueKind = "class_metadata_undecodable" // ExportIssueClassMetadataMissing means a class carries no metadata blob at // all, so its collection-level fields (creator, schema, data, restrictions) // are absent on chain. That is the shape nft-transfer leaves on ICS-721 // voucher classes (it calls the underlying nft keeper directly), and of // classes predating the metadata wrapper. Nothing the chain held is dropped, // but a round-tripped genesis carries those classes with empty metadata. ExportIssueClassMetadataMissing ExportIssueKind = "class_metadata_missing" // ExportIssueSupplyMismatch means the class' stored total-supply counter // disagrees with the number of NFTs actually stored under it. The counter is // maintained by the upstream nft keeper's mint/burn, and every write path in // this repo goes through them, so a mismatch means a historical bypass // diverged it -- or decrTotalSupply wrapped a zero counter to 2^64-1 -- and // every supply query for the class is now wrong. It is the one degradation a // round-tripped genesis does NOT preserve: the counter is not in // GenesisState and is recomputed on import, so the mismatch would quietly // vanish. Reported so it cannot vanish unobserved. ExportIssueSupplyMismatch ExportIssueKind = "supply_mismatch" // ExportIssueClassMetadataTooLarge means the class' schema and/or data blob // exceeds the denom metadata bounds that ValidateGenesis enforces, so the // export cannot carry it verbatim: an exported record that validate rejects // is a genesis no node can start from. The export truncates the offending // field to the bound (the prefix is kept) and reports the original and the // emitted byte counts here, so the loss is loud in // <home>/export-issues.json instead of silent. // // A class can only reach this state by a write path that bypasses // SaveDenom -- in practice an ICS-721 voucher class written before the // receive-side bound existed (see ClassBuilder.Build). The bound is applied // on receive now, so this kind should only ever fire on pre-existing state. ExportIssueClassMetadataTooLarge ExportIssueKind = "class_metadata_too_large" )
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine
func NewKeeper ¶
func NewKeeper(cdc codec.Codec, storeService store.KVStoreService, ak nft.AccountKeeper, bk nft.BankKeeper, ) Keeper
NewKeeper creates a new instance of the NFT Keeper
func (Keeper) Authorize ¶
Authorize checks if the sender is the owner of the given NFT Return the NFT if true, an error otherwise
func (Keeper) BurnNFT ¶
func (k Keeper) BurnNFT(goCtx context.Context, msg *types.MsgBurnNFT) (*types.MsgBurnNFTResponse, error)
func (Keeper) Collection ¶
func (k Keeper) Collection(c context.Context, request *types.QueryCollectionRequest) (*types.QueryCollectionResponse, error)
Collection queries the NFTs of the specified denom
func (Keeper) Denom ¶
func (k Keeper) Denom(c context.Context, request *types.QueryDenomRequest) (*types.QueryDenomResponse, error)
Denom queries the definition of a given denom
func (Keeper) Denoms ¶
func (k Keeper) Denoms(c context.Context, req *types.QueryDenomsRequest) (*types.QueryDenomsResponse, error)
Denoms queries all the denoms
func (Keeper) EditNFT ¶
func (k Keeper) EditNFT(goCtx context.Context, msg *types.MsgEditNFT) (*types.MsgEditNFTResponse, error)
func (Keeper) ExportGenesis ¶ added in v0.2.5
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState
ExportGenesis returns a GenesisState for a given context and keeper.
Degradations reported by GetCollectionsWithReport are logged at Error level and summarized: the export still succeeds (no class or NFT is dropped), but an operator must be able to see that some metadata fields were lost.
The app-level report (<home>/export-issues.json) is built from ExportIssuesWithReport, which re-runs this exact walk, so the sidecar and the log below now carry the SAME set of degradations — including the two kinds that need the NFT list (nft_list_failed, supply_mismatch). The cheap class-only ExportIssues scan no longer feeds the sidecar; see its comment for why the split exists and ExportIssuesWithReport for the cost of closing it.
func (Keeper) ExportIssues ¶ added in v0.5.0
func (k Keeper) ExportIssues(ctx sdk.Context) []ExportIssue
ExportIssues scans for the class-level degradations described by classMetadataIssue, without building the collection list.
It is the CHEAP scan for callers that must not walk every NFT: it reads only the class records. The app-level sidecar no longer uses it (that report needs the complete set and calls ExportIssuesWithReport), but it is what the round-trip tests assert on.
Two kinds are NOT visible here, because observing them needs the NFT list that only the export walk builds -- ExportIssueNFTListFailed and ExportIssueSupplyMismatch -- and are reported by GetCollectionsWithReport instead. Counting NFTs here would defeat the split and walk every NFT twice on a disaster-recovery path.
func (Keeper) ExportIssuesWithReport ¶ added in v0.5.0
func (k Keeper) ExportIssuesWithReport(ctx sdk.Context) []ExportIssue
ExportIssuesWithReport returns the FULL set of degradations an export of the collection module can report, including the two kinds ExportIssues cannot see (ExportIssueNFTListFailed, ExportIssueSupplyMismatch) because observing them needs the per-class NFT list.
It is what the app-level sidecar (<home>/export-issues.json) reads, so the durable report and the export walk cannot disagree: both are GetCollectionsWithReport, the only place the supply and NFT-list checks run. This closes the D-G1 gap, where supply_mismatch -- the one check in the repo that can detect a diverged counter -- was logged but never persisted, and so vanished with the process.
COST: this re-runs the full per-class NFT walk that ExportGenesis already did. Accepted deliberately: it only happens on an operator-initiated export (disaster recovery / chain restart), never in a consensus handler.
The alternative -- stash the issue list on the keeper for the app to read back -- would avoid the second walk but add hidden mutable state to a keeper copied by value into x/erc721, x/cw721 and x/internft (see the convertedNFTs field comment in keeper.go), and make the report depend on whether ExportGenesis had run. A pure re-read keeps the keeper stateless.
func (Keeper) GetCollection ¶
GetCollection returns the collection by the specified denom ID
func (Keeper) GetCollections ¶
func (k Keeper) GetCollections(ctx sdk.Context) []types.Collection
GetCollections returns all collections, logging each degradation at Error level; the machine-readable list is GetCollectionsWithReport.
A class with undecodable metadata keeps its base fields -- never dropped (skipping it used to delete the class and all its NFTs from the genesis while the export still reported success).
No error return, deliberately: the iteration cannot fail as a whole (every degradation is per class, already an ExportIssue), and the error this used to return was never non-nil, leaving a branch in SupplyInvariant unreachable.
func (Keeper) GetCollectionsWithReport ¶ added in v0.5.0
func (k Keeper) GetCollectionsWithReport(ctx sdk.Context) ([]types.Collection, []ExportIssue)
GetCollectionsWithReport is GetCollections plus the explicit list of degradations that happened during the iteration.
func (Keeper) GetDenomInfo ¶
GetDenomInfo return the denom information
A legacy / migrated class may carry nil Data; return zero-value metadata instead of an error so callers like ExportGenesis and the query endpoints never abort on a single corrupt record.
func (Keeper) GetNFTs ¶
GetNFTs returns all NFTs by the specified denom ID
An NFT with corrupt Data is logged and downgraded to empty metadata instead of aborting the whole query (matches GetCollections / GetDenomInfo).
func (Keeper) GetOwner ¶ added in v0.5.0
GetOwner returns the owner of the given NFT, delegating to the underlying x/nft keeper.
Exposed so dependent modules (x/erc721) can query ownership through the collection keeper instead of reaching into NFTkeeper() and coupling to the underlying x/nft keeper type.
func (Keeper) GetTotalSupply ¶
GetTotalSupply returns the number of NFTs by the specified denom ID
func (Keeper) GetTotalSupplyOfOwner ¶
func (k Keeper) GetTotalSupplyOfOwner(ctx sdk.Context, id string, owner sdk.AccAddress) (supply uint64)
GetTotalSupplyOfOwner returns how many NFTs of `id` the owner holds.
func (Keeper) InitGenesis ¶ added in v0.2.5
func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState)
InitGenesis stores the NFT genesis.
func (Keeper) IsConvertedNFT ¶ added in v0.5.0
IsConvertedNFT reports whether the NFT is bound to a contract token, consulting the wiring-time checker. A nil slot or an unwired checker (a module-only setup with no contract side, such as the collection module's own unit tests) reports false, which preserves the unguarded behavior those callers expect.
func (Keeper) IssueDenom ¶
func (k Keeper) IssueDenom(goCtx context.Context, msg *types.MsgIssueDenom) (*types.MsgIssueDenomResponse, error)
IssueDenom issue a new denom.
func (Keeper) MintNFT ¶
func (k Keeper) MintNFT(goCtx context.Context, msg *types.MsgMintNFT) (*types.MsgMintNFTResponse, error)
func (Keeper) NFT ¶
func (k Keeper) NFT(c context.Context, request *types.QueryNFTRequest) (*types.QueryNFTResponse, error)
NFT queries the NFT for the given denom and token ID
func (Keeper) NFTsOfOwner ¶
func (k Keeper) NFTsOfOwner(c context.Context, request *types.QueryNFTsOfOwnerRequest) (*types.QueryNFTsOfOwnerResponse, error)
NFTsOfOwner queries the NFTs of the specified owner
func (Keeper) RemoveNFT ¶ added in v0.2.5
RemoveNFT deletes a specified NFT.
A token paired with an ERC721/CW721 contract token is refused: the conversion escrowed the contract-side half in a module account, and only this module knows the binding, so burning the native half would delete the last on-chain record of the escrowed asset. The state is what x/erc721 itself describes as "undiscoverable and unrecoverable". The user must un-wrap first.
func (Keeper) SaveCollection ¶ added in v0.2.5
SaveCollection saves every NFT in the collection, returning the first error (an NFT that already exists is one: upstream Mint rejects duplicates).
func (Keeper) SaveDenom ¶ added in v0.2.5
func (k Keeper) SaveDenom(ctx sdk.Context, id, name, schema, symbol string, creator sdk.AccAddress, mintRestricted, updateRestricted bool, description, uri, uriHash, data string, ) error
SaveDenom issues a denom according to the given params
func (Keeper) SaveNFT ¶ added in v0.2.5
func (k Keeper) SaveNFT(ctx sdk.Context, denomID, tokenID, tokenNm, tokenURI, tokenUriHash, tokenData string, receiver sdk.AccAddress, ) error
SaveNFT mints an NFT and manages the NFT's existence within Collections and Owners.
Empty inputs are rejected up front: they would write a corrupt state entry (empty key / zero address) and break downstream iteration.
func (*Keeper) SetConvertedNFTChecker ¶ added in v0.5.0
func (k *Keeper) SetConvertedNFTChecker(checker ConvertedNFTChecker)
SetConvertedNFTChecker wires the cross-module burn guard.
Called by app/keepers/keepers.go once x/erc721 and x/cw721 exist: they are constructed *from* this keeper (NewKeeper takes it by value), so the dependency cannot be a constructor parameter. TestConvertedNFTCheckerIsWired fails if this wiring is ever dropped, because an unwired checker turns the burn guard back into the silent asset loss it exists to prevent.
The write lands in the shared slot, so it is visible through every copy taken before the call -- which reaches the refund path in x/erc721 (whose nftKeeper field is such a copy) and the ICS-721 path in x/internft.
func (Keeper) Supply ¶
func (k Keeper) Supply(c context.Context, request *types.QuerySupplyRequest) (*types.QuerySupplyResponse, error)
Supply queries the total supply of a given denom or owner
func (Keeper) TransferDenom ¶ added in v0.2.5
func (k Keeper) TransferDenom(goCtx context.Context, msg *types.MsgTransferDenom) (*types.MsgTransferDenomResponse, error)
func (Keeper) TransferDenomOwner ¶
func (k Keeper) TransferDenomOwner( ctx sdk.Context, denomID string, srcOwner, dstOwner sdk.AccAddress, ) error
TransferDenomOwner transfers the ownership of the given denom to the new owner
func (Keeper) TransferNFT ¶ added in v0.2.5
func (k Keeper) TransferNFT(goCtx context.Context, msg *types.MsgTransferNFT) (*types.MsgTransferNFTResponse, error)
func (Keeper) TransferOwnership ¶
func (k Keeper) TransferOwnership(ctx sdk.Context, denomID, tokenID, tokenNm, tokenURI, tokenURIHash, tokenData string, srcOwner, dstOwner sdk.AccAddress, ) error
TransferOwnership transfers the ownership of the given NFT to the new owner
type Migrator ¶ added in v0.2.5
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is a struct for handling in-place store migrations.
func NewMigrator ¶ added in v0.2.5
NewMigrator returns a new Migrator.