Documentation ¶
Index ¶
- Constants
- Variables
- func PrintDecimal(i *big.Int, decimal int) string
- type AccountKeeper
- type Amount
- func (a Amount) BigFloat() *big.Float
- func (a *Amount) BigInt() *big.Int
- func (a *Amount) CheckInRange(min Amount, max Amount) (bool, error)
- func (a *Amount) Equals(value Amount) bool
- func (a *Amount) IsZero() bool
- func (a *Amount) LessThan(value Amount) bool
- func (a Amount) MarshalJSON() ([]byte, error)
- func (a Amount) MarshalText() ([]byte, error)
- func (a *Amount) Minus(value Amount) (*Amount, error)
- func (a *Amount) Plus(value Amount) *Amount
- func (a Amount) String() string
- func (a *Amount) UnmarshalJSON(b []byte) error
- func (a *Amount) UnmarshalText(b []byte) error
- 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 EthAccount
- type NesterAccountKeeper
- func (nak *NesterAccountKeeper) GetAccount(addr keys.Address) (*EthAccount, error)
- func (nak *NesterAccountKeeper) GetBalance(addr keys.Address) *big.Int
- func (nak *NesterAccountKeeper) GetNonce(addr keys.Address) uint64
- func (nak *NesterAccountKeeper) GetVersionedAccount(addr keys.Address, height int64) (*EthAccount, error)
- func (nak *NesterAccountKeeper) NewAccountWithAddress(addr keys.Address) (*EthAccount, error)
- func (nak *NesterAccountKeeper) RemoveAccount(account EthAccount)
- func (nak *NesterAccountKeeper) SetAccount(account EthAccount) error
- func (nak *NesterAccountKeeper) WithState(state *storage.State) AccountKeeper
- type Store
- func (st *Store) AddToAddress(addr keys.Address, coin Coin) error
- func (st *Store) BuildKey(addr keys.Address, coin *Coin) []byte
- 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) GetVersionedBalanceForCurr(address keys.Address, height int64, 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) SetBalance(addr keys.Address, coin Coin) error
- func (st *Store) WithState(state *storage.State) *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") ErrBalanceErrorAddFailed = codes.ProtocolError{Code: codes.BalanceErrorAddFailed, Msg: "Failed to add balance to account"} ErrBalanceErrorMinusFailed = codes.ProtocolError{Code: codes.BalanceErrorMinusFailed, Msg: "Failed to minus balance from account"} ErrAccountNotFound = errors.New("account not found") )
Functions ¶
Types ¶
type AccountKeeper ¶ added in v0.17.0
type AccountKeeper interface { NewAccountWithAddress(addr keys.Address) (*EthAccount, error) GetAccount(addr keys.Address) (*EthAccount, error) GetVersionedAccount(addr keys.Address, height int64) (*EthAccount, error) SetAccount(account EthAccount) error RemoveAccount(account EthAccount) GetNonce(addr keys.Address) uint64 GetBalance(addr keys.Address) *big.Int WithState(state *storage.State) AccountKeeper }
func NewNesterAccountKeeper ¶ added in v0.17.0
func NewNesterAccountKeeper(state *storage.State, balances *Store, currencies *CurrencySet) AccountKeeper
type Amount ¶ added in v0.10.8
Amount represents an amount of a currency
var AmtZero Amount
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) CheckInRange ¶ added in v0.14.4
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 EthAccount ¶ added in v0.17.0
type EthAccount struct { Address keys.Address `json:"address"` CodeHash []byte `json:"codeHash"` Coins Coin `json:"coins"` Sequence uint64 `json:"sequence"` }
func NewEthAccount ¶ added in v0.17.0
func NewEthAccount(addr keys.Address, coin Coin) *EthAccount
func (*EthAccount) AddBalance ¶ added in v0.17.0
func (acc *EthAccount) AddBalance(amount *big.Int)
func (EthAccount) Balance ¶ added in v0.17.0
func (acc EthAccount) Balance() *big.Int
func (EthAccount) EthAddress ¶ added in v0.17.0
func (acc EthAccount) EthAddress() ethcmn.Address
EthAddress returns the account address ethereum format.
func (*EthAccount) SetBalance ¶ added in v0.17.0
func (acc *EthAccount) SetBalance(amount *big.Int)
func (*EthAccount) SubBalance ¶ added in v0.17.0
func (acc *EthAccount) SubBalance(amount *big.Int)
type NesterAccountKeeper ¶ added in v0.17.0
type NesterAccountKeeper struct {
// contains filtered or unexported fields
}
NesterAccountKeeper is used to combine two stores - balance and nonces
func (*NesterAccountKeeper) GetAccount ¶ added in v0.17.0
func (nak *NesterAccountKeeper) GetAccount(addr keys.Address) (*EthAccount, error)
func (*NesterAccountKeeper) GetBalance ¶ added in v0.18.15
func (nak *NesterAccountKeeper) GetBalance(addr keys.Address) *big.Int
func (*NesterAccountKeeper) GetNonce ¶ added in v0.18.15
func (nak *NesterAccountKeeper) GetNonce(addr keys.Address) uint64
func (*NesterAccountKeeper) GetVersionedAccount ¶ added in v0.17.0
func (nak *NesterAccountKeeper) GetVersionedAccount(addr keys.Address, height int64) (*EthAccount, error)
func (*NesterAccountKeeper) NewAccountWithAddress ¶ added in v0.17.0
func (nak *NesterAccountKeeper) NewAccountWithAddress(addr keys.Address) (*EthAccount, error)
func (*NesterAccountKeeper) RemoveAccount ¶ added in v0.17.0
func (nak *NesterAccountKeeper) RemoveAccount(account EthAccount)
func (*NesterAccountKeeper) SetAccount ¶ added in v0.17.0
func (nak *NesterAccountKeeper) SetAccount(account EthAccount) error
func (*NesterAccountKeeper) WithState ¶ added in v0.17.0
func (nak *NesterAccountKeeper) WithState(state *storage.State) AccountKeeper