Documentation
¶
Overview ¶
Copyright 2017 - 2018 OneLedger
Define chains as they are seen in OneLedher ¶
Copyright 2017-2018 OneLedger ¶
Keep the state of the MerkleTrees between the different stages of consensus ¶
We need an up to date tree to check new transactions against. We then need to apply them when delivered. We also need to get to the last tree.
The difficulty comes from the underlying code not quite being thread-safe...
Copyright 2017 - 2018 OneLedger ¶
Encapsulate the coins, allow int64 for interfacing and big.Int as base type ¶
Copyright 2017 - 2018 OneLedger ¶
Basic datatypes ¶
Copyright 2017-2018 OneLedger ¶
Encapsulate the underlying storage from our app. Currently using:
Tendermint's memdb (just an in-memory Merkle Tree) Tendermint's persistent kvstore (with Merkle Trees & Proofs) - Can only be opened by one process...
Only one connection can occur to LevelDB at a time...
Index ¶
- Variables
- func FileExists(name string, dir string) bool
- func GetBase(currency string) *big.Float
- type Balance
- func (b *Balance) AddAmount(coin Coin)
- func (b *Balance) AddCoin(coin Coin)
- func (b *Balance) FindCoin(currency Currency) *Coin
- func (b *Balance) GetAmountByName(name string) Coin
- func (b *Balance) GetCoin(currency Currency) Coin
- func (b Balance) IsEnoughBalance(balance Balance) bool
- func (b *Balance) MinusAmount(coin Coin)
- func (b *Balance) MinusCoin(coin Coin)
- func (b *Balance) SetAmount(coin Coin)
- func (balance Balance) String() string
- type Chain
- type ChainNode
- type ChainState
- func (c *ChainState) Close()
- func (state *ChainState) Commit() ([]byte, int64)
- func (state *ChainState) Dump()
- func (state *ChainState) Exists(key DatabaseKey) bool
- func (state *ChainState) FindAll() map[string]*Balance
- func (state *ChainState) Get(key DatabaseKey) *Balance
- func (state *ChainState) Set(key DatabaseKey, balance *Balance)
- func (state *ChainState) Test(key DatabaseKey, balance *Balance)
- type ChainType
- type Coin
- func (coin Coin) Divide(value int) Coin
- func (coin Coin) Equals(value Coin) bool
- func (coin Coin) Float64() float64
- func (coin Coin) IsCurrency(currencies ...string) bool
- func (coin Coin) IsValid() bool
- func (coin Coin) LessThan(value float64) bool
- func (coin Coin) LessThanCoin(value Coin) bool
- func (coin Coin) LessThanEqual(value float64) bool
- func (coin Coin) LessThanEqualCoin(value Coin) bool
- func (coin Coin) Minus(value Coin) Coin
- func (coin Coin) Multiply(value Coin) Coin
- func (coin Coin) MultiplyInt(value int) Coin
- func (coin Coin) Plus(value Coin) Coin
- func (coin Coin) Quotient(value Coin) Coin
- func (coin Coin) String() string
- type Coins
- type Currency
- type DatabaseKey
- type Datastore
- type Entry
- type Extra
- type KeyValue
- func (store KeyValue) Begin() Session
- func (store KeyValue) Close()
- func (store KeyValue) Dump()
- func (store KeyValue) Errors() string
- func (store KeyValue) Exists(key DatabaseKey) bool
- func (store KeyValue) FindAll() []DatabaseKey
- func (store KeyValue) Get(key DatabaseKey) interface{}
- func (store KeyValue) Reopen()
- type KeyValueSession
- func (session KeyValueSession) Commit() bool
- func (session KeyValueSession) Delete(key DatabaseKey) bool
- func (session KeyValueSession) Dump()
- func (session KeyValueSession) Errors() string
- func (session KeyValueSession) Exists(key DatabaseKey) bool
- func (session KeyValueSession) FindAll() []DatabaseKey
- func (session KeyValueSession) Get(key DatabaseKey) interface{}
- func (session KeyValueSession) Rollback() bool
- func (session KeyValueSession) Set(key DatabaseKey, value interface{}) bool
- type Message
- type MultiMap
- type Script
- type ScriptRecords
- type Session
- type StorageType
- type VersionMap
- type Versions
Constants ¶
This section is empty.
Variables ¶
var Currencies map[string]Currency = map[string]Currency{ "OLT": Currency{"OLT", ONELEDGER, 0}, "BTC": Currency{"BTC", BITCOIN, 1}, "ETH": Currency{"ETH", ETHEREUM, 2}, "VT": Currency{"VT", ONELEDGER, 3}, }
TODO: These need to be driven from a domain database, also they are many-to-one with chains
var CurrenciesExtra map[string]Extra = map[string]Extra{ "OLT": Extra{big.NewFloat(1000000000000000000), 6, 'f'}, "BTC": Extra{big.NewFloat(1), 0, 'f'}, "ETH": Extra{big.NewFloat(1), 0, 'f'}, "VT": Extra{big.NewFloat(1), 0, 'f'}, }
TODO: Separated from Currency to avoid serializing big floats and giving out this info
Functions ¶
func FileExists ¶ added in v0.6.2
TODO: Should be moved to some common/shared/utils directory Test to see if this exists already
Types ¶
type Balance ¶
Wrap the amount with owner information
func NewBalance ¶
func NewBalance() *Balance
func NewBalanceFromCoin ¶ added in v0.7.1
func NewBalanceFromInt ¶ added in v0.8.0
func NewBalanceFromString ¶ added in v0.7.1
func (*Balance) GetAmountByName ¶ added in v0.7.1
TODO: GetCoinByName?
func (Balance) IsEnoughBalance ¶ added in v0.8.0
func (*Balance) MinusAmount ¶ added in v0.8.0
type ChainState ¶
type ChainState struct {
Name string
Type StorageType
Delivered *iavl.MutableTree // Build us a new set of transactions
Checked *iavl.MutableTree // Temporary and can be Rolled Back
Committed *iavl.MutableTree // Last Persistent Tree
// Last committed values
LastVersion int64
Version int64
LastHash []byte
Hash []byte
TreeHeight int
// contains filtered or unexported fields
}
func NewChainState ¶
func NewChainState(name string, newType StorageType) *ChainState
func (*ChainState) Close ¶ added in v0.7.0
func (c *ChainState) Close()
func (*ChainState) Commit ¶
func (state *ChainState) Commit() ([]byte, int64)
TODO: Not sure about this, it seems to be Cosmos-sdk's way of getting arround the immutable copy problem...
func (*ChainState) Dump ¶
func (state *ChainState) Dump()
func (*ChainState) Exists ¶
func (state *ChainState) Exists(key DatabaseKey) bool
TODO: Should be against the commit tree, not the delivered one!!!
func (*ChainState) FindAll ¶
func (state *ChainState) FindAll() map[string]*Balance
Expensive O(n) search through everything...
func (*ChainState) Get ¶ added in v0.6.2
func (state *ChainState) Get(key DatabaseKey) *Balance
TODO: Should be against the commit tree, not the delivered one!!!
func (*ChainState) Set ¶
func (state *ChainState) Set(key DatabaseKey, balance *Balance)
Do this only for the Delivery side
func (*ChainState) Test ¶
func (state *ChainState) Test(key DatabaseKey, balance *Balance)
Do this only for the Check side
type Coin ¶
Coin is the basic amount, specified in integers, at the smallest increment (i.e. a satoshi, not a bitcoin)
func NewCoinFromFloat ¶ added in v0.8.0
Create a coin from floating point
func NewCoinFromInt ¶ added in v0.8.0
Create a coin from integer (not fractional)
func NewCoinFromString ¶ added in v0.8.0
Create a coin from string
func NewCoinFromUnits ¶ added in v0.8.1
func (Coin) IsCurrency ¶
See if the coin is one of a list of currencies
func (Coin) LessThanCoin ¶ added in v0.8.0
LessThan, for coins...
func (Coin) LessThanEqual ¶
LessThanEqual, just for OLTs...
func (Coin) LessThanEqualCoin ¶ added in v0.8.0
LessThanEqual, for coins...
func (Coin) MultiplyInt ¶ added in v0.8.0
Multiply one coin by another
type Currency ¶ added in v0.5.0
type DatabaseKey ¶
type DatabaseKey = []byte // Database key
type Datastore ¶
type Datastore interface {
// Contruction/Destruction
//Initialize(name string)
Close()
Reopen()
// Some of the databases require commits, some are persisted right way
Begin() Session
// Readonly, not in a session
FindAll() []DatabaseKey
Exists(key DatabaseKey) bool
Get(key DatabaseKey) interface{}
// Give out a listof errors
Errors() string
Dump()
}
Database is a consistent interface for all underlying persistent data stores.
func NewDatastore ¶
func NewDatastore(name string, stype StorageType) Datastore
type KeyValue ¶ added in v0.6.2
type KeyValue struct {
Type StorageType
Name string
File string
// contains filtered or unexported fields
}
Wrap the underlying usage
func NewKeyValue ¶ added in v0.6.2
func NewKeyValue(name string, newType StorageType) *KeyValue
NewKeyValue initializes a new application
func (KeyValue) Dump ¶ added in v0.6.2
func (store KeyValue) Dump()
Dump out debugging information from the KeyValue datastore
func (KeyValue) Exists ¶ added in v0.6.2
func (store KeyValue) Exists(key DatabaseKey) bool
Test to see if a key exists
func (KeyValue) FindAll ¶ added in v0.6.2
func (store KeyValue) FindAll() []DatabaseKey
FindAll of the keys in the database
func (KeyValue) Get ¶ added in v0.6.2
func (store KeyValue) Get(key DatabaseKey) interface{}
Get a key from the database
type KeyValueSession ¶ added in v0.6.2
type KeyValueSession struct {
// contains filtered or unexported fields
}
func (KeyValueSession) Commit ¶ added in v0.6.2
func (session KeyValueSession) Commit() bool
Commit the changes to persistence
func (KeyValueSession) Delete ¶ added in v0.6.2
func (session KeyValueSession) Delete(key DatabaseKey) bool
Delete a key from the datastore
func (KeyValueSession) Dump ¶ added in v0.6.2
func (session KeyValueSession) Dump()
Dump out the contents of the database
func (KeyValueSession) Errors ¶ added in v0.6.2
func (session KeyValueSession) Errors() string
List out the errors
func (KeyValueSession) Exists ¶ added in v0.6.2
func (session KeyValueSession) Exists(key DatabaseKey) bool
Test to see if a key exists
func (KeyValueSession) FindAll ¶ added in v0.6.2
func (session KeyValueSession) FindAll() []DatabaseKey
Find all of the keys in the datastore
func (KeyValueSession) Get ¶ added in v0.6.2
func (session KeyValueSession) Get(key DatabaseKey) interface{}
Load return the stored value
func (KeyValueSession) Rollback ¶ added in v0.6.2
func (session KeyValueSession) Rollback() bool
Rollback any changes since the last commit
func (KeyValueSession) Set ¶ added in v0.6.2
func (session KeyValueSession) Set(key DatabaseKey, value interface{}) bool
Store inserts or updates a value under a key
type MultiMap ¶ added in v0.8.0
type MultiMap struct {
Name map[string]VersionMap
}
func NewMultiMap ¶ added in v0.8.0
func NewMultiMap() *MultiMap
type ScriptRecords ¶ added in v0.8.0
func NewScriptRecords ¶ added in v0.8.0
func NewScriptRecords() *ScriptRecords
type Session ¶ added in v0.6.2
type Session interface {
// Primary operations
FindAll() []DatabaseKey
Exists(key DatabaseKey) bool
Get(key DatabaseKey) interface{}
Set(key DatabaseKey, value interface{}) bool
Delete(key DatabaseKey) bool
// Finish the sessions
Commit() bool
Rollback() bool
Errors() string
Dump()
}
Open a session (transaction in the database sense, not blockchain).
func NewKeyValueSession ¶ added in v0.6.2
Create a new session
type StorageType ¶ added in v0.6.2
type StorageType int
ENUM for datastore type
const ( MEMORY StorageType = iota PERSISTENT )
Different types
type VersionMap ¶ added in v0.8.0
TODO: serial won't let us use a Version struct as the map key
func NewVersionMap ¶ added in v0.8.0
func NewVersionMap() *VersionMap