keeper

package
v0.5.1-t2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 33 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxReportedExportIssues = 20

MaxReportedExportIssues caps how many individual records are spelled out in the error message. Every issue is still counted.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenesisExportError added in v0.5.0

type GenesisExportError struct {
	Module string
	Issues []GenesisExportIssue
}

GenesisExportError reports state that a genesis file cannot represent. The error-returning accessors (ExportNFTUIDPairs, ExportRefundReceivers) return it through issuesToError when the live store is damaged.

The Cosmos SDK module interface (AppModule.ExportGenesis(ctx, cdc) json.RawMessage) has no error channel, so the module-level ExportGenesis cannot surface it and degrades-and-reports instead; Error() is what spells out the actionable list of damaged keys, capped at MaxReportedExportIssues.

func (*GenesisExportError) Error added in v0.5.0

func (e *GenesisExportError) Error() string

type GenesisExportIssue added in v0.5.0

type GenesisExportIssue struct {
	Kind   GenesisExportIssueKind
	Key    string
	Detail string
}

GenesisExportIssue is one state record that cannot be exported faithfully. Key carries the store key so an operator can point at the exact record.

func MergeExportIssues added in v0.5.0

func MergeExportIssues(groups ...[]GenesisExportIssue) []GenesisExportIssue

MergeExportIssues flattens the per-store issue lists into one list so every caller reports them in the same order instead of re-implementing the append.

func (GenesisExportIssue) String added in v0.5.0

func (i GenesisExportIssue) String() string

type GenesisExportIssueKind added in v0.5.0

type GenesisExportIssueKind string

GenesisExportIssueKind classifies one reason why a genesis export could not represent the live store faithfully.

const (
	// GenesisExportIssueTokenPairCorrupt means a registered TokenPair record
	// could not be decoded.
	GenesisExportIssueTokenPairCorrupt GenesisExportIssueKind = "token_pair_corrupt" //nolint:gosec // G101 false positive: the identifier name contains "Token"; the value is a non-secret issue-kind code.
	// GenesisExportIssueUIDIndexBackward means a reverse (nftUID -> tokenUID)
	// index entry has no matching forward entry.
	GenesisExportIssueUIDIndexBackward GenesisExportIssueKind = "nft_uid_index_reverse_without_forward"
	// GenesisExportIssueUIDIndexForward means a forward (tokenUID -> nftUID)
	// index entry has no matching reverse entry.
	GenesisExportIssueUIDIndexForward GenesisExportIssueKind = "nft_uid_index_forward_without_reverse"
	// GenesisExportIssueRefundKeyOrphan means a refund receiver record does not
	// belong to any registered contract.
	GenesisExportIssueRefundKeyOrphan GenesisExportIssueKind = "refund_key_orphaned"
	// GenesisExportIssueUIDIndexUnregisteredPair means a bidirectional
	// conversion binding is internally consistent but its contract/class no
	// longer resolve to a registered token pair, so the import side would
	// reject it (ValidateGenesisPairs) and InitGenesis would panic. The export
	// drops and reports it instead.
	GenesisExportIssueUIDIndexUnregisteredPair GenesisExportIssueKind = "nft_uid_index_unregistered_pair"
)

type Keeper

type Keeper struct {
	// contains filtered or unexported fields
}

Keeper of this module maintains collections of erc721.

func NewKeeper

NewKeeper creates new instances of the erc721 Keeper

func (Keeper) CallEVM

func (k Keeper) CallEVM(
	ctx sdk.Context,
	abi abi.ABI,
	from, contract common.Address,
	commit bool,
	method string,
	args ...interface{},
) (*evmtypes.MsgEthereumTxResponse, error)

CallEVM performs a smart contract method call using given args

func (Keeper) CallEVMWithData

func (k Keeper) CallEVMWithData(
	ctx sdk.Context,
	from common.Address,
	contract *common.Address,
	data []byte,
	commit bool,
) (*evmtypes.MsgEthereumTxResponse, error)

CallEVMWithData performs a smart contract method call using contract data

