Documentation ¶
Overview ¶
Package chain is an local accounts chains cache. It's intended to process new transfers fast not fetching data from database.
General structure is a set of independent accounts. Each account is a list of output transactions and their inputs.
Example of chain for account 100. Transactions goes from last to previous. We have 3 output transactions and 2 unspent inputs. Current balance is 650.
<- id:4 from:102 to:100 amount:20 spent_by:0 <- id:3 from:107 to:100 amount:30 spent_by:0 -> id:3 from:100 to:103 amount:200 balance:600 -> id:2 from:100 to:102 amount:530 balance:800 <- id:14 from:10 to:100 amount:30 spent_by:2 <- id:8 from:105 to:100 amount:300 spent_by:2 -> id:1 from:100 to:101 amount:100 balance:900 <- id:12 from:10 to:100 amount:1000 spent_by:1
Input transactions are indented to highlight that they are:
- Belongs to another chain by ids increment and prev_hash links
- Taken into account in the next output transaction of current account.
Index ¶
- type Chain
- func (c *Chain) GetBalance(accID pt.AccID) int64
- func (c *Chain) GetLastHash(accID pt.AccID) pt.Hash
- func (c *Chain) GetLastNTxns(accID pt.AccID, n int) []pt.Txn
- func (c *Chain) GetLastTxn(accID pt.AccID) *pt.Txn
- func (c *Chain) ListUnspentTxns(accID pt.AccID) []pt.Txn
- func (c *Chain) PutTo(accID pt.AccID, txns []pt.Txn)
- func (c *Chain) Reset(accID pt.AccID)
- type SettingsChain
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is an inmemory cache of accounts chains.
func (*Chain) GetLastNTxns ¶
GetLastNTxns returns at most n transactions (as many as we have) from last one to previous
type SettingsChain ¶
type SettingsChain struct {
// contains filtered or unexported fields
}
func NewSettingsChain ¶
func NewSettingsChain() *SettingsChain
func (*SettingsChain) GetLastHash ¶
func (c *SettingsChain) GetLastHash(accID pt.AccID) pt.Hash
func (*SettingsChain) GetLastSettings ¶
func (c *SettingsChain) GetLastSettings(accID pt.AccID) *pt.Settings
func (*SettingsChain) Put ¶
func (c *SettingsChain) Put(s *pt.Settings)
func (*SettingsChain) Reset ¶
func (c *SettingsChain) Reset(accID pt.AccID)
Click to show internal directories.
Click to hide internal directories.