database

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 7 Imported by: 0

README

DATABASE

So what we need is a simple key/value store database with buckets. This will be used to keep up with balances at addresses from mining rewards, and may be extended to include balances at addresses after conversions and transactions

The database ensures that we don't have to reprocess the entire PegNet chains everytime someone launches the PegNet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(bucket Bucket, key []byte) (bkey []byte)

BuildKey() appends the bucket as a number to the front of the key, only using 7 bits and keeping the high bit set. Much like a varint. This does not work well for negative numbers or really big numbers.

This usually this adds two bytes, the value and a zero. The bucket is always separated from the key by one zero. We set the high order bit

func Decode added in v0.2.0

func Decode(o interface{}, data []byte) error

Decode is a gob decode into the target object

func Encode added in v0.2.0

func Encode(o interface{}) ([]byte, error)

Encode is a gob encode

func HeightToBytes added in v0.2.0

func HeightToBytes(v int64) []byte

Types

type Bucket

type Bucket int
const (
	INVALID Bucket = iota // Don't use zero, that's a good invalid value

	// The bucket indexed by height that has the raw oprblock data
	//	Key -> Height
	//	Value -> Graded opr list
	BUCKET_OPR_HEIGHT

	// These are unused
	BUCKET_OPR        // Mostly Valid (has the prior winners, has proper structure
	BUCKET_ALL_EB     // OPR chain Entry Blocks indexed by Directory Block Height
	BUCKET_VALID_EB   // OPR chain Entry Blocks that actually qualify to pay out mining fees and set asset prices
	BUCKET_VALID_OPRS // OPR Lists of valid OPRS, indexed by Directory Block Height, ordered as graded
	BUCKET_BALANCES   // PEG payout balances
)

type IDatabase

type IDatabase interface {
	Open(pathname string) error
	Put(bucket Bucket, key []byte, Value []byte) error
	Get(bucket Bucket, key []byte) ([]byte, error)
	Delete(bucket Bucket, key []byte) error
	Close() error

	Iterate(bucket Bucket) Iterator
}

type Iterator

type Iterator interface {
	First() bool
	Last() bool
	Next() bool
	Key() []byte
	Value() []byte
	Release()
}

type Ldb

type Ldb struct {
	Pathname string
	DB       *leveldb.DB
	// contains filtered or unexported fields
}

func (*Ldb) Close

func (db *Ldb) Close() (err error)

Close() Close the database if it has not yet been closed. We know this by checking that the DB field isn't nil.

func (*Ldb) Delete

func (db *Ldb) Delete(bucket Bucket, key []byte) error

func (*Ldb) Get

func (db *Ldb) Get(bucket Bucket, key []byte) ([]byte, error)

func (*Ldb) Iterate

func (db *Ldb) Iterate(bucket Bucket) (iter Iterator)

Iterate() Creates an iterator to iterate over the elements in a bucket. A particular iterator cannot be used in multiple processes, but multiple processes can have their own iterators without issue.

Iterators must be released.

func (*Ldb) Open

func (db *Ldb) Open(pathname string) (err error)

Open() Open the database. The path to the database is int he Ldb struct.

func (*Ldb) Put

func (db *Ldb) Put(bucket Bucket, key []byte, Value []byte) error

type MapDb added in v0.2.0

type MapDb struct {
	// contains filtered or unexported fields
}

func NewMapDb added in v0.2.0

func NewMapDb() *MapDb

func (*MapDb) Close added in v0.2.0

func (db *MapDb) Close() (err error)

func (*MapDb) Delete added in v0.2.0

func (db *MapDb) Delete(bucket Bucket, key []byte) error

func (*MapDb) Get added in v0.2.0

func (db *MapDb) Get(bucket Bucket, key []byte) ([]byte, error)

func (*MapDb) Iterate added in v0.2.0

func (db *MapDb) Iterate(bucket Bucket) (iter Iterator)

TODO: implement this for a map? Are we going to use this?

func (*MapDb) Open added in v0.2.0

func (db *MapDb) Open(pathname string) (err error)

func (*MapDb) Put added in v0.2.0

func (db *MapDb) Put(bucket Bucket, key []byte, Value []byte) error

Jump to

Keyboard shortcuts

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