func (Keeper) ConvertERC721

func (k Keeper) ConvertERC721(
	goCtx context.Context,
	msg *types.MsgConvertERC721,
) (
	*types.MsgConvertERC721Response, error,
)

ConvertERC721 converts ERC721 tokens into native Cosmos nft for both Cosmos-native and ERC721 TokenPair Owners

func (Keeper) ConvertNFT

func (k Keeper) ConvertNFT(
	goCtx context.Context,
	msg *types.MsgConvertNFT,
) (
	*types.MsgConvertNFTResponse, error,
)

ConvertNFT ConvertCoin converts native Cosmos nft into ERC721 tokens for both Cosmos-native and ERC721 TokenPair Owners

func (Keeper) CreateNFTClass

func (k Keeper) CreateNFTClass(ctx sdk.Context, msg *types.MsgConvertERC721) error

CreateNFTClass generates the metadata to represent the ERC721 token .

func (Keeper) DeleteClassMap added in v0.4.0

func (k Keeper) DeleteClassMap(ctx sdk.Context, classID string)

DeleteClassMap deletes the token pair id for the given class.

func (Keeper) DeleteERC721Map

func (k Keeper) DeleteERC721Map(ctx sdk.Context, erc721 common.Address)

DeleteERC721Map deletes the token pair id for the given address

func (Keeper) DeleteEvmAddressByContractTokenId added in v0.2.16

func (k Keeper) DeleteEvmAddressByContractTokenId(ctx sdk.Context, evmContractAddress string, evmTokenId string)

func (Keeper) DeleteNFTPairByNFTID

func (k Keeper) DeleteNFTPairByNFTID(ctx sdk.Context, classID string, nftID string)

func (Keeper) DeleteNFTPairByTokenID

func (k Keeper) DeleteNFTPairByTokenID(ctx sdk.Context, contractAddress string, tokenID string)

DeleteNFTPairByTokenID removes the forward binding for a token id under every spelling it may have been stored in — both components of the key can be spelled more than one way — so a purge driven by a value read out of the reverse index cannot leave a key orphaned behind.

func (Keeper) DeleteNFTUIDPairByNFTUID added in v0.2.5

func (k Keeper) DeleteNFTUIDPairByNFTUID(ctx sdk.Context, nftUID string)

func (Keeper) DeleteNFTUIDPairByTokenUID added in v0.2.5

func (k Keeper) DeleteNFTUIDPairByTokenUID(ctx sdk.Context, tokenUID string)

func (Keeper) DeletePairPerTokenState added in v0.5.0

func (k Keeper) DeletePairPerTokenState(ctx sdk.Context, pair types.TokenPair)

DeletePairPerTokenState removes the bidirectional NFT UID index entries and IBC refund receivers that belong to pair, so a self-destructed (or otherwise deleted) TokenPair cannot leave orphans behind and degrade every subsequent genesis export.

func (Keeper) DeleteTokenPair

func (k Keeper) DeleteTokenPair(ctx sdk.Context, tokenPair types.TokenPair)

DeleteTokenPair removes a token pair.

func (Keeper) DeployERC721Contract

func (k Keeper) DeployERC721Contract(
	ctx sdk.Context,
	msg *types.MsgConvertNFT,
) (common.Address, error)

DeployERC721Contract creates and deploys an ERC721 contract on the EVM with the erc20 module account as owner.

func (Keeper) EvmContract added in v0.2.16

EvmContract returns a given registered token pair. The `token` lookup key is derived from an IBC voucher (port + channel + class id) and is always a class-shaped identifier, so this RPC uses the unambiguous class namespace and never touches the contract map.

func (Keeper) ExportIssues added in v0.5.0

func (k Keeper) ExportIssues(ctx sdk.Context) []GenesisExportIssue

ExportIssues aggregates every degradation the genesis export can report, without requiring the caller to build the genesis state first. The app-level diagnostics report uses it to describe a degraded export without a second full export pass.

func (Keeper) ExportNFTUIDPairs added in v0.5.0

