types

package
v0.0.0-...-9863cff Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName is the name of the module
	ModuleName = "nft"

	// StoreKey is the default store key for NFT
	StoreKey = ModuleName

	// QuerierRoute is the querier route for the NFT store.
	QuerierRoute = ModuleName

	// RouterKey is the message route for the NFT module
	RouterKey = ModuleName
)

Variables

View Source
var (
	EventTypeTransfer        = "transfer_nft"
	EventTypeEditNFTMetadata = "edit_nft_metadata"
	EventTypeMintNFT         = "mint_nft"
	EventTypeBurnNFT         = "burn_nft"

	AttributeValueCategory = ModuleName

	AttributeKeySender      = "sender"
	AttributeKeyRecipient   = "recipient"
	AttributeKeyOwner       = "owner"
	AttributeKeyNFTID       = "nft-id"
	AttributeKeyNFTTokenURI = "token-uri"
	AttributeKeyDenom       = "denom"
)

NFT module event types

View Source
var (
	CollectionsKeyPrefix = []byte{0x00} // key for NFT collections
	OwnersKeyPrefix      = []byte{0x01} // key for balance of NFTs held by an address
)

NFTs are stored as follow:

- Colections: 0x00<denom_bytes_key> :<Collection>

- Owners: 0x01<address_bytes_key><denom_bytes_key>: <Owner>

View Source
var ModuleCdc *codec.Codec

ModuleCdc generic sealed codec to be used throughout this module

Functions

func CreateTestAddrs

func CreateTestAddrs(numAddrs int) []sdk.AccAddress

CreateTestAddrs creates test addresses

func ErrEmptyMetadata

func ErrEmptyMetadata(codespace sdk.CodespaceType, msg string) sdk.Error

ErrEmptyMetadata is an error when metadata is empty

func ErrInvalidCollection

func ErrInvalidCollection(codespace sdk.CodespaceType) sdk.Error

ErrInvalidCollection is an error

func ErrInvalidNFT

func ErrInvalidNFT(codespace sdk.CodespaceType) sdk.Error

ErrInvalidNFT is an error

func ErrNFTAlreadyExists

func ErrNFTAlreadyExists(codespace sdk.CodespaceType, msg string) sdk.Error

ErrNFTAlreadyExists is an error when an invalid NFT is minted

func ErrUnknownCollection

func ErrUnknownCollection(codespace sdk.CodespaceType, msg string) sdk.Error

ErrUnknownCollection is an error

func ErrUnknownNFT

func ErrUnknownNFT(codespace sdk.CodespaceType, msg string) sdk.Error

ErrUnknownNFT is an error

func FindUtil

func FindUtil(group Findable, el string) int

FindUtil is a binary search funcion for types that support the Findable interface (elements must be sorted)

func GetCollectionKey

func GetCollectionKey(denom string) []byte

GetCollectionKey gets the key of a collection

func GetOwnerKey

func GetOwnerKey(address sdk.AccAddress, denom string) []byte

GetOwnerKey gets the key of a collection owned by an account address

func GetOwnersKey

func GetOwnersKey(address sdk.AccAddress) []byte

GetOwnersKey gets the key prefix for all the collections owned by an account address

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec concrete types on codec

func SplitOwnerKey

func SplitOwnerKey(key []byte) (sdk.AccAddress, []byte)

SplitOwnerKey gets an address and denom from an owner key

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

ValidateGenesis performs basic validation of nfts genesis data returning an error for any failed validation criteria.

Types

type BaseNFT

type BaseNFT struct {
	ID       string         `json:"id,omitempty" yaml:"id"`     // id of the token; not exported to clients
	Owner    sdk.AccAddress `json:"owner" yaml:"owner"`         // account address that owns the NFT
	TokenURI string         `json:"token_uri" yaml:"token_uri"` // optional extra properties available for querying
}

BaseNFT non fungible token definition

func NewBaseNFT

