Documentation ¶
Index ¶
- Constants
- Variables
- func PrintDecimal(i *big.Int, decimal int) string
- type Amount
- type Balance
- type Coin
- func (c *Coin) Data() serialize.Data
- func (coin Coin) Divide(value int) Coin
- func (coin Coin) DivideInt64(value int64) Coin
- func (coin Coin) Equals(value Coin) bool
- func (coin Coin) Humanize() string
- func (coin Coin) IsCurrency(currencies ...string) bool
- func (coin Coin) IsValid() bool
- func (coin Coin) LessThanCoin(value Coin) bool
- func (coin Coin) LessThanEqualCoin(value Coin) bool
- func (coin Coin) Minus(value Coin) (Coin, error)
- func (coin Coin) MultiplyInt(value int) Coin
- func (coin Coin) MultiplyInt64(value int64) Coin
- func (c *Coin) NewDataInstance() serialize.Data
- func (coin Coin) Plus(value Coin) Coin
- func (c *Coin) SetData(a interface{}) error
- func (coin Coin) String() string
- type CoinData
- type Context
- type Currencies
- type Currency
- func (c Currency) Base() *big.Int
- func (c Currency) Bytes() []byte
- func (c Currency) NewCoinFromAmount(a Amount) Coin
- func (c Currency) NewCoinFromBytes(amount []byte) Coin
- func (c Currency) NewCoinFromFloat64(amount float64) Coin
- func (c Currency) NewCoinFromInt(amount int64) Coin
- func (c Currency) NewCoinFromString(unitAmount string) Coin
- func (c Currency) NewCoinFromUnit(unitAmount int64) Coin
- type CurrencySet
- type Store
- func (st *Store) AddToAddress(addr keys.Address, coin Coin) error
- func (st *Store) CheckBalanceFromAddress(addr keys.Address, coin Coin) error
- func (st *Store) GetBalance(address keys.Address, list *CurrencySet) (balance *Balance, err error)
- func (st *Store) GetBalanceForCurr(address keys.Address, curr *Currency) (coin Coin, err error)
- func (st *Store) IterateAll(fn func(addr keys.Address, c string, amt Amount) bool) bool
- func (st *Store) MinusFromAddress(addr keys.Address, coin Coin) error
- func (st *Store) WithState(state *storage.State) *Store
Constants ¶
View Source
const ( TagBalanceData = "data_balance_data" TagBalance = "data_balance" )
Variables ¶
View Source
var ( ErrWrongBalanceAdapter = errors.New("error in asserting to BalanceAdapter") ErrDuplicateCurrency = errors.New("provided currency has already been registered") ErrMismatchingCurrency = errors.New("mismatching currencies") ErrInsufficientBalance = errors.New("insufficient balance") )
Functions ¶
Types ¶
type Amount ¶ added in v0.10.8
Amount represents an amount of a currency
func NewAmountFromBigInt ¶ added in v0.12.0
func NewAmountFromInt ¶ added in v0.10.8
func NewAmountFromString ¶ added in v0.10.8
NewAmountFromString parses the amount as a string with the given base. For example, if base is 10, then it expects the given string to be base-10 notation. If the base is 16, then it expects the string in hexadecimal notation. If the base is set to 16, it ignores any "0x" prefix if present.
func (Amount) MarshalJSON ¶ added in v0.10.8
func (Amount) MarshalText ¶ added in v0.10.8
func (*Amount) UnmarshalJSON ¶ added in v0.10.8
func (*Amount) UnmarshalText ¶ added in v0.10.8
type Coin ¶
Coin starts here
Coin is the basic amount, specified in integers, at the smallest increment (i.e. a satoshi, not a bitcoin)
func (Coin) DivideInt64 ¶ added in v0.12.0
func (Coin) IsCurrency ¶
See if the coin is one of a list of currencies
func (Coin) LessThanEqualCoin ¶
LessThanEqual, for coins...
func (Coin) MultiplyInt64 ¶ added in v0.12.0
func (*Coin) NewDataInstance ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext(logger *log.Logger, balances *Store, currencies *CurrencySet) *Context
func (*Context) Currencies ¶
func (ctx *Context) Currencies() *CurrencySet
type Currencies ¶ added in v0.10.8
type Currencies []Currency
func (Currencies) GetCurrencySet ¶ added in v0.12.0
func (cs Currencies) GetCurrencySet() *CurrencySet
type Currency ¶
type Currency struct { Id int64 `json:"id"` Name string `json:"name"` Chain chain.Type `json:"chain"` Decimal int64 `json:"decimal"` Unit string `json:"unit"` }
func (Currency) NewCoinFromAmount ¶ added in v0.10.8
func (Currency) NewCoinFromBytes ¶
Create a coin from bytes, the bytes must come from Big.Int.
func (Currency) NewCoinFromFloat64 ¶
TODO Create a coin from float
func (Currency) NewCoinFromInt ¶
Create a coin from integer (not fractional)
func (Currency) NewCoinFromString ¶ added in v0.13.0
func (Currency) NewCoinFromUnit ¶ added in v0.13.0
type CurrencySet ¶ added in v0.12.0
type CurrencySet struct {
// contains filtered or unexported fields
}
func NewCurrencySet ¶ added in v0.12.0
func NewCurrencySet() *CurrencySet
func (CurrencySet) GetCurrencies ¶ added in v0.12.0
func (c CurrencySet) GetCurrencies() Currencies
func (*CurrencySet) GetCurrencyById ¶ added in v0.12.0
func (cl *CurrencySet) GetCurrencyById(id int64) (Currency, bool)
func (*CurrencySet) GetCurrencyByName ¶ added in v0.12.0
func (cl *CurrencySet) GetCurrencyByName(name string) (Currency, bool)
func (CurrencySet) Len ¶ added in v0.12.0
func (cl CurrencySet) Len() int
func (*CurrencySet) Register ¶ added in v0.12.0
func (cl *CurrencySet) Register(c Currency) error
type Store ¶
func (*Store) AddToAddress ¶ added in v0.12.0
func (*Store) CheckBalanceFromAddress ¶ added in v0.12.0
func (*Store) GetBalance ¶ added in v0.12.0
func (*Store) GetBalanceForCurr ¶ added in v0.13.0
func (*Store) IterateAll ¶ added in v0.13.0
func (*Store) MinusFromAddress ¶ added in v0.12.0
Click to show internal directories.
Click to hide internal directories.