token

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToQuantitySum

func ToQuantitySum(precision uint64) iterators.Reducer[*UnspentToken, Quantity]

ToQuantitySum computes the sum of the quantities of the tokens in the iterator.

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, error)

func (*BigQuantity) Clone

func (q *BigQuantity) Clone() 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, error)

func (*BigQuantity) ToBigInt

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

type Format

type Format string

Format is the encoding of a token on the ledger, e.g. fabtoken, comm. It is a many-to-many relationship with the token driver, i.e. a token driver can support multiple formats (e.g. fabtoken1, fabtoken2), but a format can also be supported by multiple drivers (e.g. zkat, zkatlog).

type ID

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

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

func (id ID) Equal(right ID) bool

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 `json:"id" protobuf:"bytes,1,opt,name=id,proto3"`
	// Owner is the token owner
	Owner []byte `json:"owner,omitempty" protobuf:"bytes,1,opt,name=owner,proto3"`
	// Type is the type of the token
	Type Type `json:"type,omitempty" protobuf:"bytes,2,opt,name=type,proto3"`
	// Quantity represents the number of units of Type that this unspent token holds.
	// It is formatted in decimal representation
	Quantity string `json:"quantity,omitempty" protobuf:"bytes,3,opt,name=quantity,proto3"`
	// Issuer is the issuer of this token
	Issuer []byte
}

type IssuedTokens

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

func (*IssuedTokens) ByType

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

func (*IssuedTokens) Count

func (it *IssuedTokens) Count() int

func (*IssuedTokens) Sum

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

type LedgerToken

type LedgerToken struct {
	// ID is used to uniquely identify the token in the ledger
	ID            ID
	Format        Format
	Token         []byte
	TokenMetadata []byte
}

func (LedgerToken) Equal

func (t LedgerToken) Equal(right LedgerToken) bool

type Quantity

type Quantity interface {

	// Add returns a new Quantity whose value is this + b.
	// It returns an error on type mismatch or overflow.
	Add(b Quantity) (Quantity, error)

	// Sub returns a new Quantity whose value is this - b.
	// It returns an error on type mismatch or underflow.
	Sub(b Quantity) (Quantity, error)

	// 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

	// Clone returns a deep copy of this quantity
	Clone() Quantity
}

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#scan specification. The precision is expressed in bits.

func UInt64ToQuantity

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

UInt64ToQuantity converts an uint64 q to a Quantity of a given precision. The precision is expressed in bits.

type Token

type Token struct {
	// Owner is the token owner
	Owner []byte `json:"owner,omitempty" protobuf:"bytes,1,opt,name=owner,proto3"`
	// Type is the type of the token
	Type Type `json:"type,omitempty" protobuf:"bytes,2,opt,name=type,proto3"`
	// Quantity is the number of units of Type carried in the token.
	// It is encoded as a string containing a non-negative integer. The value is parsed
	// with big.Int base-0 auto-detection, so the base is inferred from the string's prefix:
	// decimal by default, hexadecimal with a "0x"/"0X" prefix, octal with a "0o"/"0O" prefix
	// (or a leading "0"), and binary with a "0b"/"0B" prefix.
	Quantity string `json:"quantity,omitempty" protobuf:"bytes,3,opt,name=quantity,proto3"`
}

Token is the result of issue and transfer transactions

func (*Token) Clone added in v0.18.0

func (t *Token) Clone() *Token

Clone returns a full, independent copy of the token. The returned token shares no mutable state with the receiver: the Owner byte slice is copied, so mutating either token's Owner (or replacing any field) does not affect the other. Type and Quantity are strings and are therefore immutable.

type Type

type Type string

Type is the currency, e.g. USD

type UInt64Quantity

type UInt64Quantity struct {
	Value uint64
}

func (*UInt64Quantity) Add

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

func (*UInt64Quantity) Clone

func (q *UInt64Quantity) Clone() 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, error)

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 []byte
	// Type is the type of the token
	Type Type
	// Quantity represents the number of units of Type that this unspent token holds.
	Quantity string
}

UnspentToken models an unspent token

func (UnspentToken) String

func (ut UnspentToken) String() string

type UnspentTokenInWallet

type UnspentTokenInWallet struct {
	// Id is used to uniquely identify the token in the ledger
	Id ID
	// WalletID is the ID of the wallet owning this token
	WalletID string
	// Type is the type of the token
	Type Type
	// Quantity represents the number of units of Type that this unspent token holds.
	Quantity string
}

UnspentTokenInWallet models an unspent token owner solely by a given wallet

type UnspentTokens

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

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 Type) *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