func (k Keeper) ExportNFTUIDPairs(ctx sdk.Context) ([]types.NFTUIDPair, error)

ExportNFTUIDPairs returns every per-token conversion binding and verifies the bidirectional index is internally consistent (forward[x]=y must imply reverse[y]=x). A mismatch means the live store is corrupt; failing the export loudly is preferable to baking the corruption into a genesis file.

func (Keeper) ExportNFTUIDPairsWithReport added in v0.5.0

func (k Keeper) ExportNFTUIDPairsWithReport(ctx sdk.Context) ([]types.NFTUIDPair, []GenesisExportIssue)

ExportNFTUIDPairsWithReport collects every damaged index entry instead of aborting on the first one, so the fail-closed export can report the complete repair list in one pass.

A binding is exported only if the import side would accept it: types.ValidateGenesisPairs requires the token UID and the NFT UID to resolve to the same registered token pair, and InitGenesis panics on the same condition. A consistent binding can still outlive its pair -- a pair record that no longer decodes is dropped from the exported TokenPairs, and a removed pair's index entries are swept best-effort -- so emitting them verbatim produced a genesis that failed its own validation: an unusable backup exactly when it is needed. Such bindings are dropped AND reported: dropping is the only importable option (nothing this validation rejects can survive an InitGenesis), and the dropped record stays visible in <home>/export-issues.json so it can be repaired out of band. The live chain is untouched either way -- this is purely about producing a genesis that can be read back.

func (Keeper) ExportRefundReceivers added in v0.5.0

func (k Keeper) ExportRefundReceivers(ctx sdk.Context) ([]types.RefundReceiver, error)

ExportRefundReceivers returns every recorded IBC refund receiver. Refund store keys are "<contractAddress><tokenID>" concatenations; the contract part is recovered by matching against the registered pair contracts, which is lossless for any address format and fails loudly on orphaned records instead of silently dropping refund state.

func (Keeper) ExportRefundReceiversWithReport added in v0.5.0

func (k Keeper) ExportRefundReceiversWithReport(ctx sdk.Context) ([]types.RefundReceiver, []GenesisExportIssue)

ExportRefundReceiversWithReport exports every refund receiver and reports (rather than aborts on) the orphaned keys, so the fail-closed caller can print the full repair list at once.

func (Keeper) GetClassIDAndNFTID added in v0.2.5

func (k Keeper) GetClassIDAndNFTID(ctx sdk.Context, msg *types.MsgConvertERC721) (string, []string, error)

GetClassIDAndNFTID resolves the canonical Cosmos class id and NFT ids for an ERC721 → Cosmos conversion. The stored UID mapping is authoritative: when a token is already bound, its saved class/NFT id wins over caller input, and caller input that contradicts it is rejected.

func (Keeper) GetClassMap

func (k Keeper) GetClassMap(ctx sdk.Context, classID string) []byte

GetClassMap returns the token pair id for the given class

func (Keeper) GetContractAddressAndTokenIds added in v0.2.8

func (k Keeper) GetContractAddressAndTokenIds(ctx sdk.Context, msg *types.MsgConvertNFT) (string, []string, error)

GetContractAddressAndTokenIds resolves the canonical ERC721 contract address and token ids for a Cosmos → ERC721 conversion, using saved mappings or generating new ids as needed. An unregistered class deploys a fresh module contract; a registered class is pinned to its canonical contract, and a caller-supplied address that differs is rejected.

func (Keeper) GetERC721Map

func (k Keeper) GetERC721Map(ctx sdk.Context, erc721 common.Address) []byte

GetERC721Map returns the token pair id for the given address

func (Keeper) GetEnableErc721 added in v0.4.0

func (k Keeper) GetEnableErc721(ctx sdk.Context) bool

GetEnableErc721 returns whether ERC721 conversion is enabled.

func (Keeper) GetEvmAddressByContractTokenId added in v0.2.16

func (k Keeper) GetEvmAddressByContractTokenId(ctx sdk.Context, evmContractAddress string, evmTokenId string) []byte

