Documentation ¶
Index ¶
- Constants
- Variables
- type Amount
- type AmountUnit
- type Balance
- func (b *Balance) Add(c *Balance) *Balance
- func (b *Balance) AddValue(v Value) *Balance
- func (b Balance) Amount(token Token) Amount
- func (b Balance) Big() *BalanceBig
- func (b *Balance) Clone() *Balance
- func (b *Balance) Cover(c *Balance) bool
- func (b *Balance) Div(a Amount) *Balance
- func (b *Balance) Empty() bool
- func (b *Balance) Fee() *Fee
- func (b Balance) Map() []Amount
- func (b *Balance) Mul(a Amount) *Balance
- func (b *Balance) Neg() *Balance
- func (b *Balance) Price() *Price
- func (b *Balance) RangeCheck() int
- func (b *Balance) SafeAdd(c *Balance) error
- func (b *Balance) SetAmount(token Token, amount Amount)
- func (b *Balance) String() string
- func (b *Balance) Sub(c *Balance) *Balance
- func (b *Balance) SubValue(v Value) *Balance
- func (b *Balance) Value(token Token) Value
- func (b *Balance) Values() []Value
- type BalanceBig
- type CoinPriceReq
- type Fee
- type Price
- type PriceReq
- type Token
- type Value
Constants ¶
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 )
const ( Token0 = Token(0x0) Token1 = Token(0x1) TokenInvalid = Token(0xFF) )
Variables ¶
var ( BalanceEmpty = Balance{} BalanceDummy = Balance{-1, -1} BalanceMax = Balance{MaxAtom, MaxAtom} )
var ( FeeEmpty = Fee{} FeeDummy = Fee{-1, -1} )
var ( ValueEmpty = Value{} ValueDummy = Value{-1, TokenInvalid} )
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 ¶
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) 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) MulF64 ¶
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) 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.
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 (Balance) Big ¶
func (b Balance) Big() *BalanceBig
func (*Balance) RangeCheck ¶
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.
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 Price ¶
type Price Balance
Price represents the fee over KB of transaction size. Price.a(i) = Tx.Fee.a(i) / Tx.SizeInKB
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 (PriceReq) ToCoinPriceReq ¶
func (b PriceReq) ToCoinPriceReq() CoinPriceReq