func NewBaseNFT(id string, owner sdk.AccAddress, tokenURI string) BaseNFT

NewBaseNFT creates a new NFT instance

func (*BaseNFT) EditMetadata

func (bnft *BaseNFT) EditMetadata(tokenURI string)

EditMetadata edits metadata of an nft

func (BaseNFT) GetID

func (bnft BaseNFT) GetID() string

GetID returns the ID of the token

func (BaseNFT) GetOwner

func (bnft BaseNFT) GetOwner() sdk.AccAddress

GetOwner returns the account address that owns the NFT

func (BaseNFT) GetTokenURI

func (bnft BaseNFT) GetTokenURI() string

GetTokenURI returns the path to optional extra properties

func (*BaseNFT) SetOwner

func (bnft *BaseNFT) SetOwner(address sdk.AccAddress)

SetOwner updates the owner address of the NFT

func (BaseNFT) String

func (bnft BaseNFT) String() string

type CodeType

type CodeType = sdk.CodeType

CodeType definition

const (
	DefaultCodespace sdk.CodespaceType = ModuleName

	CodeInvalidCollection CodeType = 650
	CodeUnknownCollection CodeType = 651
	CodeInvalidNFT        CodeType = 652
	CodeUnknownNFT        CodeType = 653
	CodeNFTAlreadyExists  CodeType = 654
	CodeEmptyMetadata     CodeType = 655
)

NFT error code

type Collection

type Collection struct {
	Denom string `json:"denom,omitempty" yaml:"denom"` // name of the collection; not exported to clients
	NFTs  NFTs   `json:"nfts" yaml:"nfts"`             // NFTs that belong to a collection
}

Collection of non fungible tokens

func EmptyCollection

func EmptyCollection() Collection

EmptyCollection returns an empty collection

func NewCollection

func NewCollection(denom string, nfts NFTs) Collection

NewCollection creates a new NFT Collection

func (Collection) AddNFT

func (collection Collection) AddNFT(nft exported.NFT) (Collection, sdk.Error)

AddNFT adds an NFT to the collection

func (Collection) ContainsNFT

func (collection Collection) ContainsNFT(id string) bool

ContainsNFT returns whether or not a Collection contains an NFT

func (Collection) DeleteNFT

func (collection Collection) DeleteNFT(nft exported.NFT) (Collection, sdk.Error)

DeleteNFT deletes an NFT from a collection

func (Collection) GetNFT

func (collection Collection) GetNFT(id string) (nft exported.NFT, err sdk.Error)

GetNFT gets a NFT from the collection

func (Collection) String

func (collection Collection) String() string

String follows stringer interface

func (Collection) Supply

func (collection Collection) Supply() int

Supply gets the total supply of NFTs of a collection

func (Collection) UpdateNFT

func (collection Collection) UpdateNFT(nft exported.NFT) (Collection, sdk.Error)

UpdateNFT updates an NFT from a collection

type CollectionJSON

type CollectionJSON map[string]Collection

CollectionJSON is the exported Collection format for clients

type Collections

type Collections []Collection

Collections define an array of Collection

func NewCollections

func NewCollections(collections ...Collection) Collections

NewCollections creates a new set of NFTs

func (Collections) Append

func (collections Collections) Append(collectionsB ...Collection) Collections

Append appends two sets of Collections

func (Collections) ElAtIndex

func (collections Collections) ElAtIndex(index int) string

func (Collections) Empty

func (collections Collections) Empty() bool

Empty returns true if there are no collections and false otherwise.

func (Collections) Find

func (collections Collections) Find(denom string) (Collection, bool)

Find returns the searched collection from the set

func (Collections) Len

func (collections Collections) Len() int

func (Collections) Less

func (collections Collections) Less(i, j int) bool

func (Collections) MarshalJSON

func (collections Collections) MarshalJSON() ([]byte, error)

MarshalJSON for Collections

func (Collections) Remove

func (collections Collections) Remove(denom string) (Collections, bool)

Remove removes a collection from the set of collections

