Documentation ¶
Overview ¶
Package nft is a generated protocol buffer package. It is generated from these files: x/nft/codec.proto It has these top-level messages: NonFungibleToken ActionApprovals Approval ApprovalOptions AddApprovalMsg RemoveApprovalMsg
Package nft provides a core of a Non-fungible token implementation (NFT). Specialized implementations are located in submodules.
This package is a data container. Think of it as an implementation of a document store with permission (approval) control and possibility to create more than one index for each document. It does not provide a standalone implementation. This is a framework for building custom NFT implementations.
Index ¶
- Constants
- Variables
- func ErrDuplicateEntry(id []byte) error
- func ErrInvalidCodec(codec string) error
- func ErrInvalidEntry(id []byte) error
- func ErrInvalidHost() error
- func ErrInvalidID(id []byte) error
- func ErrInvalidJson() error
- func ErrInvalidLength() error
- func ErrInvalidPort() error
- func ErrInvalidProtocol() error
- func ErrMissingEntry() error
- func ErrUnknownID(id []byte) error
- func ErrUnsupportedTokenType() error
- func FindActor(auth x.Authenticator, ctx weave.Context, t BaseNFT, action Action) weave.Address
- func RegisterAction(actions ...Action)
- func WithOwnerIndex(bucket orm.Bucket) orm.Bucket
- type Action
- type ActionApprovals
- func (m ActionApprovals) Clone() ActionApprovals
- func (*ActionApprovals) Descriptor() ([]byte, []int)
- func (m *ActionApprovals) GetApprovals() []Approval
- func (m *ActionApprovals) Marshal() (dAtA []byte, err error)
- func (m *ActionApprovals) MarshalTo(dAtA []byte) (int, error)
- func (*ActionApprovals) ProtoMessage()
- func (m *ActionApprovals) Reset()
- func (m *ActionApprovals) Size() (n int)
- func (m *ActionApprovals) String() string
- func (m *ActionApprovals) Unmarshal(dAtA []byte) error
- type AddApprovalMsg
- func (*AddApprovalMsg) Descriptor() ([]byte, []int)
- func (m *AddApprovalMsg) GetAddress() []byte
- func (m *AddApprovalMsg) GetID() []byte
- func (m *AddApprovalMsg) GetOptions() ApprovalOptions
- func (m *AddApprovalMsg) GetT() string
- func (m *AddApprovalMsg) Marshal() (dAtA []byte, err error)
- func (m *AddApprovalMsg) MarshalTo(dAtA []byte) (int, error)
- func (*AddApprovalMsg) Path() string
- func (*AddApprovalMsg) ProtoMessage()
- func (m *AddApprovalMsg) Reset()
- func (m *AddApprovalMsg) Size() (n int)
- func (m *AddApprovalMsg) String() string
- func (m *AddApprovalMsg) Unmarshal(dAtA []byte) error
- func (m AddApprovalMsg) Validate() error
- type Approval
- func (a Approval) AsAddress() weave.Address
- func (m Approval) Clone() Approval
- func (*Approval) Descriptor() ([]byte, []int)
- func (a Approval) Equals(o Approval) bool
- func (m *Approval) GetAddress() []byte
- func (m *Approval) GetOptions() ApprovalOptions
- func (m *Approval) Marshal() (dAtA []byte, err error)
- func (m *Approval) MarshalTo(dAtA []byte) (int, error)
- func (*Approval) ProtoMessage()
- func (m *Approval) Reset()
- func (m *Approval) Size() (n int)
- func (m *Approval) String() string
- func (m *Approval) Unmarshal(dAtA []byte) error
- func (m Approval) Validate() error
- type ApprovalMeta
- type ApprovalMsg
- type ApprovalOps
- type ApprovalOptions
- func (*ApprovalOptions) Descriptor() ([]byte, []int)
- func (a ApprovalOptions) Equals(o ApprovalOptions) bool
- func (a ApprovalOptions) EqualsAfterUse(used ApprovalOptions) bool
- func (m *ApprovalOptions) GetCount() int64
- func (m *ApprovalOptions) GetImmutable() bool
- func (m *ApprovalOptions) GetUntilBlockHeight() int64
- func (m *ApprovalOptions) Marshal() (dAtA []byte, err error)
- func (m *ApprovalOptions) MarshalTo(dAtA []byte) (int, error)
- func (*ApprovalOptions) ProtoMessage()
- func (m *ApprovalOptions) Reset()
- func (m *ApprovalOptions) Size() (n int)
- func (m *ApprovalOptions) String() string
- func (m *ApprovalOptions) Unmarshal(dAtA []byte) error
- func (a ApprovalOptions) Validate() error
- type Approvals
- func (m Approvals) Add(action Action, approval Approval) Approvals
- func (m Approvals) AsPersistable() []ActionApprovals
- func (m Approvals) Filter(obsolete Approvals) Approvals
- func (m Approvals) FilterExpired(blockHeight int64) Approvals
- func (m Approvals) ForAction(action Action) Approvals
- func (m Approvals) ForAddress(addr weave.Address) Approvals
- func (m Approvals) Intersect(others Approvals) Approvals
- func (m Approvals) IsEmpty() bool
- func (m Approvals) MergeUsed(used Approvals) Approvals
- func (m Approvals) MetaByAction(action Action) ApprovalMeta
- func (m Approvals) UseCount() Approvals
- func (m Approvals) Validate(actionMaps ...map[Action]int32) error
- type BaseNFT
- type BucketAccess
- type BucketDispatcher
- type Identified
- type NonFungibleToken
- func (m *NonFungibleToken) Approvals() *ApprovalOps
- func (m *NonFungibleToken) Clone() *NonFungibleToken
- func (m *NonFungibleToken) Copy() orm.CloneableData
- func (*NonFungibleToken) Descriptor() ([]byte, []int)
- func (m *NonFungibleToken) GetActionApprovals() []ActionApprovals
- func (m *NonFungibleToken) GetID() []byte
- func (m *NonFungibleToken) GetOwner() []byte
- func (m *NonFungibleToken) HasApproval(actor weave.Address, action Action) bool
- func (m *NonFungibleToken) Marshal() (dAtA []byte, err error)
- func (m *NonFungibleToken) MarshalTo(dAtA []byte) (int, error)
- func (u *NonFungibleToken) OwnerAddress() weave.Address
- func (*NonFungibleToken) ProtoMessage()
- func (m *NonFungibleToken) Reset()
- func (m *NonFungibleToken) SetApprovals(a Approvals)
- func (m *NonFungibleToken) Size() (n int)
- func (m *NonFungibleToken) String() string
- func (m *NonFungibleToken) Unmarshal(dAtA []byte) error
- func (m *NonFungibleToken) Validate() error
- type Owned
- type RemoveApprovalMsg
- func (*RemoveApprovalMsg) Descriptor() ([]byte, []int)
- func (m *RemoveApprovalMsg) GetAddress() []byte
- func (m *RemoveApprovalMsg) GetID() []byte
- func (m *RemoveApprovalMsg) GetT() string
- func (m *RemoveApprovalMsg) Marshal() (dAtA []byte, err error)
- func (m *RemoveApprovalMsg) MarshalTo(dAtA []byte) (int, error)
- func (*RemoveApprovalMsg) Path() string
- func (*RemoveApprovalMsg) ProtoMessage()
- func (m *RemoveApprovalMsg) Reset()
- func (m *RemoveApprovalMsg) Size() (n int)
- func (m *RemoveApprovalMsg) String() string
- func (m *RemoveApprovalMsg) Unmarshal(dAtA []byte) error
- func (m RemoveApprovalMsg) Validate() error
Constants ¶
const ( CodeUnsupportedTokenType uint32 = 500 CodeInvalidID uint32 = 501 CodeDuplicateEntry uint32 = 502 CodeMissingEntry uint32 = 503 CodeInvalidEntry uint32 = 504 CodeUnknownID uint32 = 505 CodeInvalidLength uint32 = 506 CodeInvalidHost uint32 = 507 CodeInvalidPort uint32 = 508 CodeInvalidProtocol uint32 = 509 CodeInvalidCodec uint32 = 510 CodeInvalidJson uint32 = 511 )
nft and subpackages reserves 500~600
const ( PathAddApprovalMsg = "nft/approval/add" PathRemoveApprovalMsg = "nft/approval/remove" )
const OwnerIndexName = "owner"
OwnerIndexName is the index to query nft by owner
const UnlimitedCount = -1
Variables ¶
var ( ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowCodec = fmt.Errorf("proto: integer overflow") )
var DefaultActions = []Action{ UpdateApprovals, UpdateDetails, Transfer, }
DefaultActions lists all the actions that need to be registered for nft to work
Functions ¶
func ErrDuplicateEntry ¶
func ErrInvalidCodec ¶
func ErrInvalidEntry ¶
func ErrInvalidHost ¶
func ErrInvalidHost() error
func ErrInvalidID ¶
func ErrInvalidJson ¶
func ErrInvalidJson() error
func ErrInvalidLength ¶
func ErrInvalidLength() error
func ErrInvalidPort ¶
func ErrInvalidPort() error
func ErrInvalidProtocol ¶
func ErrInvalidProtocol() error
func ErrMissingEntry ¶
func ErrMissingEntry() error
func ErrUnknownID ¶
func ErrUnsupportedTokenType ¶
func ErrUnsupportedTokenType() error
ErrUnsupportedTokenType is when the type passed does not match the expected token type.
func RegisterAction ¶ added in v0.10.1
func RegisterAction(actions ...Action)
RegisterAction introduce an Action to the extension.
Every action must be registered before being used. This is a mandatory step so that the validation process can regcognise known actions. Registration is global. Registration should be done during the program initialization phase. Failed registration result in panic.
Types ¶
type Action ¶
type Action string
Action represents available and supported by the implementation actions. This is just a string type alias, but using it increase the clarity of the API.
type ActionApprovals ¶
type ActionApprovals struct { Action Action `protobuf:"bytes,1,opt,name=action,proto3,customtype=Action" json:"action"` Approvals []Approval `protobuf:"bytes,2,rep,name=approvals" json:"approvals"` }
ActionApprovals are used to control permissions and validate that a user can execute given operation.
func (ActionApprovals) Clone ¶
func (m ActionApprovals) Clone() ActionApprovals
func (*ActionApprovals) Descriptor ¶
func (*ActionApprovals) Descriptor() ([]byte, []int)
func (*ActionApprovals) GetApprovals ¶
func (m *ActionApprovals) GetApprovals() []Approval
func (*ActionApprovals) Marshal ¶
func (m *ActionApprovals) Marshal() (dAtA []byte, err error)
func (*ActionApprovals) ProtoMessage ¶
func (*ActionApprovals) ProtoMessage()
func (*ActionApprovals) Reset ¶
func (m *ActionApprovals) Reset()
func (*ActionApprovals) Size ¶
func (m *ActionApprovals) Size() (n int)
func (*ActionApprovals) String ¶
func (m *ActionApprovals) String() string
func (*ActionApprovals) Unmarshal ¶
func (m *ActionApprovals) Unmarshal(dAtA []byte) error
type AddApprovalMsg ¶
type AddApprovalMsg struct { ID []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Address []byte `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` Action Action `protobuf:"bytes,3,opt,name=action,proto3,customtype=Action" json:"action"` Options ApprovalOptions `protobuf:"bytes,4,opt,name=options" json:"options"` T string `protobuf:"bytes,5,opt,name=t,proto3" json:"t,omitempty"` }
func (*AddApprovalMsg) Descriptor ¶
func (*AddApprovalMsg) Descriptor() ([]byte, []int)
func (*AddApprovalMsg) GetAddress ¶
func (m *AddApprovalMsg) GetAddress() []byte
func (*AddApprovalMsg) GetID ¶ added in v0.10.0
func (m *AddApprovalMsg) GetID() []byte
func (*AddApprovalMsg) GetOptions ¶
func (m *AddApprovalMsg) GetOptions() ApprovalOptions
func (*AddApprovalMsg) GetT ¶
func (m *AddApprovalMsg) GetT() string
func (*AddApprovalMsg) Marshal ¶
func (m *AddApprovalMsg) Marshal() (dAtA []byte, err error)
func (*AddApprovalMsg) Path ¶
func (*AddApprovalMsg) Path() string
func (*AddApprovalMsg) ProtoMessage ¶
func (*AddApprovalMsg) ProtoMessage()
func (*AddApprovalMsg) Reset ¶
func (m *AddApprovalMsg) Reset()
func (*AddApprovalMsg) Size ¶
func (m *AddApprovalMsg) Size() (n int)
func (*AddApprovalMsg) String ¶
func (m *AddApprovalMsg) String() string
func (*AddApprovalMsg) Unmarshal ¶
func (m *AddApprovalMsg) Unmarshal(dAtA []byte) error
func (AddApprovalMsg) Validate ¶
func (m AddApprovalMsg) Validate() error
type Approval ¶
type Approval struct { Address []byte `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` Options ApprovalOptions `protobuf:"bytes,2,opt,name=options" json:"options"` }
func (*Approval) Descriptor ¶
func (*Approval) GetAddress ¶
func (*Approval) GetOptions ¶
func (m *Approval) GetOptions() ApprovalOptions
func (*Approval) ProtoMessage ¶
func (*Approval) ProtoMessage()
type ApprovalMeta ¶
type ApprovalMeta []Approval
func (ApprovalMeta) Clone ¶
func (m ApprovalMeta) Clone() ApprovalMeta
func (ApprovalMeta) Validate ¶
func (m ApprovalMeta) Validate() error
type ApprovalMsg ¶
type ApprovalMsg interface { GetT() string Identified }
type ApprovalOps ¶
type ApprovalOps struct {
// contains filtered or unexported fields
}
func NewApprovalOps ¶
func NewApprovalOps(owner weave.Address, approvals *[]ActionApprovals) *ApprovalOps
TODO: Sort errors and their codes TODO: Figure out what we need to do with counts for the next iteration
func (*ApprovalOps) Grant ¶
func (o *ApprovalOps) Grant(action Action, to weave.Address, op ApprovalOptions, blockHeight int64, actionMaps ...map[Action]int32) error
TODO: Figure out whether we need wildcard approvals, might be wise to add an ApprovalOptions flag
func (*ApprovalOps) List ¶
func (o *ApprovalOps) List() Approvals
type ApprovalOptions ¶
type ApprovalOptions struct { // Until block height is used to mark blochain height until which an // approval is valid. This can be used to define an approval expiration. UntilBlockHeight int64 `protobuf:"varint,1,opt,name=until_block_height,json=untilBlockHeight,proto3" json:"until_block_height,omitempty"` // Count is defining how many times an approval can be used. Each approval // test decrese the counter. Once the counter reaches value 0, an approval // is considered expired and can no longer be used. // Use -1 to bypass count expiration. Count int64 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` // Immutable is a flag that prevents an option to be modified. Once // created, cannot be altered. For example, counter state cannot be // changed. Immutable bool `protobuf:"varint,3,opt,name=immutable,proto3" json:"immutable,omitempty"` }
func (*ApprovalOptions) Descriptor ¶
func (*ApprovalOptions) Descriptor() ([]byte, []int)
func (ApprovalOptions) Equals ¶
func (a ApprovalOptions) Equals(o ApprovalOptions) bool
func (ApprovalOptions) EqualsAfterUse ¶ added in v0.9.1
func (a ApprovalOptions) EqualsAfterUse(used ApprovalOptions) bool
func (*ApprovalOptions) GetCount ¶
func (m *ApprovalOptions) GetCount() int64
func (*ApprovalOptions) GetImmutable ¶
func (m *ApprovalOptions) GetImmutable() bool
func (*ApprovalOptions) GetUntilBlockHeight ¶
func (m *ApprovalOptions) GetUntilBlockHeight() int64
func (*ApprovalOptions) Marshal ¶
func (m *ApprovalOptions) Marshal() (dAtA []byte, err error)
func (*ApprovalOptions) ProtoMessage ¶
func (*ApprovalOptions) ProtoMessage()
func (*ApprovalOptions) Reset ¶
func (m *ApprovalOptions) Reset()
func (*ApprovalOptions) Size ¶
func (m *ApprovalOptions) Size() (n int)
func (*ApprovalOptions) String ¶
func (m *ApprovalOptions) String() string
func (*ApprovalOptions) Unmarshal ¶
func (m *ApprovalOptions) Unmarshal(dAtA []byte) error
func (ApprovalOptions) Validate ¶
func (a ApprovalOptions) Validate() error
type Approvals ¶
type Approvals map[Action]ApprovalMeta
func (Approvals) AsPersistable ¶
func (m Approvals) AsPersistable() []ActionApprovals
func (Approvals) FilterExpired ¶
func (Approvals) MetaByAction ¶
func (m Approvals) MetaByAction(action Action) ApprovalMeta
type BaseNFT ¶
type BaseNFT interface { Owned //GetId() []byte Approvals() *ApprovalOps //Set new approvals SetApprovals(Approvals) }
type BucketAccess ¶
type BucketAccess interface { Get(db weave.ReadOnlyKVStore, key []byte) (orm.Object, error) Save(db weave.KVStore, model orm.Object) error }
TODO: Better name?
type BucketDispatcher ¶
type BucketDispatcher interface { Register(t string, bucket BucketAccess) error AssertRegistered(types ...string) Get(t string) (BucketAccess, error) }
func GetBucketDispatcher ¶
func GetBucketDispatcher() BucketDispatcher
TODO: if we ever want to support concurrency here then we might be better of with a separate Init() method or similar
type NonFungibleToken ¶
type NonFungibleToken struct { // ID is the address of this token. ID []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // Owner is the address of the token owner. Owner []byte `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"` // Action approvals is a list of permissions. In order for operation to // succeed, all action approvals validation must pass. ActionApprovals []ActionApprovals `protobuf:"bytes,3,rep,name=action_approvals,json=actionApprovals" json:"action_approvals"` }
NonFungibleToken is a message that must be incuded by any concrete NFT implementation. Usually it is the first attirbute called `base`.
func NewNonFungibleToken ¶
func NewNonFungibleToken(key []byte, owner weave.Address, approvals []ActionApprovals) *NonFungibleToken
func (*NonFungibleToken) Approvals ¶
func (m *NonFungibleToken) Approvals() *ApprovalOps
func (*NonFungibleToken) Clone ¶
func (m *NonFungibleToken) Clone() *NonFungibleToken
func (*NonFungibleToken) Copy ¶
func (m *NonFungibleToken) Copy() orm.CloneableData
func (*NonFungibleToken) Descriptor ¶
func (*NonFungibleToken) Descriptor() ([]byte, []int)
func (*NonFungibleToken) GetActionApprovals ¶
func (m *NonFungibleToken) GetActionApprovals() []ActionApprovals
func (*NonFungibleToken) GetID ¶ added in v0.10.0
func (m *NonFungibleToken) GetID() []byte
func (*NonFungibleToken) GetOwner ¶
func (m *NonFungibleToken) GetOwner() []byte
func (*NonFungibleToken) HasApproval ¶
func (m *NonFungibleToken) HasApproval(actor weave.Address, action Action) bool
func (*NonFungibleToken) Marshal ¶
func (m *NonFungibleToken) Marshal() (dAtA []byte, err error)
func (*NonFungibleToken) OwnerAddress ¶
func (u *NonFungibleToken) OwnerAddress() weave.Address
func (*NonFungibleToken) ProtoMessage ¶
func (*NonFungibleToken) ProtoMessage()
func (*NonFungibleToken) Reset ¶
func (m *NonFungibleToken) Reset()
func (*NonFungibleToken) SetApprovals ¶ added in v0.9.1
func (m *NonFungibleToken) SetApprovals(a Approvals)
func (*NonFungibleToken) Size ¶
func (m *NonFungibleToken) Size() (n int)
func (*NonFungibleToken) String ¶
func (m *NonFungibleToken) String() string
func (*NonFungibleToken) Unmarshal ¶
func (m *NonFungibleToken) Unmarshal(dAtA []byte) error
func (*NonFungibleToken) Validate ¶
func (m *NonFungibleToken) Validate() error
type RemoveApprovalMsg ¶
type RemoveApprovalMsg struct { ID []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Address []byte `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` Action Action `protobuf:"bytes,3,opt,name=action,proto3,customtype=Action" json:"action"` T string `protobuf:"bytes,4,opt,name=t,proto3" json:"t,omitempty"` }
func (*RemoveApprovalMsg) Descriptor ¶
func (*RemoveApprovalMsg) Descriptor() ([]byte, []int)
func (*RemoveApprovalMsg) GetAddress ¶
func (m *RemoveApprovalMsg) GetAddress() []byte
func (*RemoveApprovalMsg) GetID ¶ added in v0.10.0
func (m *RemoveApprovalMsg) GetID() []byte
func (*RemoveApprovalMsg) GetT ¶
func (m *RemoveApprovalMsg) GetT() string
func (*RemoveApprovalMsg) Marshal ¶
func (m *RemoveApprovalMsg) Marshal() (dAtA []byte, err error)
func (*RemoveApprovalMsg) MarshalTo ¶
func (m *RemoveApprovalMsg) MarshalTo(dAtA []byte) (int, error)
func (*RemoveApprovalMsg) Path ¶
func (*RemoveApprovalMsg) Path() string
func (*RemoveApprovalMsg) ProtoMessage ¶
func (*RemoveApprovalMsg) ProtoMessage()
func (*RemoveApprovalMsg) Reset ¶
func (m *RemoveApprovalMsg) Reset()
func (*RemoveApprovalMsg) Size ¶
func (m *RemoveApprovalMsg) Size() (n int)
func (*RemoveApprovalMsg) String ¶
func (m *RemoveApprovalMsg) String() string
func (*RemoveApprovalMsg) Unmarshal ¶
func (m *RemoveApprovalMsg) Unmarshal(dAtA []byte) error
func (RemoveApprovalMsg) Validate ¶
func (m RemoveApprovalMsg) Validate() error