balance

package
v0.18.15 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

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")
	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

func PrintDecimal added in v0.10.8

func PrintDecimal(i *big.Int, decimal int) string

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

type Amount big.Int

Amount represents an amount of a currency

var AmtZero Amount

func NewAmount added in v0.10.8

func NewAmount(x int64) *Amount

func NewAmountFromBigInt added in v0.12.0

func NewAmountFromBigInt(x *big.Int) *Amount

func NewAmountFromInt added in v0.10.8

func NewAmountFromInt(x int64) *Amount

func NewAmountFromString added in v0.10.8

func NewAmountFromString(x string, base int) (*Amount, error)

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) BigFloat added in v0.14.3

func (a Amount) BigFloat() *big.Float

func (*Amount) BigInt added in v0.12.0

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

func (*Amount) CheckInRange added in v0.14.4

func (a *Amount) CheckInRange(min Amount, max Amount) (bool, error)

func (*Amount) Equals added in v0.14.3

func (a *Amount) Equals(value Amount) bool

func (*Amount) IsZero added in v0.18.15

func (a *Amount) IsZero() bool

func (*Amount) LessThan added in v0.14.4

func (a *Amount) LessThan(value Amount) bool

func (Amount) MarshalJSON added in v0.10.8

func (a Amount) MarshalJSON() ([]byte, error)

func (Amount) MarshalText added in v0.10.8

func (a Amount) MarshalText() ([]byte, error)

func (*Amount) Minus added in v0.14.3

func (a *Amount) Minus(value Amount) (*Amount, error)

func (*Amount) Plus added in v0.14.3

func (a *Amount) Plus(value Amount) *Amount

func (Amount) String added in v0.13.0

func (a Amount) String() string

func (*Amount) UnmarshalJSON added in v0.10.8

func (a *Amount) UnmarshalJSON(b []byte) error

func (*Amount) UnmarshalText added in v0.10.8

func (a *Amount) UnmarshalText(b []byte) error

type Balance

type Balance struct {
	Amounts map[string]Coin `json:"amounts"`
}

Wrap the amount with owner information

func NewBalance

func NewBalance() *Balance

Generators

func (*Balance) GetCoin

func (b *Balance) GetCoin(currency Currency) Coin

methods

func (Balance) String

func (b Balance) String() string

String method used in fmt and Dump

type Coin

type Coin struct {
	Currency Currency `json:"currency"`
	Amount   *Amount  `json:"amount,string"`
}
Coin starts here

Coin is the basic amount, specified in integers, at the smallest increment (i.e. a satoshi, not a bitcoin)

func (*Coin) Data

func (c *Coin) Data() serialize.Data

func (Coin) Divide

func (coin Coin) Divide(value int) Coin

func (Coin) DivideInt64 added in v0.12.0

func (coin Coin) DivideInt64(value int64) Coin

func (Coin) Equals

func (coin Coin) Equals(value Coin) bool

Equals another coin

func (Coin) Humanize added in v0.10.8

func (coin Coin) Humanize() string

func (Coin) IsCurrency

func (coin Coin) IsCurrency(currencies ...string) bool

See if the coin is one of a list of currencies

func (Coin) IsValid

func (coin Coin) IsValid() bool

IsValid coin or is it broken

func (Coin) LessThanCoin

func (coin Coin) LessThanCoin(value Coin) bool

LessThan, for coins...

func (Coin) LessThanEqualCoin

func (coin Coin) LessThanEqualCoin(value Coin) bool

LessThanEqual, for coins...

func (Coin) Minus

func (coin Coin) Minus(value Coin) (Coin, error)

Minus two coins

func (Coin) MultiplyInt

func (coin Coin) MultiplyInt(value int) Coin

Multiply one coin by another

func (Coin) MultiplyInt64 added in v0.12.0

func (coin Coin) MultiplyInt64(value int64) Coin

func (*Coin) NewDataInstance

func (c *Coin) NewDataInstance() serialize.Data

func (Coin) Plus

func (coin Coin) Plus(value Coin) Coin

Plus two coins

func (*Coin) SetData

func (c *Coin) SetData(a interface{}) error

func (Coin) String

func (coin Coin) String() string

Turn a coin into a readable, floating point string with the currency

type CoinData

type CoinData struct {
	Currency Currency `json:"currency"`
	Amount   []byte   `json:"amount"`
}

func (*CoinData) SerialTag added in v0.10.8

func (ad *CoinData) SerialTag() string

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

func (*Context) Store

func (ctx *Context) Store() *Store

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) Base

func (c Currency) Base() *big.Int

func (Currency) Bytes

func (c Currency) Bytes() []byte

func (Currency) NewCoinFromAmount added in v0.10.8

func (c Currency) NewCoinFromAmount(a Amount) Coin

func (Currency) NewCoinFromBytes

func (c Currency) NewCoinFromBytes(amount []byte) Coin

Create a coin from bytes, the bytes must come from Big.Int.

func (Currency) NewCoinFromFloat64

func (c Currency) NewCoinFromFloat64(amount float64) Coin

TODO Create a coin from float

func (Currency) NewCoinFromInt

func (c Currency) NewCoinFromInt(amount int64) Coin

Create a coin from integer (not fractional)

func (Currency) NewCoinFromString added in v0.13.0

func (c Currency) NewCoinFromString(unitAmount string) Coin

func (Currency) NewCoinFromUnit added in v0.13.0

func (c Currency) NewCoinFromUnit(unitAmount int64) Coin

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

type Store

type Store struct {
	State *storage.State
	// contains filtered or unexported fields
}

func NewStore

func NewStore(prefix string, state *storage.State) *Store

func (*Store) AddToAddress added in v0.12.0

func (st *Store) AddToAddress(addr keys.Address, coin Coin) error

func (*Store) BuildKey added in v0.18.15

func (st *Store) BuildKey(addr keys.Address, coin *Coin) []byte

func (*Store) CheckBalanceFromAddress added in v0.12.0

func (st *Store) CheckBalanceFromAddress(addr keys.Address, coin Coin) error

func (*Store) GetBalance added in v0.12.0

func (st *Store) GetBalance(address keys.Address, list *CurrencySet) (balance *Balance, err error)

func (*Store) GetBalanceForCurr added in v0.13.0

func (st *Store) GetBalanceForCurr(address keys.Address, curr *Currency) (coin Coin, err error)

func (*Store) GetVersionedBalanceForCurr added in v0.18.15

func (st *Store) GetVersionedBalanceForCurr(address keys.Address, height int64, curr *Currency) (coin Coin, err error)

func (*Store) IterateAll added in v0.13.0

func (st *Store) IterateAll(fn func(addr keys.Address, c string, amt Amount) bool) bool

func (*Store) MinusFromAddress added in v0.12.0

func (st *Store) MinusFromAddress(addr keys.Address, coin Coin) error

func (*Store) SetBalance added in v0.14.3

func (st *Store) SetBalance(addr keys.Address, coin Coin) error

func (*Store) WithState added in v0.12.0

func (st *Store) WithState(state *storage.State) *Store

Jump to

Keyboard shortcuts

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