nft

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

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

View Source
const (
	PathAddApprovalMsg    = "nft/approval/add"
	PathRemoveApprovalMsg = "nft/approval/remove"
)
View Source
const OwnerIndexName = "owner"

OwnerIndexName is the index to query nft by owner

View Source
const UnlimitedCount = -1
View Source
const (
	UnsupportedTokenType = "unsupported token type"
)

Variables

View Source
var (
	ErrInvalidLengthCodec = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCodec   = fmt.Errorf("proto: integer overflow")
)

DefaultActions lists all the actions that need to be registered for nft to work

Functions

func FindActor

func FindActor(auth x.Authenticator, ctx weave.Context, t BaseNFT, action Action) weave.Address

func PrintableID added in v0.12.0

func PrintableID(id []byte) string

id's are stored as bytes, but most are ascii text if in ascii, just convert to string if not, hex-encode it and prefix with 0x

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 recognise known actions. Registration is global. Registration should be done during the program initialization phase. Failed registration result in panic.

func WithOwnerIndex

func WithOwnerIndex(bucket orm.Bucket) orm.Bucket

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.

const (
	UpdateDetails   Action = "ActionUpdateDetails"
	Transfer        Action = "ActionTransfer"
	UpdateApprovals Action = "ActionUpdateApprovals"
)

nft package provides default set of actions.

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,proto3" 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) MarshalTo

func (m *ActionApprovals) MarshalTo(dAtA []byte) (int, 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

func (*ActionApprovals) XXX_DiscardUnknown added in v0.12.0

func (m *ActionApprovals) XXX_DiscardUnknown()

func (*ActionApprovals) XXX_Marshal added in v0.12.0

func (m *ActionApprovals) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ActionApprovals) XXX_Merge added in v0.12.0

func (m *ActionApprovals) XXX_Merge(src proto.Message)

func (*ActionApprovals) XXX_Size added in v0.12.0

func (m *ActionApprovals) XXX_Size() int

func (*ActionApprovals) XXX_Unmarshal added in v0.12.0

func (m *ActionApprovals) XXX_Unmarshal(b []byte) error

type AddApprovalMsg

type AddApprovalMsg struct {
	Metadata *weave.Metadata                  `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	ID       []byte                           `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	Address  github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=address,proto3,casttype=github.com/iov-one/weave.Address" json:"address,omitempty"`
	Action   Action                           `protobuf:"bytes,4,opt,name=action,proto3,customtype=Action" json:"action"`
	Options  ApprovalOptions                  `protobuf:"bytes,5,opt,name=options,proto3" json:"options"`
	T        string                           `protobuf:"bytes,6,opt,name=t,proto3" json:"t,omitempty"`
}

func (*AddApprovalMsg) Descriptor

func (*AddApprovalMsg) Descriptor() ([]byte, []int)

func (*AddApprovalMsg) GetAddress

func (*AddApprovalMsg) GetID added in v0.10.0

func (m *AddApprovalMsg) GetID() []byte

func (*AddApprovalMsg) GetMetadata added in v0.15.0

func (m *AddApprovalMsg) GetMetadata() *weave.Metadata

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) MarshalTo

func (m *AddApprovalMsg) MarshalTo(dAtA []byte) (int, 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

func (*AddApprovalMsg) XXX_DiscardUnknown added in v0.12.0

func (m *AddApprovalMsg) XXX_DiscardUnknown()

func (*AddApprovalMsg) XXX_Marshal added in v0.12.0

func (m *AddApprovalMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*AddApprovalMsg) XXX_Merge added in v0.12.0

func (m *AddApprovalMsg) XXX_Merge(src proto.Message)

func (*AddApprovalMsg) XXX_Size added in v0.12.0

func (m *AddApprovalMsg) XXX_Size() int

func (*AddApprovalMsg) XXX_Unmarshal added in v0.12.0

func (m *AddApprovalMsg) XXX_Unmarshal(b []byte) 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,proto3" json:"options"`
}

func (Approval) AsAddress

func (a Approval) AsAddress() weave.Address

func (Approval) Clone

func (m Approval) Clone() Approval

func (*Approval) Descriptor

func (*Approval) Descriptor() ([]byte, []int)

func (Approval) Equals

func (a Approval) Equals(o Approval) bool

func (*Approval) GetAddress

func (m *Approval) GetAddress() []byte

func (*Approval) GetOptions

func (m *Approval) GetOptions() ApprovalOptions

func (*Approval) Marshal

func (m *Approval) Marshal() (dAtA []byte, err error)

func (*Approval) MarshalTo

func (m *Approval) MarshalTo(dAtA []byte) (int, error)

func (*Approval) ProtoMessage

func (*Approval) ProtoMessage()

func (*Approval) Reset

func (m *Approval) Reset()

func (*Approval) Size

func (m *Approval) Size() (n int)

func (*Approval) String

func (m *Approval) String() string

func (*Approval) Unmarshal

func (m *Approval) Unmarshal(dAtA []byte) error

func (Approval) Validate

func (m Approval) Validate() error

func (*Approval) XXX_DiscardUnknown added in v0.12.0

func (m *Approval) XXX_DiscardUnknown()

func (*Approval) XXX_Marshal added in v0.12.0

func (m *Approval) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Approval) XXX_Merge added in v0.12.0

func (m *Approval) XXX_Merge(src proto.Message)

func (*Approval) XXX_Size added in v0.12.0

func (m *Approval) XXX_Size() int

func (*Approval) XXX_Unmarshal added in v0.12.0

func (m *Approval) XXX_Unmarshal(b []byte) error

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

func (*ApprovalOps) Revoke

