data

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 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},
}

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

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

Types

type Balance

type Balance struct {
	// Address id.Address
	Amount Coin
}

Wrap the amount with owner information

func NewBalance

func NewBalance(amount int64, currency string) Balance

TODO: Should return a pointer, as per Go conventions

func (Balance) AsString

func (balance Balance) AsString() string

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 Delivery 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) AsString

func (coin Coin) AsString() string

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

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
	Exists(key DatabaseKey) bool
	Get(key DatabaseKey) interface{}
	FindAll() []DatabaseKey

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

NewApplicationContext initializes a new application

func (KeyValue) Begin added in v0.6.2

func (store KeyValue) Begin() 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()

func (KeyValue) Errors added in v0.6.2

func (store KeyValue) Errors() string

func (KeyValue) Exists added in v0.6.2

func (store KeyValue) Exists(key DatabaseKey) bool

func (KeyValue) FindAll added in v0.6.2

func (store KeyValue) FindAll() []DatabaseKey

func (KeyValue) Get added in v0.6.2

func (store KeyValue) Get(key DatabaseKey) interface{}

func (KeyValue) Reopen added in v0.6.2

func (store KeyValue) Reopen()

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

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

func (KeyValueSession) Exists added in v0.6.2

func (session KeyValueSession) Exists(key DatabaseKey) bool

func (KeyValueSession) FindAll added in v0.6.2

func (session KeyValueSession) FindAll() []DatabaseKey

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

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

type Session added in v0.6.2

type Session interface {
	// Primary operations
	Exists(key DatabaseKey) bool
	Set(key DatabaseKey, value interface{}) bool
	Get(key DatabaseKey) interface{}
	Delete(key DatabaseKey) bool
	FindAll() []DatabaseKey

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

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