func (Keeper) GetEvmRefundReceiver added in v0.4.0

func (k Keeper) GetEvmRefundReceiver(ctx sdk.Context, evmContractAddress, cosmosTokenId, evmTokenId string) []byte

GetEvmRefundReceiver looks up the original ERC721 owner recorded at IBC send.

func (Keeper) GetNFTPairByClassNFTID added in v0.2.8

func (k Keeper) GetNFTPairByClassNFTID(ctx sdk.Context, classID string, nftID string) []byte

func (Keeper) GetNFTPairByContractTokenID added in v0.2.8

func (k Keeper) GetNFTPairByContractTokenID(ctx sdk.Context, contractAddress string, tokenID string) []byte

func (Keeper) GetNFTUIDPairByTokenUID added in v0.2.5

func (k Keeper) GetNFTUIDPairByTokenUID(ctx sdk.Context, tokenUID string) []byte

func (Keeper) GetPair added in v0.2.5

func (k Keeper) GetPair(
	ctx sdk.Context,
	token string,
) (types.TokenPair, error)

GetPair looks up a token pair by contract address first, then by class id. NOTE: this combined lookup routes by string shape (see GetTokenPairID) and is therefore ambiguous when a class id equals a contract address. Handlers must use the semantics-specific lookups below instead.

func (Keeper) GetPairByClass added in v0.5.0

func (k Keeper) GetPairByClass(
	ctx sdk.Context,
	classID string,
) (types.TokenPair, error)

GetPairByClass resolves a pair exclusively from the class-id map. Conversion handlers that operate on a native class (ConvertNFT) must use this so a hex-address-shaped denom can never resolve to the contract-address map of a different, victim pair.

func (Keeper) GetPairByEVM added in v0.5.0

func (k Keeper) GetPairByEVM(
	ctx sdk.Context,
	contract string,
) (types.TokenPair, error)

GetPairByEVM resolves a pair exclusively from the contract-address map. Handlers that operate on an ERC721 contract (ConvertERC721) must use this so the lookup cannot be hijacked through the class-id namespace.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams returns the total set of erc721 parameters.

func (Keeper) GetTokenPair

func (k Keeper) GetTokenPair(ctx sdk.Context, id []byte) (types.TokenPair, bool)

GetTokenPair - get registered token pair from the identifier

func (Keeper) GetTokenPairID deprecated

func (k Keeper) GetTokenPairID(ctx sdk.Context, token string) []byte

GetTokenPairID returns the pair id from either of the registered tokens.

Deprecated: dispatches by string shape, which is unsafe for hex-shaped class ids. Kept only for backwards compatibility with the gRPC TokenPair read query. Handlers and write paths MUST use GetPairByClass / GetPairByEVM instead.

func (Keeper) GetTokenPairs

func (k Keeper) GetTokenPairs(ctx sdk.Context) []types.TokenPair

GetTokenPairs - get all registered token tokenPairs

Corrupt records are skipped here and reported through GetTokenPairsWithReport: this accessor is reachable from the gRPC query path, where a panic would take the node's query handler down, and it is no longer the genesis-export entry point (ExportGenesis fails closed on the report).

func (Keeper) GetTokenPairsWithReport added in v0.5.0

func (k Keeper) GetTokenPairsWithReport(ctx sdk.Context) ([]types.TokenPair, []GenesisExportIssue)

GetTokenPairsWithReport returns every decodable token pair plus the list of records that could not be decoded. Damaged records are never dropped silently: the caller decides whether to abort (genesis export does) or to continue with the healthy subset.

func (Keeper) GetTokenUIDPairByNFTUID added in v0.2.5

func (k Keeper) GetTokenUIDPairByNFTUID(ctx sdk.Context, nftUID string) []byte

func (*Keeper) GetVoucherClassID added in v0.2.16

func (k *Keeper) GetVoucherClassID(port string, channel string, classId string) string

GetVoucherClassID returns the canonical IBC voucher class ID for a given (port, channel, originalClassID) tuple.