func (Collections) Sort

func (collections Collections) Sort() Collections

Sort is a helper function to sort the set of coins inplace

func (Collections) String

func (collections Collections) String() string

String follows stringer interface

func (Collections) Swap

func (collections Collections) Swap(i, j int)

func (*Collections) UnmarshalJSON

func (collections *Collections) UnmarshalJSON(b []byte) error

UnmarshalJSON for Collections

type Findable

type Findable interface {
	ElAtIndex(index int) string
	Len() int
}

Findable is an interface for iterable types that allows the FindUtil function to work

type GenesisState

type GenesisState struct {
	Owners      []Owner     `json:"owners"`
	Collections Collections `json:"collections"`
}

GenesisState is the state that must be provided at genesis.

func DefaultGenesisState

func DefaultGenesisState() GenesisState

DefaultGenesisState returns a default genesis state

func NewGenesisState

func NewGenesisState(owners []Owner, collections Collections) GenesisState

NewGenesisState creates a new genesis state.

type IDCollection

type IDCollection struct {
	Denom string            `json:"denom" yaml:"denom"`
	IDs   SortedStringArray `json:"ids" yaml:"ids"`
}

IDCollection defines a set of nft ids that belong to a specific collection

func NewIDCollection

func NewIDCollection(denom string, ids []string) IDCollection

NewIDCollection creates a new IDCollection instance

func (IDCollection) AddID

func (idCollection IDCollection) AddID(id string) IDCollection

AddID adds an ID to the idCollection

func (IDCollection) DeleteID

func (idCollection IDCollection) DeleteID(id string) (IDCollection, sdk.Error)

DeleteID deletes an ID from an ID Collection

func (IDCollection) Exists

func (idCollection IDCollection) Exists(id string) (exists bool)

Exists determines whether an ID is in the IDCollection

func (IDCollection) String

func (idCollection IDCollection) String() string

String follows stringer interface

func (IDCollection) Supply

func (idCollection IDCollection) Supply() int

Supply gets the total supply of NFTIDs of a balance

type IDCollections

type IDCollections []IDCollection

IDCollections is an array of ID Collections whose sole purpose is for find

func (IDCollections) Append

func (idCollections IDCollections) Append(idCollections2 ...IDCollection) IDCollections

Append appends IDCollections to IDCollections

func (IDCollections) ElAtIndex

func (idCollections IDCollections) ElAtIndex(index int) string

func (IDCollections) Len

func (idCollections IDCollections) Len() int

func (IDCollections) Less

func (idCollections IDCollections) Less(i, j int) bool

func (IDCollections) Sort

func (idCollections IDCollections) Sort() IDCollections

Sort is a helper function to sort the set of strings in place

func (IDCollections) String

func (idCollections IDCollections) String() string

String follows stringer interface

func (IDCollections) Swap

func (idCollections IDCollections) Swap(i, j int)

type MsgBurnNFT

type MsgBurnNFT struct {
	Sender sdk.AccAddress
	ID     string
	Denom  string
}

MsgBurnNFT defines a BurnNFT message

func NewMsgBurnNFT

func NewMsgBurnNFT(sender sdk.AccAddress, id string, denom string) MsgBurnNFT

NewMsgBurnNFT is a constructor function for MsgBurnNFT

func (MsgBurnNFT) GetSignBytes

func (msg MsgBurnNFT) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgBurnNFT) GetSigners

func (msg MsgBurnNFT) GetSigners() []sdk.AccAddress

GetSigners Implements Msg.

func (MsgBurnNFT) Route

func (msg MsgBurnNFT) Route() string

Route Implements Msg

func (MsgBurnNFT) Type

func (msg MsgBurnNFT) Type() string

Type Implements Msg

func (MsgBurnNFT) ValidateBasic

func (msg MsgBurnNFT) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgEditNFTMetadata

type MsgEditNFTMetadata struct {
	Sender   sdk.AccAddress
	ID       string
	Denom    string
	TokenURI string
}

