Documentation ¶
Overview ¶
SPDX-License-Identifier: ISC
SPDX-License-Identifier: ISC
Package storage - 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 available 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 (prefix ⧺ public key ≡ 33 bytes if Ed25519) 8. 00 = single byte values 00..ff 9. value = balance quantity value as 8 byte big endian (uint64) 10. *others* = byte values of various length
Blocks:
B ⧺ BN - block store data: header ⧺ (concat transactions) 2 ⧺ BN - block Argon2 hashes data: hash of block 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 L ⧺ owner ⧺ count - list of owned items data: txId D ⧺ owner ⧺ txId - position in list of owned items, for delete after transfer data: count P ⧺ txId - owner data (00=asset, 01=block, 02=share) head of provenance chain data: 00 ⧺ transfer BN ⧺ issue txId ⧺ issue BN ⧺ asset id data: 01 ⧺ transfer BN ⧺ issue txId ⧺ issue BN ⧺ owned BN data: 02 ⧺ transfer BN ⧺ issue txId ⧺ issue BN ⧺ asset id
Bitmark Shares (txId ≡ share id)
F ⧺ txId - share total value (constant) data: value ⧺ txId Q ⧺ owner ⧺ txId - current balance quantity of shares (ShareId) for each owner (deleted if value becomes zero) data: value
Testing:
Z ⧺ key - testing data
Index ¶
- Constants
- Variables
- func Finalise()
- func Initialise(database string, readOnly bool) (bool, bool, error)
- func ReindexDone() error
- type Cache
- type DataAccess
- type DataAccessImpl
- func (d *DataAccessImpl) Abort()
- func (d *DataAccessImpl) Begin() error
- func (d *DataAccessImpl) Commit() error
- func (d *DataAccessImpl) Delete(key []byte)
- func (d *DataAccessImpl) DumpTx() []byte
- func (d *DataAccessImpl) Get(key []byte) ([]byte, error)
- func (d *DataAccessImpl) Has(key []byte) (bool, error)
- func (d *DataAccessImpl) InUse() bool
- func (d *DataAccessImpl) Iterator(searchRange *ldb_util.Range) iterator.Iterator
- func (d *DataAccessImpl) Put(key []byte, value []byte)
- type Element
- type FetchCursor
- type Handle
- type PoolHandle
- func (p *PoolHandle) Begin()
- func (p *PoolHandle) Commit() error
- func (p *PoolHandle) Empty() bool
- func (p *PoolHandle) Get(key []byte) []byte
- func (p *PoolHandle) GetN(key []byte) (uint64, bool)
- func (p *PoolHandle) GetNB(key []byte) (uint64, []byte)
- func (p *PoolHandle) Has(key []byte) bool
- func (p *PoolHandle) LastElement() (Element, bool)
- func (p *PoolHandle) NewFetchCursor() *FetchCursor
- type PoolNB
- func (p *PoolNB) Begin()
- func (p *PoolNB) Commit() error
- func (p *PoolNB) Empty() bool
- func (p *PoolNB) Get(key []byte) []byte
- func (p *PoolNB) GetN(key []byte) (uint64, bool)
- func (p *PoolNB) GetNB(key []byte) (uint64, []byte)
- func (p *PoolNB) Has(key []byte) bool
- func (p *PoolNB) NewFetchCursor() *FetchCursor
- type Transaction
- type TransactionImpl
- func (t *TransactionImpl) Abort()
- func (t *TransactionImpl) Begin() error
- func (t *TransactionImpl) Commit() error
- func (t *TransactionImpl) Delete(h Handle, key []byte)
- func (t *TransactionImpl) Get(h Handle, key []byte) []byte
- func (t *TransactionImpl) GetN(h Handle, key []byte) (uint64, bool)
- func (t *TransactionImpl) GetNB(h Handle, key []byte) (uint64, []byte)
- func (t *TransactionImpl) Has(h Handle, key []byte) bool
- func (t *TransactionImpl) InUse() bool
- func (t *TransactionImpl) Put(h Handle, key []byte, value []byte, additional []byte)
- func (t *TransactionImpl) PutN(h Handle, key []byte, value uint64)
Constants ¶
const ( ReadOnly = true ReadWrite = false )
pool access modes
const (
ErrEmptyTransaction = "Empty Transaction"
)
Variables ¶
var Pool pools
Pool - the set of exported pools
Functions ¶
func Initialise ¶
Initialise - open up the database connection
this must be called before any pool is accessed
func ReindexDone ¶ added in v0.8.0
func ReindexDone() error
ReindexDone - called at the end of reindex
Types ¶
type DataAccess ¶ added in v0.11.0
type DataAccess interface { Abort() Begin() error Commit() error Delete([]byte) DumpTx() []byte Get([]byte) ([]byte, error) Has([]byte) (bool, error) InUse() bool Iterator(*ldb_util.Range) iterator.Iterator Put([]byte, []byte) }
for Database
type DataAccessImpl ¶ added in v0.11.0
func (*DataAccessImpl) Abort ¶ added in v0.11.0
func (d *DataAccessImpl) Abort()
func (*DataAccessImpl) Begin ¶ added in v0.11.0
func (d *DataAccessImpl) Begin() error
func (*DataAccessImpl) Commit ¶ added in v0.11.0
func (d *DataAccessImpl) Commit() error
func (*DataAccessImpl) Delete ¶ added in v0.11.0
func (d *DataAccessImpl) Delete(key []byte)
func (*DataAccessImpl) DumpTx ¶ added in v0.11.0
func (d *DataAccessImpl) DumpTx() []byte
func (*DataAccessImpl) Get ¶ added in v0.11.0
func (d *DataAccessImpl) Get(key []byte) ([]byte, error)
func (*DataAccessImpl) Has ¶ added in v0.11.0
func (d *DataAccessImpl) Has(key []byte) (bool, error)
func (*DataAccessImpl) InUse ¶ added in v0.11.0
func (d *DataAccessImpl) InUse() bool
func (*DataAccessImpl) Iterator ¶ added in v0.11.0
func (d *DataAccessImpl) Iterator(searchRange *ldb_util.Range) iterator.Iterator
func (*DataAccessImpl) Put ¶ added in v0.11.0
func (d *DataAccessImpl) Put(key []byte, value []byte)
type FetchCursor ¶
type FetchCursor struct {
// contains filtered or unexported fields
}
FetchCursor - cursor structure
func (*FetchCursor) Fetch ¶
func (cursor *FetchCursor) Fetch(count int) ([]Element, error)
Fetch - return 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 - run a function on all elements in the range
func (*FetchCursor) Seek ¶
func (cursor *FetchCursor) Seek(key []byte) *FetchCursor
Seek - move cursor to specific key position
type PoolHandle ¶
type PoolHandle struct { Handle // contains filtered or unexported fields }
PoolHandle - the structure of a pool handle
func (*PoolHandle) Begin ¶ added in v0.11.0
func (p *PoolHandle) Begin()
func (*PoolHandle) Commit ¶ added in v0.11.0
func (p *PoolHandle) Commit() error
func (*PoolHandle) Empty ¶ added in v0.11.1
func (p *PoolHandle) Empty() bool
Empty - check if struct is empty
func (*PoolHandle) Get ¶
func (p *PoolHandle) Get(key []byte) []byte
Get - 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)
GetN - 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)
GetNB - 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) LastElement ¶
func (p *PoolHandle) LastElement() (Element, bool)
LastElement - get the last element in a pool
func (*PoolHandle) NewFetchCursor ¶
func (p *PoolHandle) NewFetchCursor() *FetchCursor
NewFetchCursor - initialise a cursor to the start of a key range
type PoolNB ¶ added in v0.8.0
type PoolNB struct {
// contains filtered or unexported fields
}
PoolNB - handle for a storage pool
func (*PoolNB) GetNB ¶ added in v0.8.0
GetNB - 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) NewFetchCursor ¶ added in v0.8.0
func (p *PoolNB) NewFetchCursor() *FetchCursor
NewFetchCursor - initialise a cursor to the start of a key range
type Transaction ¶ added in v0.11.0
type Transaction interface { Abort() Begin() error Commit() error Delete(Handle, []byte) Get(Handle, []byte) []byte GetN(Handle, []byte) (uint64, bool) GetNB(Handle, []byte) (uint64, []byte) Has(Handle, []byte) bool InUse() bool Put(Handle, []byte, []byte, []byte) PutN(Handle, []byte, uint64) }
Transaction RDBS transaction
func NewDBTransaction ¶ added in v0.11.0
func NewDBTransaction() (Transaction, error)
type TransactionImpl ¶ added in v0.11.0
func (*TransactionImpl) Abort ¶ added in v0.11.0
func (t *TransactionImpl) Abort()
func (*TransactionImpl) Begin ¶ added in v0.11.0
func (t *TransactionImpl) Begin() error
func (*TransactionImpl) Commit ¶ added in v0.11.0
func (t *TransactionImpl) Commit() error
func (*TransactionImpl) Delete ¶ added in v0.11.0
func (t *TransactionImpl) Delete(h Handle, key []byte)
func (*TransactionImpl) Get ¶ added in v0.11.0
func (t *TransactionImpl) Get(h Handle, key []byte) []byte
func (*TransactionImpl) GetN ¶ added in v0.11.0
func (t *TransactionImpl) GetN(h Handle, key []byte) (uint64, bool)
func (*TransactionImpl) GetNB ¶ added in v0.11.0
func (t *TransactionImpl) GetNB(h Handle, key []byte) (uint64, []byte)
func (*TransactionImpl) Has ¶ added in v0.11.0
func (t *TransactionImpl) Has(h Handle, key []byte) bool
func (*TransactionImpl) InUse ¶ added in v0.11.0
func (t *TransactionImpl) InUse() bool