token

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigQuantity

type BigQuantity struct {
	*big.Int
	Precision uint64
}

func NewUBigQuantity

func NewUBigQuantity(q string, precision uint64) (*BigQuantity, error)

func (*BigQuantity) Add

func (q *BigQuantity) Add(b Quantity) Quantity

func (*BigQuantity) Cmp

func (q *BigQuantity) Cmp(b Quantity) int

Cmp compares x and y and returns:

-1 if x <  y
 0 if x == y
+1 if x >  y

func (*BigQuantity) Decimal

func (q *BigQuantity) Decimal() string

func (*BigQuantity) Hex

func (q *BigQuantity) Hex() string

func (*BigQuantity) String

func (q *BigQuantity) String() string

func (*BigQuantity) Sub

func (q *BigQuantity) Sub(b Quantity) Quantity

func (*BigQuantity) ToBigInt

func (q *BigQuantity) ToBigInt() *big.Int

type ID

type ID struct {
	// TxId is the transaction ID of the transaction that created the token
	TxId string `protobuf:"bytes,1,opt,name=tx_id,json=txId,proto3" json:"tx_id,omitempty"`
	// Index is the index of the token in the transaction that created it
	Index uint64 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"`
}

ID identifies a token as a function of the identifier of the transaction (issue, transfer) that created it and its index in that transaction

func (*ID) String

func (id *ID) String() string

type IssuedToken

type IssuedToken struct {
	// Id is used to uniquely identify the token in the ledger
	Id *ID `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// Owner is the token owner
	Owner *Owner `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
	// Type is the type of the token
	Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
	// Quantity represents the number of units of Type that this unspent token holds.
	// It is formatted in decimal representation
	Quantity string `protobuf:"bytes,3,opt,name=quantity,proto3" json:"quantity,omitempty"`

	Issuer *Owner
}

type IssuedTokens

type IssuedTokens struct {
	// Tokens is an array of UnspentToken
	Tokens []*IssuedToken `protobuf:"bytes,1,rep,name=tokens,proto3" json:"tokens,omitempty"`
}

func (*IssuedTokens) ByType

func (it *IssuedTokens) ByType(typ string) *IssuedTokens

func (*IssuedTokens) Count

func (it *IssuedTokens) Count() int

func (*IssuedTokens) Sum

func (it *IssuedTokens) Sum(precision uint64) Quantity

type Owner

type Owner struct {
	// Raw is the serialization of the identity
	Raw []byte `protobuf:"bytes,2,opt,name=raw,proto3" json:"raw,omitempty"`
}

Owner holds the identity of a token owner

type Quantity

type Quantity interface {

	// Add returns this + b modifying this.
	// If an overflow occurs, it returns an error.
	Add(b Quantity) Quantity

	// Sub returns this - b modifying this.
	// If an overflow occurs, it returns an error.
	Sub(b Quantity) Quantity

	// Cmp compares this and b and returns:
	//
	//   -1 if this <  b
	//    0 if this == b
	//   +1 if this >  b
	//
	Cmp(b Quantity) int

	// Hex returns the hexadecimal representation of this quantity
	Hex() string

	// Decimal returns the decimal representation of this quantity
	Decimal() string

	// ToBigInt returns the big int representation of this quantity
	ToBigInt() *big.Int
}

Quantity models an immutable token quantity and its basic operations.

func NewOneQuantity

func NewOneQuantity(precision uint64) Quantity

func NewQuantityFromUInt64

func NewQuantityFromUInt64(q uint64) Quantity

func NewZeroQuantity

func NewZeroQuantity(precision uint64) Quantity

NewZeroQuantity returns to zero quantity at the passed precision/ The precision is expressed in bits.

func ToQuantity

func ToQuantity(q string, precision uint64) (Quantity, error)

ToQuantity converts a string q to a Quantity of a given precision. Argument q is supposed to be formatted following big.Int#scan specification. The precision is expressed in bits.

func UInt64ToQuantity

func UInt64ToQuantity(u uint64, precision uint64) (Quantity, error)

UInt64ToQuantity converts a uint64 q to a Quantity of a given precision. Argument q is supposed to be formatted following big.Int#scan specification. The precision is expressed in bits.

type Token

type Token struct {
	// Owner is the token owner
	Owner *Owner `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
	// Type is the type of the token
	Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
	// Quantity is the number of units of Type carried in the token.
	// It is encoded as a string containing a number in base 16. The string has prefix “0x”.
	Quantity string `protobuf:"bytes,3,opt,name=quantity,proto3" json:"quantity,omitempty"`
}

Token is the result of issue and transfer transactions

type UInt64Quantity

type UInt64Quantity struct {
	Value uint64
}

func (*UInt64Quantity) Add

func (q *UInt64Quantity) Add(b Quantity) Quantity

func (*UInt64Quantity) Cmp

func (q *UInt64Quantity) Cmp(b Quantity) int

func (*UInt64Quantity) Decimal

func (q *UInt64Quantity) Decimal() string

func (*UInt64Quantity) Hex

func (q *UInt64Quantity) Hex() string

func (*UInt64Quantity) Sub

func (q *UInt64Quantity) Sub(b Quantity) Quantity

func (*UInt64Quantity) ToBigInt

func (q *UInt64Quantity) ToBigInt() *big.Int

type UnspentToken

type UnspentToken struct {
	// Id is used to uniquely identify the token in the ledger
	Id *ID
	// Owner is the token owner
	Owner *Owner
	// Type is the type of the token
	Type string
	// Quantity represents the number of units of Type that this unspent token holds.
	Quantity string
}

UnspentToken is used to specify a token returned by ListRequest

type UnspentTokens

type UnspentTokens struct {
	// Tokens is an array of UnspentToken
	Tokens []*UnspentToken `protobuf:"bytes,1,rep,name=tokens,proto3" json:"tokens,omitempty"`
}

UnspentTokens is used to hold the output of ListRequest

func (*UnspentTokens) At

func (it *UnspentTokens) At(i int) *UnspentToken

At returns the unspent token at position i. No boundary checks are performed.

func (*UnspentTokens) ByType

func (it *UnspentTokens) ByType(typ string) *UnspentTokens

func (*UnspentTokens) Count

func (it *UnspentTokens) Count() int

func (*UnspentTokens) Sum

func (it *UnspentTokens) Sum(precision uint64) Quantity

Jump to

Keyboard shortcuts

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