MsgEditNFTMetadata edits an NFT's metadata

func NewMsgEditNFTMetadata

func NewMsgEditNFTMetadata(sender sdk.AccAddress, id,
	denom, tokenURI string,
) MsgEditNFTMetadata

NewMsgEditNFTMetadata is a constructor function for MsgSetName

func (MsgEditNFTMetadata) GetSignBytes

func (msg MsgEditNFTMetadata) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgEditNFTMetadata) GetSigners

func (msg MsgEditNFTMetadata) GetSigners() []sdk.AccAddress

GetSigners Implements Msg.

func (MsgEditNFTMetadata) Route

func (msg MsgEditNFTMetadata) Route() string

Route Implements Msg

func (MsgEditNFTMetadata) Type

func (msg MsgEditNFTMetadata) Type() string

Type Implements Msg

func (MsgEditNFTMetadata) ValidateBasic

func (msg MsgEditNFTMetadata) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgMintNFT

type MsgMintNFT struct {
	Sender    sdk.AccAddress
	Recipient sdk.AccAddress
	ID        string
	Denom     string
	TokenURI  string
}

MsgMintNFT defines a MintNFT message

func NewMsgMintNFT

func NewMsgMintNFT(sender, recipient sdk.AccAddress, id, denom, tokenURI string) MsgMintNFT

NewMsgMintNFT is a constructor function for MsgMintNFT

func (MsgMintNFT) GetSignBytes

func (msg MsgMintNFT) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgMintNFT) GetSigners

func (msg MsgMintNFT) GetSigners() []sdk.AccAddress

GetSigners Implements Msg.

func (MsgMintNFT) Route

func (msg MsgMintNFT) Route() string

Route Implements Msg

func (MsgMintNFT) Type

func (msg MsgMintNFT) Type() string

Type Implements Msg

func (MsgMintNFT) ValidateBasic

func (msg MsgMintNFT) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type MsgTransferNFT

type MsgTransferNFT struct {
	Sender    sdk.AccAddress
	Recipient sdk.AccAddress
	Denom     string
	ID        string
}

MsgTransferNFT defines a TransferNFT message

func NewMsgTransferNFT

func NewMsgTransferNFT(sender, recipient sdk.AccAddress, denom, id string) MsgTransferNFT

NewMsgTransferNFT is a constructor function for MsgSetName

func (MsgTransferNFT) GetSignBytes

func (msg MsgTransferNFT) GetSignBytes() []byte

GetSignBytes Implements Msg.

func (MsgTransferNFT) GetSigners

func (msg MsgTransferNFT) GetSigners() []sdk.AccAddress

GetSigners Implements Msg.

func (MsgTransferNFT) Route

func (msg MsgTransferNFT) Route() string

Route Implements Msg

func (MsgTransferNFT) Type

func (msg MsgTransferNFT) Type() string

Type Implements Msg

func (MsgTransferNFT) ValidateBasic

func (msg MsgTransferNFT) ValidateBasic() sdk.Error

ValidateBasic Implements Msg.

type NFTJSON

type NFTJSON map[string]BaseNFT

NFTJSON is the exported NFT format for clients

type NFTs

type NFTs []exported.NFT

NFTs define a list of NFT

func NewNFTs

func NewNFTs(nfts ...exported.NFT) NFTs

NewNFTs creates a new set of NFTs

func (NFTs) Append

func (nfts NFTs) Append(nftsB ...exported.NFT) NFTs

Append appends two sets of NFTs

func (NFTs) ElAtIndex

func (nfts NFTs) ElAtIndex(index int) string

Findable and Sort interfaces

func (NFTs) Empty

func (nfts NFTs) Empty() bool

Empty returns true if there are no NFTs and false otherwise.

func (NFTs) Find

func (nfts NFTs) Find(id string) (nft exported.NFT, found bool)

Find returns the searched collection from the set

func (NFTs) Len

