coin

package
v4.13.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Amount

type Amount struct {
	// contains filtered or unexported fields
}

Amount represents an amount in the smallest coin unit (e.g. satoshi).

func NewAmount

func NewAmount(amount *big.Int) Amount

NewAmount creates a new amount.

func NewAmountFromInt64

func NewAmountFromInt64(amount int64) Amount

NewAmountFromInt64 creates a new amount.

func NewAmountFromString

func NewAmountFromString(s string, unit *big.Int) (Amount, error)

NewAmountFromString parses a user given coin amount, converting it from the default coin unit to the the smallest unit.

func (Amount) BigInt

func (amount Amount) BigInt() *big.Int

BigInt returns a copy of the underlying big integer.

func (Amount) Int64

func (amount Amount) Int64() (int64, error)

Int64 returns the int64 representation of amount. If x cannot be represented in an int64, an error is returned.

type Coin

type Coin interface {
	observable.Interface

	// Code returns the code used to identify the coin (should be the acronym of the coin in
	// lowercase).
	Code() string

	// Unit is the unit code for formatting amounts, e.g. "BTC".
	// The fee unit is usually the same as the main unit, but can differ.
	Unit(isFee bool) string

	// Number of decimal places in the standard unit, e.g. 8 for Bitcoin. Must be in the range
	// [0..31].
	Decimals(isFee bool) uint

	// FormatAmount formats the given amount as a number.
	FormatAmount(amount Amount, isFee bool) string

	// ToUnit returns the given amount in the unit as returned above.
	ToUnit(amount Amount, isFee bool) float64

	// BlockExplorerTransactionURLPrefix returns the URL prefix of the block explorer.
	BlockExplorerTransactionURLPrefix() string

	// Initialize initializes the coin by connecting to a full node, downloading the headers, etc.
	Initialize()

	// SmallestUnit returns the name of the smallest unit of a given coin
	SmallestUnit() string
}

Coin models the currency of a blockchain.

type SendAmount

type SendAmount struct {
	// contains filtered or unexported fields
}

SendAmount is either a concrete amount, or "all"/"max". The concrete amount is user input and is parsed/validated in Amount().

func NewSendAmount

func NewSendAmount(amount string) SendAmount

NewSendAmount creates a new SendAmount based on a concrete amount.

func NewSendAmountAll

func NewSendAmountAll() SendAmount

NewSendAmountAll creates a new Sendall-amount.

func (SendAmount) Amount

func (sendAmount SendAmount) Amount(unit *big.Int, allowZero bool) (Amount, error)

Amount parses the amount and converts it from the default unit to the smallest unit (e.g. satoshi = 1e8). Returns an error if the amount is negative, or depending on allowZero, if it is zero.

func (*SendAmount) SendAll

func (sendAmount *SendAmount) SendAll() bool

SendAll returns if this represents a send-all input.

Jump to

Keyboard shortcuts

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