chain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: GPL-3.0 Imports: 3 Imported by: 0

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:

  1. Belongs to another chain by ids increment and prev_hash links
  2. Taken into account in the next output transaction of current account.

Index

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 NewChain

func NewChain() *Chain

func (*Chain) GetBalance

func (c *Chain) GetBalance(accID pt.AccID) int64

func (*Chain) GetLastHash

func (c *Chain) GetLastHash(accID pt.AccID) pt.Hash

func (*Chain) GetLastNTxns

func (c *Chain) GetLastNTxns(accID pt.AccID, n int) []pt.Txn

GetLastNTxns returns at most n transactions (as many as we have) from last one to previous

func (*Chain) GetLastTxn

func (c *Chain) GetLastTxn(accID pt.AccID) *pt.Txn

func (*Chain) ListUnspentTxns

func (c *Chain) ListUnspentTxns(accID pt.AccID) []pt.Txn

func (*Chain) PutTo

func (c *Chain) PutTo(accID pt.AccID, txns []pt.Txn)

PutTo puts transactions to account chain.

func (*Chain) Reset

func (c *Chain) Reset(accID pt.AccID)

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)

Jump to

Keyboard shortcuts

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