types

package
v0.0.0-...-688ee80 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: ISC Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AtomPerCent is the number of atom in one bitcoin cent.
	AtomPerCent = 1e6

	// AtomPerCoin is the number of atom in one bitcoin (1 Coin).
	AtomPerCoin = 1e8

	// MaxAtom is the maximum transaction amount allowed in atom.
	MaxAtom = 21e6 * AtomPerCoin
)
View Source
const (
	Token0 = Token(0x0)
	Token1 = Token(0x1)

	TokenInvalid = Token(0xFF)
)

Variables

View Source
var (
	BalanceEmpty = Balance{}
	BalanceDummy = Balance{-1, -1}
	BalanceMax   = Balance{MaxAtom, MaxAtom}
)
View Source
var (
	FeeEmpty = Fee{}
	FeeDummy = Fee{-1, -1}
)
View Source
var (
	ValueEmpty = Value{}
	ValueDummy = Value{-1, TokenInvalid}
)
View Source
var (
	BalanceBigEmtpy = BalanceBig{}
)

Functions

This section is empty.

Types

type Amount

type Amount int64

Amount represents the base bitcoin monetary unit (colloquially referred to as a `Atom'). A single Amount is equal to 1e-8 of a bitcoin.

func NewAmount

func NewAmount(f float64) (Amount, error)

NewAmount creates an Amount from a floating point value representing some value in bitcoin. NewAmount errors if f is NaN or +-Infinity, but does not check that the amount is within the total amount of bitcoin producible as f may not refer to an amount at a single moment in time.

NewAmount is for specifically for converting Coin to Atom. For creating a new Amount with an int64 value which denotes a quantity of Atom, do a simple type conversion from type int64 to Amount. See GoDoc for example: http://godoc.org/github.com/endurio/ndrd/chainutil#example-Amount

func (Amount) BigInt

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

func (Amount) Format

func (a Amount) Format(u AmountUnit) string

Format formats a monetary amount counted in bitcoin base units as a string for a given unit. The conversion will succeed for any unit, however, known units will be formated with an appended label describing the units with SI notation, or "Atom" for the base unit.

func (Amount) Int64

func (a Amount) Int64() int64

func (Amount) MulF64

func (a Amount) MulF64(f float64) Amount

MulF64 multiplies an Amount by a floating point value. While this is not an operation that must typically be done by a full node or wallet, it is useful for services that build on top of bitcoin (for example, calculating a fee by multiplying by a percentage).

func (Amount) String

func (a Amount) String() string

String is the equivalent of calling Format with AmountCoin.

func (Amount) ToCoin

func (a Amount) ToCoin() float64

ToCoin is the equivalent of calling ToUnit with AmountCoin.

func (Amount) ToUnit

func (a Amount) ToUnit(u AmountUnit) float64

ToUnit converts a monetary amount counted in bitcoin base units to a floating point value representing an amount of bitcoin.

func (Amount) Uint64

func (a Amount) Uint64() uint64

type AmountUnit

type AmountUnit int

AmountUnit describes a method of converting an Amount to something other than the base unit of a bitcoin. The value of the AmountUnit is the exponent component of the decadic multiple to convert from an amount in bitcoin to an amount counted in units.

const (
	AmountMegaCoin  AmountUnit = 6
	AmountKiloCoin  AmountUnit = 3
	AmountCoin      AmountUnit = 0
	AmountMilliCoin AmountUnit = -3
	AmountMicroCoin AmountUnit = -6
	AmountAtom      AmountUnit = -8
)

These constants define various units used when describing a bitcoin monetary amount.

func (AmountUnit) String

func (u AmountUnit) String() string

String returns the unit as a string. For recognized units, the SI prefix is used, or "Atom" for the base unit. For all unrecognized units, "1eN Coin" is returned, where N is the AmountUnit.

type Balance

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

Balance contains all token amounts carried by an tx output. Designed as map of Token => Amount, but currently be a struct of 2 fields for optimization.

func NewBalance

func NewBalance(a0, a1 Amount) *Balance

func (*Balance) Add

func (b *Balance) Add(c *Balance) *Balance

func (*Balance) AddValue

func (b *Balance) AddValue(v Value) *Balance

func (Balance) Amount

func (b Balance) Amount(token Token) Amount

func (Balance) Big

func (b Balance) Big() *BalanceBig

func (*Balance) Clone

func (b *Balance) Clone() *Balance

func (*Balance) Cover

func (b *Balance) Cover(c *Balance) bool

Cover returns b >= c

func (*Balance) Div

func (b *Balance) Div(a Amount) *Balance

func (*Balance) Empty

func (b *Balance) Empty() bool

func (*Balance) Fee

func (b *Balance) Fee() *Fee

func (Balance) Map

func (b Balance) Map() []Amount

func (*Balance) Mul

func (b *Balance) Mul(a Amount) *Balance

func (*Balance) Neg

func (b *Balance) Neg() *Balance

func (*Balance) Price

func (b *Balance) Price() *Price

func (*Balance) RangeCheck

func (b *Balance) RangeCheck() int

RangeCheck checks whether the value is in it's valid range. Returns 0 for a valid range, negative for lower than minimum, and positive value for higher than maximum.

func (*Balance) SafeAdd

func (b *Balance) SafeAdd(c *Balance) error

SafeAdd perform Add with overflows check.

func (*Balance) SetAmount

func (b *Balance) SetAmount(token Token, amount Amount)

func (*Balance) String

func (b *Balance) String() string

func (*Balance) Sub

func (b *Balance) Sub(c *Balance) *Balance

func (*Balance) SubValue

func (b *Balance) SubValue(v Value) *Balance

func (*Balance) Value

func (b *Balance) Value(token Token) Value

func (*Balance) Values

func (b *Balance) Values() []Value

type BalanceBig

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

BalanceBig is balance of big.Int

func (*BalanceBig) Add

func (b *BalanceBig) Add(bb *BalanceBig) *BalanceBig

func (*BalanceBig) Clone

func (b *BalanceBig) Clone() *BalanceBig

func (*BalanceBig) Sub

func (b *BalanceBig) Sub(bb *BalanceBig) *BalanceBig

type CoinPriceReq

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

CoinPriceReq is balance of float64

func (CoinPriceReq) ToPriceReq

func (bc CoinPriceReq) ToPriceReq() PriceReq

type Fee

type Fee Balance

Fee represents the fee of an transaction.

func (*Fee) Add

func (f *Fee) Add(g *Fee) *Fee

func (*Fee) Balance

func (f *Fee) Balance() *Balance

func (*Fee) Price

func (f *Fee) Price() *Price

type Price

type Price Balance

Price represents the fee over KB of transaction size. Price.a(i) = Tx.Fee.a(i) / Tx.SizeInKB

func (Price) Rate

func (p Price) Rate(r PriceReq) (rate float64)

Rate calculates the price rate paid for a tx. Tx with higher rate will have higher priority. A rate >= 1.0 is sufficient for an tx to be accepted.

type PriceReq

type PriceReq Price

PriceReq is the miner-configured price rate accepted for each tokens. The fundametal different between PriceReq and Price/Fee/Balance is that PriceReq's amounts are not accumulated. The price is required to be PriceReq.a0 of Token0, OR PriceReq.a1 of Token1, OR 50% of each.

PriceReq.a(i) == 0 when miner does not accept fee in token(i) PriceReq.a(i) > 0 then the tx is accepted when it pays at least a(i) fee of token(i) Multiple prices can be accepted, so the tx can be paid by multiple tokens. For each pair of accepted tokens, a(i)/a(j) should be equal market_price(j)/market_price(i).

func NewPriceReq

func NewPriceReq(a0, a1 Amount) *PriceReq

func (*PriceReq) Balance

func (p *PriceReq) Balance() *Balance

func (PriceReq) ToCoinPriceReq

func (b PriceReq) ToCoinPriceReq() CoinPriceReq

type Token

type Token uint8

func (Token) String

func (t Token) String() string

type Value

type Value struct {
	Amount
	Token
}

func (*Value) RangeCheck

func (v *Value) RangeCheck() int

RangeCheck checks whether the value is in it's valid range. Returns 0 for a valid range, negative for lower than minimum, and positive value for higher than maximum.

Jump to

Keyboard shortcuts

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