KEEP-IN-SYNC: duplicated in x/evmibc/keeper/keeper.go (the keepers cannot import each other). Bodies MUST stay byte-identical.

func (Keeper) IsClassRegistered

func (k Keeper) IsClassRegistered(ctx sdk.Context, classID string) bool

IsClassRegistered check if registered nft class is registered

func (Keeper) IsERC721Registered

func (k Keeper) IsERC721Registered(ctx sdk.Context, erc721 common.Address) bool

IsERC721Registered check if registered ERC721 token is registered

func (Keeper) IsTokenPairRegistered

func (k Keeper) IsTokenPairRegistered(ctx sdk.Context, id []byte) bool

IsTokenPairRegistered - check if registered token tokenPair is registered

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) Params

Params returns the params of the erc20 module

func (Keeper) PruneDuplicateUIDIndexEntries added in v0.5.0

func (k Keeper) PruneDuplicateUIDIndexEntries(ctx sdk.Context) UIDIndexPruneReport

PruneDuplicateUIDIndexEntries removes the duplicate forward keys the pre-v0.4.1 write path could leave behind; it is the one-shot half of the A-3/A-4 key-spelling work.

WHY A MIGRATION IS NEEDED AT ALL. The runtime fixes make both components of a forward key readable under either spelling and make every write canonical, but they only rewrite a pair a write path actually touches; a superseded forward key persists with no reverse partner -- exactly the GenesisExportIssueUIDIndexForward that degrades every genesis export (B-1) and buries real corruption in fixed noise.

THE REVERSE INDEX IS THE AUTHORITY. A forward key is built from two components, so a binding can be stored under a cross product of spellings and no single key is self-evidently "the" one. The reverse index is keyed by nftUID -- one entry per Cosmos NFT, naming the spelling its binding lives under -- so every decision below is anchored on it, which is what makes "is this key redundant?" answerable at all.

WHAT IS DELETED, AND ONLY THIS. A forward key K is removed iff all of:

  1. K is not the tokenUID some reverse entry points at (K is not an authority — the authority is the surviving spelling by construction);
  2. K denotes the same (uint256 token id, 20-byte address) pair as that reverse entry's tokenUID, i.e. K is one of its spelling variants;
  3. forward[K] is that reverse entry's very nftUID.

Condition 2 must cover BOTH axes: a duplicate can differ in the token-id segment (the v0.3.3 "0x"+hex spelling versus the v0.4.0 sha256 base-10 one) as easily as in the address segment. Only the address axis fires today -- the legacy token-id keys are all still the authority of their binding -- but the axis is covered so the criterion need not be revisited if that changes.

Condition 1 is deliberately "K is not an authority" rather than the blunter "K is not disputed": mainnet holds six bindings that TWO reverse entries each point at, so a key can be B's spelling sibling while duplicating A -- whose own key survives, so dropping the duplicate loses nothing, while refusing on B's account would leave the store unconverged.

WHAT IS LEFT ALONE. Anything that cannot self-prove as a duplicate is reported instead of guessed at:

  • a forward key no reverse entry accounts for ("orphan"): the reverse half is gone, so deleting it would destroy the only remaining record of a binding;
  • a spelling variant of a reverse entry's tokenUID whose value no reverse entry vouches for ("conflict"): two NFTs claim one token, and picking a winner is exactly what SetNFTPairs refuses to do;
  • the authoritative key of a non-canonically spelled binding: the runtime reads it and the next write canonicalises it, so it is a pair not written since, not a duplicate. Rewriting it would be a full normalisation, not a shadow removal.

NO ERROR, NO PANIC, IDEMPOTENT. This runs from an upgrade handler: failing would halt the chain at the upgrade height over pre-existing state the handler is not required to repair, so a residual orphan or conflict is logged at Error level instead -- the genesis export's fail-closed-but-keep-running posture. After the pass no deletable key remains, so a replay removes nothing; v0.4.1 needs that, as it deliberately carries no UpgradeAlreadyApplied guard.

