data

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Copyright 2017 - 2018 OneLedger

Define chains as they are seen in OneLedher

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...

Encapsulate the coins, allow int64 for interfacing and big.Int as base type

Basic datatypes

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

Constants

This section is empty.

Variables

View Source
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

View Source
var OLTBase *big.Float = big.NewFloat(1000000000000000000)

TODO: Add in the base for all arithmatic operations (encapsulated)

Functions

func FileExists added in v0.6.2

func FileExists(name string, dir string) bool

TODO: Should be moved to some common/shared/utils directory Test to see if this exists already

Types

type Balance

type Balance struct {
	// Address id.Address
	Amounts []Coin
}

Wrap the amount with owner information

func NewBalance

func NewBalance() Balance

func NewBalanceFromCoin added in v0.7.1

func NewBalanceFromCoin(coin Coin) Balance

func NewBalanceFromString added in v0.7.1

func NewBalanceFromString(amount int64, currency string) Balance

func (*Balance) AddAmmount added in v0.7.1

func (b *Balance) AddAmmount(coin Coin)

func (*Balance) FromCoin added in v0.7.1

func (b *Balance) FromCoin(coin Coin)

func (*Balance) GetAmountByCurrency added in v0.7.1

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

func (*Balance) GetAmountByName added in v0.7.1

func (b *Balance) GetAmountByName(name string) Coin

func (*Balance) MinusAmmount added in v0.7.1

func (b *Balance) MinusAmmount(coin Coin)

func (*Balance) SetAmmount added in v0.7.1

func (b *Balance) SetAmmount(coin Coin)

func (Balance) String added in v0.7.1

func (balance Balance) String() string

String used in fmt and Dump

type Chain

type Chain struct {
	ChainType   ChainType
	Description string
	Features    []string
}

type ChainNode

type ChainNode struct {
	ChainType ChainType
	Location  string
}

A specific node in a chain

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 ChainType

type ChainType int
const (
	UNKNOWN ChainType = iota
	ONELEDGER
	BITCOIN
	ETHEREUM
)

TODO: These should be in a domain database

func (ChainType) String added in v0.6.2

func (ctype ChainType) String() string

type Coin

type Coin struct {
	Currency Currency `json:"currency"`
	Amount   *big.Int `json:"amount"`
}

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

func NewCoin

func NewCoin(amount int64, currency string) Coin

func (Coin) Equals

func (coin Coin) Equals(value Coin) bool

func (Coin) EqualsInt64

func (coin Coin) EqualsInt64(value int64) bool

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

func (Coin) LessThan

func (coin Coin) LessThan(value int64) bool

func (Coin) LessThanEqual

func (coin Coin) LessThanEqual(value int64) bool

func (Coin) Minus

func (coin Coin) Minus(value Coin) Coin

func (Coin) Multiply added in v0.7.0

func (coin Coin) Multiply(value Coin) Coin

func (Coin) Plus

func (coin Coin) Plus(value Coin) Coin

func (Coin) Quotient added in v0.7.0

func (coin Coin) Quotient(value Coin) Coin

func (Coin) String added in v0.7.1

func (coin Coin) String() string

type Coins

type Coins []Coin

type Currency added in v0.5.0

type Currency struct {
	Name string `json:"name"`

	Chain ChainType `json:"chain"`

	// TODO: Is this the specific instance of the chain?
	Id int `json:"id"`
}

func NewCurrency added in v0.6.2

func NewCurrency(currency string) Currency

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) Begin added in v0.6.2

func (store KeyValue) Begin() Session

Begin a new writable session

func (KeyValue) Close added in v0.6.2

func (store KeyValue) Close()

Close the database

func (KeyValue) Dump added in v0.6.2

func (store KeyValue) Dump()

Dump out debugging information from the KeyValue datastore

func (KeyValue) Errors added in v0.6.2

func (store KeyValue) Errors() string

Print out the error details

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

func (KeyValue) Reopen added in v0.6.2

func (store KeyValue) Reopen()

Close and reopen the datastore

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 Message

type Message = []byte // TODO: Maybe replaced by something better named?

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

func NewKeyValueSession(store *KeyValue) Session

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

Jump to

Keyboard shortcuts

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