storage

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2018 License: ISC Imports: 12 Imported by: 0

Documentation

Overview

maintain the on-disk data store

maintain separate pools of a number of elements in key->value form

This maintains a LevelDB database split into a series of tables. Each table is defined by a prefix byte that is obtained from the prefix tag in the struct defining the avaiable tables.

Notes: 1. each separate pool has a single byte prefix (to spread the keys in LevelDB) 2. ++ = concatenation of byte data 3. BN = block number as 8 byte big endian (uint64) 4. txId = transaction digest as 32 byte SHA3-256(data) 5. asset id = fingerprint digest as 64 byte SHA3-512(data) 6. count = successive index value as 8 byte big endian (uint64) 7. owner = bitmark account (32 byte public key) 8. 00 = single byte values 00..ff 9. *others* = byte values of various length

Blocks:

B ++ BN               - block store
                        data: header ++ (concat transactions)
H ++ BN               - current block currencies
                        data: map(currency → currency address)
I ++ txId             - current block owner transaction index
                        data: BN

Transactions:

T ++ txId             - confirmed transactions
                        data: BN ++ packed transaction data

Assets:

A ++ asset id         - confirmed asset identifier
                        data: BN ++ packed asset data

Ownership:

N ++ owner            - next count value to use for appending to owned items
                        data: count
K ++ owner ++ count   - list of owned items
                        data: 00 ++ last transfer txId ++ last transfer BN ++ issue txId ++ issue BN ++ asset id
                        data: 01 ++ last transfer txId ++ last transfer BN ++ issue txId ++ issue BN ++ owned BN
D ++ owner ++ txId    - position in list of owned items, for delete after transfer
                        data: count

Testing:

Z ++ key              - testing data

Index

Constants

View Source
const (
	ReadOnly  = true
	ReadWrite = false
)

Variables

View Source
var Pool pools

the instance

Functions

func Finalise

func Finalise()

close the database connection

func Initialise

func Initialise(database string, readOnly bool) (bool, error)

open up the database connection

this must be called before any pool is accessed

func ReindexDone added in v0.8.0

func ReindexDone() error

called at the end of reindex

Types

type Element

type Element struct {
	Key   []byte
	Value []byte
}

a binary data item

type FetchCursor

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

cursor structure

func (*FetchCursor) Fetch

func (cursor *FetchCursor) Fetch(count int) ([]Element, error)

fetch some elements starting from key

func (*FetchCursor) Map added in v0.8.0

func (cursor *FetchCursor) Map(f func(key []byte, value []byte) error) error

map a function over all elements in the range

func (*FetchCursor) Seek

func (cursor *FetchCursor) Seek(key []byte) *FetchCursor

type PoolHandle

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

func (*PoolHandle) Delete

func (p *PoolHandle) Delete(key []byte)

remove a key from the database

func (*PoolHandle) Get

func (p *PoolHandle) Get(key []byte) []byte

read a value for a given key

this returns the actual element - copy the result if it must be preserved

func (*PoolHandle) GetN added in v0.8.0

func (p *PoolHandle) GetN(key []byte) (uint64, bool)

read a record and decode first 8 bytes as big endian uint64

second parameter is false if record was not found panics if not 8 (or more) bytes in the record

func (*PoolHandle) GetNB added in v0.8.0

func (p *PoolHandle) GetNB(key []byte) (uint64, []byte)

read a record and decode first 8 bytes as big endian uint64 and return the rest of the record as byte slice

second parameter is nil if record was not found panics if not 9 (or more) bytes in the record this returns the actual element in the second parameter - copy the result if it must be preserved

func (*PoolHandle) Has

func (p *PoolHandle) Has(key []byte) bool

Check if a key exists

func (*PoolHandle) LastElement

func (p *PoolHandle) LastElement() (Element, bool)

get the last element in a pool

func (*PoolHandle) NewFetchCursor

func (p *PoolHandle) NewFetchCursor() *FetchCursor

initialise a cursor to the start of a key range

func (*PoolHandle) Put

func (p *PoolHandle) Put(key []byte, value []byte)

store a key/value bytes pair to the database

type PoolNB added in v0.8.0

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

func (*PoolNB) Delete added in v0.8.0

func (p *PoolNB) Delete(key []byte)

remove a key from the database

func (*PoolNB) GetNB added in v0.8.0

func (p *PoolNB) GetNB(key []byte) (uint64, []byte)

read a record and decode first 8 bytes as big endian uint64 and return the rest of the record as byte slice

second parameter is nil if record was not found panics if not 9 (or more) bytes in the record this returns the actual element in the second parameter - copy the result if it must be preserved

func (*PoolNB) Has added in v0.8.0

func (p *PoolNB) Has(key []byte) bool

Check if a key exists

func (*PoolNB) NewFetchCursor added in v0.8.0

func (p *PoolNB) NewFetchCursor() *FetchCursor

initialise a cursor to the start of a key range

func (*PoolNB) Put added in v0.8.0

func (p *PoolNB) Put(key []byte, nValue []byte, bValue []byte)

store a key/value bytes pair to the database

Jump to

Keyboard shortcuts

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