func (o *ApprovalOps) Revoke(action Action, from weave.Address) error

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) MarshalTo

func (m *ApprovalOptions) MarshalTo(dAtA []byte) (int, 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

func (*ApprovalOptions) XXX_DiscardUnknown added in v0.12.0

func (m *ApprovalOptions) XXX_DiscardUnknown()

func (*ApprovalOptions) XXX_Marshal added in v0.12.0

func (m *ApprovalOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ApprovalOptions) XXX_Merge added in v0.12.0

func (m *ApprovalOptions) XXX_Merge(src proto.Message)

func (*ApprovalOptions) XXX_Size added in v0.12.0

func (m *ApprovalOptions) XXX_Size() int

func (*ApprovalOptions) XXX_Unmarshal added in v0.12.0

func (m *ApprovalOptions) XXX_Unmarshal(b []byte) error

type Approvals

type Approvals map[Action]ApprovalMeta

func (Approvals) Add

func (m Approvals) Add(action Action, approval Approval) Approvals

func (Approvals) AsPersistable

func (m Approvals) AsPersistable() []ActionApprovals

func (Approvals) Filter

func (m Approvals) Filter(obsolete Approvals) Approvals

func (Approvals) FilterExpired

func (m Approvals) FilterExpired(blockHeight int64) Approvals

func (Approvals) ForAction

func (m Approvals) ForAction(action Action) Approvals

func (Approvals) ForAddress

func (m Approvals) ForAddress(addr weave.Address) Approvals

func (Approvals) Intersect added in v0.9.1

func (m Approvals) Intersect(others Approvals) Approvals

func (Approvals) IsEmpty

func (m Approvals) IsEmpty() bool

func (Approvals) MergeUsed added in v0.9.1

func (m Approvals) MergeUsed(used Approvals) Approvals

func (Approvals) MetaByAction

func (m Approvals) MetaByAction(action Action) ApprovalMeta

func (Approvals) UseCount added in v0.9.1

func (m Approvals) UseCount() Approvals

func (Approvals) Validate

func (m Approvals) Validate(actionMaps ...map[Action]int32) error

This requires all the model-specific actions to be passed here TODO: Not sure I'm a fan of array of maps, but it makes sense given we validate using protobuf enum value maps

type BaseNFT

type BaseNFT interface {
	Owned
	//GetId() []byte
	Approvals() *ApprovalOps
	//Set new approvals
	SetApprovals(Approvals)
}

type Identified

type Identified interface {
	GetID() []byte
}

TODO: Better name

type NonFungibleToken

type NonFungibleToken struct {
	Metadata *weave.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// ID is the address of this token.
	ID []byte `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	// Owner is the address of the token owner.
	Owner github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=owner,proto3,casttype=github.com/iov-one/weave.Address" 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,4,rep,name=action_approvals,json=actionApprovals,proto3" 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 (*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) GetMetadata added in v0.15.0

func (m *NonFungibleToken) GetMetadata() *weave.Metadata

func (*NonFungibleToken) GetOwner

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) MarshalTo

func (m *NonFungibleToken) MarshalTo(dAtA []byte) (int, 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

func (*NonFungibleToken) XXX_DiscardUnknown added in v0.12.0

func (m *NonFungibleToken) XXX_DiscardUnknown()

func (*NonFungibleToken) XXX_Marshal added in v0.12.0

func (m *NonFungibleToken) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NonFungibleToken) XXX_Merge added in v0.12.0

func (m *NonFungibleToken) XXX_Merge(src proto.Message)

func (*NonFungibleToken) XXX_Size added in v0.12.0

func (m *NonFungibleToken) XXX_Size() int

func (*NonFungibleToken) XXX_Unmarshal added in v0.12.0

func (m *NonFungibleToken) XXX_Unmarshal(b []byte) error

type Owned

type Owned interface {
	OwnerAddress() weave.Address
}

type RemoveApprovalMsg

type RemoveApprovalMsg struct {
	Metadata *weave.Metadata                  `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata,omitempty"`
	ID       []byte                           `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	Address  github_com_iov_one_weave.Address `protobuf:"bytes,3,opt,name=address,proto3,casttype=github.com/iov-one/weave.Address" json:"address,omitempty"`
	Action   Action                           `protobuf:"bytes,4,opt,name=action,proto3,customtype=Action" json:"action"`
	T        string                           `protobuf:"bytes,5,opt,name=t,proto3" json:"t,omitempty"`
}

func (*RemoveApprovalMsg) Descriptor

func (*RemoveApprovalMsg) Descriptor() ([]byte, []int)

func (*RemoveApprovalMsg) GetAddress

func (*RemoveApprovalMsg) GetID added in v0.10.0

func (m *RemoveApprovalMsg) GetID() []byte

func (*RemoveApprovalMsg) GetMetadata added in v0.15.0

func (m *RemoveApprovalMsg) GetMetadata() *weave.Metadata

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

func (*RemoveApprovalMsg) XXX_DiscardUnknown added in v0.12.0

func (m *RemoveApprovalMsg) XXX_DiscardUnknown()

func (*RemoveApprovalMsg) XXX_Marshal added in v0.12.0

func (m *RemoveApprovalMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RemoveApprovalMsg) XXX_Merge added in v0.12.0

func (m *RemoveApprovalMsg) XXX_Merge(src proto.Message)

func (*RemoveApprovalMsg) XXX_Size added in v0.12.0

func (m *RemoveApprovalMsg) XXX_Size() int

func (*RemoveApprovalMsg) XXX_Unmarshal added in v0.12.0

func (m *RemoveApprovalMsg) XXX_Unmarshal(b []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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