func (Keeper) PurgeTokenPair added in v0.5.0

func (k Keeper) PurgeTokenPair(ctx sdk.Context, pair types.TokenPair)

PurgeTokenPair removes a token pair and every piece of state that refers to it: the per-token bidirectional index entries, the IBC refund receivers, and both lookup maps (contract -> pair id, class -> pair id). It is idempotent.

IMPORTANT — commit semantics: Cosmos SDK state is transactional per message-execution. Any write performed on a handler path that eventually returns an error is rolled back by baseapp, so PurgeTokenPair must only be invoked from a path that ends in success (or from tests / a future governance message), otherwise the purge silently never persists. See Keeper.ConvertNFT for the one production caller that uses it this way.

func (Keeper) QueryClassEnhance added in v0.2.5

func (k Keeper) QueryClassEnhance(
	ctx sdk.Context,
	contract common.Address,
) (types.ClassEnhance, error)

QueryClassEnhance returns the data of a deployed ERC721 contract

func (Keeper) QueryERC721

func (k Keeper) QueryERC721(
	ctx sdk.Context,
	contract common.Address,
) (types.ERC721Data, error)

QueryERC721 returns the data of a deployed ERC721 contract

func (Keeper) QueryERC721DataByTokenID added in v0.2.16

func (k Keeper) QueryERC721DataByTokenID(
	queryFuncName string,
	ctx sdk.Context,
	contract common.Address,
	tokenID *big.Int) ([]interface{}, error)

func (Keeper) QueryERC721Token

func (k Keeper) QueryERC721Token(
	ctx sdk.Context,
	contract common.Address,
) (types.ERC721TokenData, error)

QueryERC721Token returns the data of a ERC721 token

func (Keeper) QueryERC721TokenOwner

func (k Keeper) QueryERC721TokenOwner(
	ctx sdk.Context,
	contract common.Address,
	tokenID *big.Int,
) (common.Address, error)

QueryERC721TokenOwner returns the owner of given tokenID

func (Keeper) QueryNFTEnhance added in v0.2.5

func (k Keeper) QueryNFTEnhance(
	ctx sdk.Context,
	contract common.Address,
	tokenID *big.Int,
) (types.NFTEnhance, error)

QueryNFTEnhance returns the data of a deployed ERC721 contract

func (Keeper) RefundPacketToken added in v0.2.16

func (k Keeper) RefundPacketToken(
	ctx sdk.Context,
	data ibcnfttransfertypes.NonFungibleTokenPacketData,
) error

RefundPacketToken handles the erc721 conversion for a native erc721 token pair:

  • escrow tokens on module account
  • mint nft to the receiver: nftId: tokenAddress|tokenID

func (Keeper) RegisterERC721

func (k Keeper) RegisterERC721(ctx sdk.Context, msg *types.MsgConvertERC721) (*types.TokenPair, error)

RegisterERC721 creates a Cosmos coin and registers the token pair between the nft and the ERC721

func (Keeper) RegisterNFT

func (k Keeper) RegisterNFT(ctx sdk.Context, msg *types.MsgConvertNFT) (*types.TokenPair, error)

RegisterNFT deploys an erc721 contract and creates the token pair for the existing cosmos coin

func (Keeper) ResolveNFTUIDPair added in v0.5.0

func (k Keeper) ResolveNFTUIDPair(ctx sdk.Context, contractAddress string, tokenID string) (nftUID []byte, matchedTokenID string)

ResolveNFTUIDPair resolves the forward (contract, tokenID) → NFT binding for a key written under ANY spelling of either component, returning the stored NFT UID and the exact token-id spelling it was found under. Both spellings of each component denote the same value (a uint256, and a 20-byte address), so callers that hold any of them reach the same binding.

Read-only by construction: it never rewrites the key it found. The upgrade to the canonical spelling happens in SetNFTPairs, i.e. only when a write path is already touching the pair.

func (Keeper) SetClassMap

func (k Keeper) SetClassMap(ctx sdk.Context, classID string, id []byte)

