v0.2202.11 Latest Latest

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 3 Imported by: 54




This section is empty.


View Source
var (
	// ErrInvalidQuantity is the error returned on malformed arguments.
	ErrInvalidQuantity = errors.New("invalid quantity")

	// ErrInsufficientBalance is the error returned when an operation
	// fails due to insufficient balance.
	ErrInsufficientBalance = errors.New("insufficient balance")

	// ErrInvalidAccount is the error returned when an operation fails
	// due to a missing account.
	ErrInvalidAccount = errors.New("invalid account")


func Move

func Move(dst, src, n *Quantity) error

Move moves exactly n from src to dst. On failures neither src nor dst are altered.


type Quantity

type Quantity struct {
	// contains filtered or unexported fields

Quantity is a arbitrary precision unsigned integer that never underflows.

func MoveUpTo

func MoveUpTo(dst, src, n *Quantity) (*Quantity, error)

MoveUpTo moves up to n from src to dst, and returns the amount moved. On failures neither src nor dst are altered.

func NewFromUint64

func NewFromUint64(n uint64) *Quantity

NewFromUint64 creates a new Quantity from an uint64 or panics.

func NewQuantity

func NewQuantity() (q *Quantity)

NewQuantity creates a new Quantity, initialized to zero.

func (*Quantity) Add

func (q *Quantity) Add(n *Quantity) error

Add adds n to q, returning an error if n < 0 or n == nil.

func (*Quantity) Clone

func (q *Quantity) Clone() *Quantity

Clone copies a Quantity.

func (*Quantity) Cmp

func (q *Quantity) Cmp(n *Quantity) int

Cmp returns -1 if q < n, 0 if q == n, and 1 if q > n.

func (*Quantity) FromBigInt

func (q *Quantity) FromBigInt(n *big.Int) error

FromBigInt converts from a big.Int to a Quantity.

func (*Quantity) FromInt64

func (q *Quantity) FromInt64(n int64) error

FromInt64 converts from an int64 to a Quantity.

func (*Quantity) FromUint64

func (q *Quantity) FromUint64(n uint64) error

FromUint64 converts from an uint64 to a Quantity.

func (*Quantity) IsValid

func (q *Quantity) IsValid() bool

IsValid returns true iff the quantity is in the valid range.

func (*Quantity) IsZero

func (q *Quantity) IsZero() bool

IsZero returns true iff the quantity is zero.

func (*Quantity) MarshalBinary

func (q *Quantity) MarshalBinary() ([]byte, error)

MarshalBinary encodes a Quantity into binary form.

func (Quantity) MarshalText

func (q Quantity) MarshalText() ([]byte, error)

MarshalText encodes a Quantity into text form.

func (*Quantity) Mul

func (q *Quantity) Mul(n *Quantity) error

Mul multiplies n with q, returning an error if n < 0 or n == nil.

func (*Quantity) Quo

func (q *Quantity) Quo(n *Quantity) error

Quo divides q with n, returning an error if n <= 0 or n == nil.

func (Quantity) String

func (q Quantity) String() string

String returns the string representation of q.

func (*Quantity) Sub

func (q *Quantity) Sub(n *Quantity) error

Sub subtracts exactly n from q, returning an error if q < n, n < 0 or n == nil.

func (*Quantity) SubUpTo

func (q *Quantity) SubUpTo(n *Quantity) (*Quantity, error)

SubUpTo subtracts up to n from q, and returns the amount subtracted, returning an error if n < 0 or n == nil.

func (*Quantity) ToBigInt

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

ToBigInt converts from a Quantity to a big.Int.

func (*Quantity) UnmarshalBinary

func (q *Quantity) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a byte slice into a Quantity.

func (*Quantity) UnmarshalText

func (q *Quantity) UnmarshalText(text []byte) error

UnmarshalText decodes a text slice into a Quantity.

Jump to

Keyboard shortcuts

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