data

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Copyright 2017 - 2018 OneLedger

Basic datatypes

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

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

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},
}
View Source
var OLTBase *big.Float = big.NewFloat(1000000000000000000)

Functions

func Exists

func Exists(name string, dir string) bool

Test to see if this exists already

Types

type Balance

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

func NewBalance

func NewBalance(amount int64, currency string) Balance

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
}

type ChainState

type ChainState struct {
	Name string
	Type DatastoreType

	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
	Version    int64
	TreeHeight int
	Hash       []byte
	// contains filtered or unexported fields
}

func NewChainState

func NewChainState(name string, newType DatastoreType) *ChainState

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) Find

func (state *ChainState) Find(key DatabaseKey) *Balance

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) Set

func (state *ChainState) Set(key DatabaseKey, balance Balance)

Do this for the Delivery side

type ChainType

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

TODO: These should be in a database

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) Plus

func (coin Coin) Plus(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"`
	Id    int       `json:"id"`
}

type DatabaseKey

type DatabaseKey = []byte // Database key

type Datastore

type Datastore struct {
	Type DatastoreType

	Name string
	File string
	// contains filtered or unexported fields
}

Wrap the underlying usage

func NewDatastore

func NewDatastore(name string, newType DatastoreType) *Datastore

NewApplicationContext initializes a new application

func (Datastore) Close

func (store Datastore) Close()

Close the database

func (Datastore) Commit

func (store Datastore) Commit()

Commit the changes to persistence

func (Datastore) Dump

func (store Datastore) Dump()

Dump out the contents of the database

func (Datastore) Empty

func (store Datastore) Empty()

Empty out all rows from the database

func (Datastore) Exists

func (store Datastore) Exists(key DatabaseKey) bool

func (Datastore) List

func (store Datastore) List() (keys []DatabaseKey)

List all of the keys

func (Datastore) Load

func (store Datastore) Load(key DatabaseKey) (value Message)

Load return the stored value

func (Datastore) Store

func (store Datastore) Store(key DatabaseKey, value Message) Message

Store inserts or updates a value under a key

type DatastoreType

type DatastoreType int

ENUM for datastore type

const (
	MEMORY     DatastoreType = iota
	PERSISTENT DatastoreType = iota
)

Different types

type Message

type Message = []byte

Jump to

Keyboard shortcuts

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