func (nfts NFTs) Len() int

func (NFTs) Less

func (nfts NFTs) Less(i, j int) bool

func (NFTs) MarshalJSON

func (nfts NFTs) MarshalJSON() ([]byte, error)

MarshalJSON for NFTs

func (NFTs) Remove

func (nfts NFTs) Remove(id string) (NFTs, bool)

Remove removes an NFT from the set of NFTs

func (NFTs) Sort

func (nfts NFTs) Sort() NFTs

Sort is a helper function to sort the set of coins in place

func (NFTs) String

func (nfts NFTs) String() string

String follows stringer interface

func (NFTs) Swap

func (nfts NFTs) Swap(i, j int)

func (*NFTs) UnmarshalJSON

func (nfts *NFTs) UnmarshalJSON(b []byte) error

UnmarshalJSON for NFTs

func (NFTs) Update

func (nfts NFTs) Update(id string, nft exported.NFT) (NFTs, bool)

Update removes and replaces an NFT from the set

type Owner

type Owner struct {
	Address       sdk.AccAddress `json:"address" yaml:"address"`
	IDCollections IDCollections  `json:"idCollections" yaml:"idCollections"`
}

Owner of non fungible tokens

func NewOwner

func NewOwner(owner sdk.AccAddress, idCollections ...IDCollection) Owner

NewOwner creates a new Owner

func (Owner) DeleteID

func (owner Owner) DeleteID(denom string, id string) (Owner, sdk.Error)

DeleteID deletes an ID from an owners ID Collection

func (Owner) GetIDCollection

func (owner Owner) GetIDCollection(denom string) (IDCollection, bool)

GetIDCollection gets the IDCollection from the owner

func (Owner) String

func (owner Owner) String() string

String follows stringer interface

func (Owner) Supply

func (owner Owner) Supply() int

Supply gets the total supply of an Owner

func (Owner) UpdateIDCollection

func (owner Owner) UpdateIDCollection(idCollection IDCollection) (Owner, sdk.Error)

UpdateIDCollection updates the ID Collection of an owner

type QueryBalanceParams

type QueryBalanceParams struct {
	Owner sdk.AccAddress
	Denom string // optional
}

QueryBalanceParams params for query 'custom/nfts/balance'

func NewQueryBalanceParams

func NewQueryBalanceParams(owner sdk.AccAddress, denom ...string) QueryBalanceParams

NewQueryBalanceParams creates a new instance of QuerySupplyParams

type QueryCollectionParams

type QueryCollectionParams struct {
	Denom string
}

QueryCollectionParams defines the params for queries: - 'custom/nft/supply' - 'custom/nft/collection'

func NewQueryCollectionParams

func NewQueryCollectionParams(denom string) QueryCollectionParams

NewQueryCollectionParams creates a new instance of QuerySupplyParams

func (QueryCollectionParams) Bytes

func (q QueryCollectionParams) Bytes() []byte

Bytes exports the Denom as bytes

type QueryNFTParams

type QueryNFTParams struct {
	Denom   string
	TokenID string
}

QueryNFTParams params for query 'custom/nfts/nft'

func NewQueryNFTParams

func NewQueryNFTParams(denom, id string) QueryNFTParams

NewQueryNFTParams creates a new instance of QueryNFTParams

type SortedStringArray

type SortedStringArray []string

SortedStringArray is an array of strings whose sole purpose is to help with find

func (SortedStringArray) ElAtIndex

func (sa SortedStringArray) ElAtIndex(index int) string

func (SortedStringArray) Len

func (sa SortedStringArray) Len() int

func (SortedStringArray) Less

func (sa SortedStringArray) Less(i, j int) bool

func (SortedStringArray) Sort

Sort is a helper function to sort the set of strings in place

func (SortedStringArray) String

func (sa SortedStringArray) String() string

String is the string representation

func (SortedStringArray) Swap

func (sa SortedStringArray) Swap(i, j int)

Jump to

Keyboard shortcuts

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