coin

package
v4.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2018 License: Apache-2.0 Imports: 5 Imported by: 42

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAddress is used when the recipient address is invalid or does not match the correct
	// network.
	ErrInvalidAddress = TxValidationError("invalidAddress")
	// ErrInvalidAmount is used when the user entered amount is malformatted or not positive.
	ErrInvalidAmount = TxValidationError("invalidAmount")
	// ErrInvalidData is used when the user entered data is not hexadecimal.
	ErrInvalidData = TxValidationError("invalidData")
	// ErrInsufficientFunds is returned when there are not enough funds to cover the target amount
	// and fee.
	ErrInsufficientFunds = TxValidationError("insufficientFunds")
)

Functions

This section is empty.

Types

type Address

type Address interface {
	// ID is an identifier for the address.
	ID() string
	EncodeForHumans() string
}

Address models a blockchain address to which coins can be sent.

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 Balance

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

Balance contains the available and incoming balance of an account.

func NewBalance

func NewBalance(available Amount, incoming Amount) *Balance

NewBalance creates a new balance with the given amounts.

func (*Balance) Available

func (balance *Balance) Available() Amount

Available returns the sum of all unspent coins in the account. The amounts of unconfirmed outgoing transfers are no longer included (but their change is).

func (*Balance) Incoming

func (balance *Balance) Incoming() Amount

Incoming returns the sum of all unconfirmed transfers coming into the account.

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 of the string for formatting amounts.
	Unit() string

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

	// ToUnit returns the given amount in the unit as returned above.
	ToUnit(Amount) 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()
}

Coin models the currency of a blockchain.

type ProposedTransaction

type ProposedTransaction interface {
}

ProposedTransaction models a proposed but not yet fully signed transaction of the given coin.

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.

type Transaction

type Transaction interface {
	// Fee is nil for a receiving tx. The fee is only displayed (and relevant) when sending funds
	// from the wallet.
	Fee() *Amount

	// Time of confirmation. nil for unconfirmed tx or when the headers are not synced yet.
	Timestamp() *time.Time

	// ID is the tx ID.
	ID() string

	// NumConfirmations is the number of confirmations. 0 for unconfirmed.
	NumConfirmations() int

	// Type returns the type of the transaction.
	Type() TxType

	// Amount is always >0 and is the amount received or sent (not including the fee).
	Amount() Amount

	// Addresses money was sent to / received on.
	Addresses() []string
}

Transaction models a transaction with common transaction info.

type TxType

type TxType string

TxType is a type of transaction. See the TxType* constants.

const (
	// TxTypeReceive is a tx which sends funds to our account.
	TxTypeReceive TxType = "receive"
	// TxTypeSend is a tx which sends funds out of our account.
	TxTypeSend TxType = "send"
	// TxTypeSendSelf is a tx from out account to our account.
	TxTypeSendSelf TxType = "sendSelf"
)

type TxValidationError

type TxValidationError string

TxValidationError represents errors in the tx proposal input data.

func (TxValidationError) Error

func (err TxValidationError) Error() string

Jump to

Keyboard shortcuts

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