Documentation ¶
Index ¶
- Constants
- Variables
- type Balance
- func (b *Balance) AddCoin(coin Coin) *Balance
- func (b *Balance) Data() serialize.Data
- func (b *Balance) FindCoin(currency Currency) *Coin
- func (b *Balance) GetCoin(currency Currency) Coin
- func (b Balance) IsEnoughBalance(balance Balance) bool
- func (b *Balance) MinusCoin(coin Coin) (*Balance, error)
- func (b *Balance) NewDataInstance() serialize.Data
- func (b *Balance) SetData(obj interface{}) error
- func (b Balance) String() string
- type BalanceData
- type Coin
- func (c *Coin) Data() serialize.Data
- func (coin Coin) Divide(value int) Coin
- func (coin Coin) Equals(value Coin) bool
- 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 (c *Coin) NewDataInstance() serialize.Data
- func (coin Coin) Plus(value Coin) (Coin, error)
- func (c *Coin) SetData(a interface{}) error
- func (coin Coin) String() string
- type CoinData
- type Context
- type Currency
- type CurrencyList
- type Store
Constants ¶
const ( TagBalanceData = "data_balance_data" TagBalance = "data_balance" )
Variables ¶
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 ¶
This section is empty.
Types ¶
type Balance ¶
Wrap the amount with owner information
func (*Balance) Data ¶
Data creates a BalanceData from a given Balance object, the coins are flattened to a list in the generator itself ideally there should be no change done to a data after this step. This datatype can go straight to serialization.
func (Balance) IsEnoughBalance ¶
func (*Balance) NewDataInstance ¶
type BalanceData ¶
type BalanceData struct { Coins []CoinData `json:"coins"` Tag string `json:"tag"` // Tag is a field used to identify the type after ser/deser }
BalanceData is an easy to serialize representation of a Balance object. A full Balance object can be recostructed from a BalanceAdapter object and vice versa. There is a map flattening of course for Coins
func (*BalanceData) SerialTag ¶
func (bd *BalanceData) SerialTag() string
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) IsCurrency ¶
See if the coin is one of a list of currencies
func (Coin) LessThanEqualCoin ¶
LessThanEqual, for coins...
func (*Coin) NewDataInstance ¶
type CoinData ¶
type CoinData struct { CurName string `json:"curr_name"` CurChain chain.Type `json:"curr_chain"` CurDecimal int64 `json:"curr_decimal"` Amount []byte `json:"amt"` }
CoinData is a flattening of coin map in a balance data type
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext(logger *log.Logger, balances *Store, currencies *CurrencyList) *Context
func (*Context) Currencies ¶
func (ctx *Context) Currencies() *CurrencyList
type Currency ¶
type Currency struct { Name string `json:"name"` Chain chain.Type `json:"chain"` Decimal int64 `json:"decimal"` }
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)
type CurrencyList ¶
type CurrencyList struct {
// contains filtered or unexported fields
}
func NewCurrencyList ¶
func NewCurrencyList() *CurrencyList
func (*CurrencyList) GetCurrencyByName ¶
func (cl *CurrencyList) GetCurrencyByName(name string) (Currency, bool)
func (*CurrencyList) GetCurrencyByStringKey ¶
func (cl *CurrencyList) GetCurrencyByStringKey(key string) (Currency, bool)
func (CurrencyList) Len ¶
func (cl CurrencyList) Len() int
func (*CurrencyList) Register ¶
func (cl *CurrencyList) Register(c Currency) error
type Store ¶
type Store struct {
*storage.ChainState
}