SetClassMap sets the token pair id for the classID

func (Keeper) SetERC721Map

func (k Keeper) SetERC721Map(ctx sdk.Context, erc721 common.Address, id []byte)

SetERC721Map sets the token pair id for the given address

func (Keeper) SetEvmAddressByContractTokenId added in v0.2.16

func (k Keeper) SetEvmAddressByContractTokenId(ctx sdk.Context, evmContractAddress string, evmTokenId string, evmAddress string)

SetEvmAddressByContractTokenId

func (Keeper) SetEvmRefundReceiver added in v0.4.0

func (k Keeper) SetEvmRefundReceiver(ctx sdk.Context, evmContractAddress string, cosmosTokenIds, evmTokenIds []string, evmAddress string)

SetEvmRefundReceiver records the original ERC721 owner for IBC timeout/error refunds. Keys use a lowercased contract address plus both cosmos and EVM token ids so lookup matches packet TokenIds and the NFT-UID mapping.

func (Keeper) SetGenesisNFTUIDPair added in v0.5.0

func (k Keeper) SetGenesisNFTUIDPair(ctx sdk.Context, pair types.NFTUIDPair)

SetGenesisNFTUIDPair restores one bidirectional conversion binding during InitGenesis, writing both directions of the runtime index.

func (Keeper) SetGenesisRefundReceiver added in v0.5.0

func (k Keeper) SetGenesisRefundReceiver(ctx sdk.Context, receiver types.RefundReceiver)

SetGenesisRefundReceiver restores one IBC refund receiver during InitGenesis. The contract address is lowercased to match runtime refund keys.

func (Keeper) SetNFTPairByClassNFTID added in v0.2.8

func (k Keeper) SetNFTPairByClassNFTID(ctx sdk.Context, classID string, nftID string, contractAddress string, tokenID string)

func (Keeper) SetNFTPairByContractTokenID added in v0.2.8

func (k Keeper) SetNFTPairByContractTokenID(ctx sdk.Context, contractAddress string, tokenID string, classID string, nftID string)

func (Keeper) SetNFTPairs added in v0.2.5

func (k Keeper) SetNFTPairs(ctx sdk.Context, contractAddress string, tokenID string, classID string, nftID string) error

SetNFTPairs atomically binds an EVM (contract, tokenID) to a Cosmos NFT (classID, nftID) in both directions, enforcing the one-to-one invariant forward[x]=y ⟺ reverse[y]=x. A conflicting binding would let an attacker release a module-escrowed victim token (registry poisoning) and is rejected with ErrNFTMappingConflict so the conversion rolls back.

Key spelling: BOTH components of the forward key are normalised. The token id is written as the canonical base-10 value (types.CanonicalEVMTokenID) and the contract address as its lowercase form (types.CanonicalContractAddress), and any pre-existing key for the same binding under another spelling of either component is removed in the same write. That is what lets a pair created before v0.4.0 stay readable (see ResolveNFTUIDPair) while the store converges on one key per binding instead of accumulating duplicates.

Creation is still strictly gated — but only on the token id, because only there do the two spellings mean different things. A legacy "0x"+hex token id is accepted only when it is upgrading a binding that already exists; letting a fresh binding use the old spelling would key it by a value that differs from what the caller's string names. The two address spellings are the same 20 bytes, so an address is simply normalised and needs no gate.

func (Keeper) SetNFTUIDPairByNFTUID added in v0.2.5

func (k Keeper) SetNFTUIDPairByNFTUID(ctx sdk.Context, nftUID string, tokenUID string)

func (Keeper) SetNFTUIDPairByTokenUID added in v0.2.5

func (k Keeper) SetNFTUIDPairByTokenUID(ctx sdk.Context, tokenUID string, nftUID string)

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error

SetParams sets the erc721 parameters to the store.

func (Keeper) SetTokenPair

func (k Keeper) SetTokenPair(ctx sdk.Context, tokenPair types.TokenPair) error

