Documentation
¶
Overview ¶
Package state manages persistent state for the DEX VM.
Index ¶
- Variables
- type Account
- type State
- func (s *State) AddOpenOrder(addr ids.ShortID, orderID ids.ID) error
- func (s *State) Close() error
- func (s *State) Commit() error
- func (s *State) Credit(addr ids.ShortID, token ids.ID, amount uint64) error
- func (s *State) CreditLPTokens(addr ids.ShortID, poolID ids.ID, amount uint64) error
- func (s *State) Debit(addr ids.ShortID, token ids.ID, amount uint64) error
- func (s *State) DebitLPTokens(addr ids.ShortID, poolID ids.ID, amount uint64) error
- func (s *State) GetAccount(addr ids.ShortID) (*Account, error)
- func (s *State) GetBalance(addr ids.ShortID, token ids.ID) (uint64, error)
- func (s *State) GetLPBalance(addr ids.ShortID, poolID ids.ID) (uint64, error)
- func (s *State) GetLastBlock() (ids.ID, uint64)
- func (s *State) GetNonce(addr ids.ShortID) (uint64, error)
- func (s *State) GetOrCreateAccount(addr ids.ShortID) *Account
- func (s *State) IncrementNonce(addr ids.ShortID) error
- func (s *State) Initialize() error
- func (s *State) RemoveOpenOrder(addr ids.ShortID, orderID ids.ID) error
- func (s *State) SaveAccount(acc *Account) error
- func (s *State) SetLastBlock(blockID ids.ID, height uint64) error
- func (s *State) Transfer(from, to ids.ShortID, token ids.ID, amount uint64) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
Address ids.ShortID `json:"address"`
Nonce uint64 `json:"nonce"`
Balances map[ids.ID]uint64 `json:"balances"` // token -> balance
OpenOrders []ids.ID `json:"openOrders"` // list of open order IDs
LPTokens map[ids.ID]uint64 `json:"lpTokens"` // pool -> LP token balance
CreatedAt int64 `json:"createdAt"`
}
Account represents a user account in the DEX.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State manages the persistent state of the DEX VM.
func (*State) AddOpenOrder ¶
AddOpenOrder adds an order ID to an account's open orders.
func (*State) CreditLPTokens ¶
CreditLPTokens adds LP tokens to an account.
func (*State) DebitLPTokens ¶
DebitLPTokens removes LP tokens from an account.
func (*State) GetAccount ¶
GetAccount returns an account by address.
func (*State) GetBalance ¶
GetBalance returns the balance of a token for an account.
func (*State) GetLPBalance ¶
GetLPBalance returns the LP token balance for a pool.
func (*State) GetLastBlock ¶
GetLastBlock returns the last accepted block ID and height.
func (*State) GetOrCreateAccount ¶
GetOrCreateAccount returns an existing account or creates a new one.
func (*State) IncrementNonce ¶
IncrementNonce increments the nonce for an account.
func (*State) Initialize ¶
Initialize initializes state from database.
func (*State) RemoveOpenOrder ¶
RemoveOpenOrder removes an order ID from an account's open orders.
func (*State) SaveAccount ¶
SaveAccount saves an account to database.
func (*State) SetLastBlock ¶
SetLastBlock sets the last accepted block.