SetTokenPair stores a token pair. A protobuf marshal failure is surfaced to the caller instead of being swallowed: silently dropping the write would leave the token pair unregistered while later lookups assume it exists.

func (Keeper) SettleIBCVoucherPairs added in v0.5.0

func (k Keeper) SettleIBCVoucherPairs(ctx sdk.Context) (settled, staleCleared, kept, pairsDeleted int)

SettleIBCVoucherPairs clears legacy ibc/ voucher pairs left behind by the pre-R1-C convert-memo / manual-convert flow, which bound an ICS-721 voucher to an ERC721 contract. Such a pair's presence made the ICS-721 burn guard (x/internft IsConvertedNFT) refuse to release the voucher on its way back to the origin chain (R1). This is the v0.5.0 migration companion to the registration gate (A1) and the terminal un-wrap (A3): the gate stops new pairs, this function settles the existing ones, and A3 lets any pair it keeps (ambiguous state) self-heal through a normal ConvertERC721.

Per binding it classifies the (ERC owner × native owner) state:

  • user × module (wrapped): burn the ERC721 half and hand the native voucher to the same 20-byte account, then drop the binding — settled.
  • module × none (orphan, e.g. a pre-v0.4.0 redeem residue): burn the module-held ERC721 half and drop the binding — settled.
  • user × none / none × none (stale): only drop the binding — stale_cleared.
  • anything else (native in escrow, ERC held by a contract, ambiguous owner, EVM query failure): leave untouched and log — kept (never destroy an asset we cannot positively attribute; A3 remains the self-heal path).

Each binding is settled in its own cache context so a mid-token failure rolls back to a clean state instead of leaving a burned ERC721 with a surviving native NFT. It is idempotent: a second run sees no bindings and reports all zeros.

func (Keeper) TokenPair

TokenPair returns a given registered token pair.

The input is an untyped user-supplied string: the class-id namespace is tried first, with fallback to the contract map only when the input is unambiguously an EVM hex address (see GetTokenPairID for the shape-routing footgun this avoids).

func (Keeper) TokenPairs

TokenPairs returns all registered pairs

func (Keeper) TransferERC721 added in v0.2.16

func (k Keeper) TransferERC721(
	goCtx context.Context,
	msg *types.MsgTransferERC721,
) (
	*types.MsgTransferERC721Response, error,
)

TransferERC721 converts ERC721 tokens into native Cosmos nft for both Cosmos-native and ERC721 TokenPair Owners and transfer through IBC

func (Keeper) UpdateParams added in v0.4.0

UpdateParams updates erc721 params. Authority must be the gov module account.

type UIDIndexPruneReport added in v0.5.0

type UIDIndexPruneReport struct {
	// Scanned is the number of reverse-index entries inspected.
	Scanned int
	// ForwardBefore is the number of forward keys before the pass.
	ForwardBefore int
	// Deleted holds the forward keys removed because they provably duplicated a
	// binding that survives under another spelling.
	Deleted []string
	// Conflicts holds the forward keys a reverse entry's spelling variant
	// matched but whose value no reverse entry vouches for. Left in place.
	Conflicts []string
	// Orphans holds the forward keys no reverse entry can account for, i.e. the
	// reverse half of the pair is missing. Left in place.
	Orphans []string
	// UnpairedNFTs holds the reverse entries whose own forward key is missing.
	UnpairedNFTs []string
}

UIDIndexPruneReport is the outcome of one PruneDuplicateUIDIndexEntries pass: what it removed and what it refused to touch. Every list is sorted so the caller's log line is reproducible.

func (UIDIndexPruneReport) Balanced added in v0.5.0

func (r UIDIndexPruneReport) Balanced() bool

Balanced reports whether the forward and reverse indexes agree in size after the pass: the property a healthy store has, so it doubles as the migration's postcondition (app/upgrades/v041/migrate.go, uidIndexPruneClean).

func (UIDIndexPruneReport) ForwardAfter added in v0.5.0

func (r UIDIndexPruneReport) ForwardAfter() int

ForwardAfter returns the forward key count once the pass has been applied.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL