Documentation ¶
Overview ¶
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(dbPrefix string, readOnly bool) error
- func IsMigrationNeed() bool
- type Access
- type AccessData
- func (d *AccessData) Abort()
- func (d *AccessData) Begin() error
- func (d *AccessData) Commit() error
- func (d *AccessData) Delete(key []byte)
- func (d *AccessData) DumpTx() []byte
- func (d *AccessData) Get(key []byte) ([]byte, error)
- func (d *AccessData) Has(key []byte) (bool, error)
- func (d *AccessData) InUse() bool
- func (d *AccessData) Iterator(searchRange *ldb_util.Range) iterator.Iterator
- func (d *AccessData) Put(key []byte, value []byte)
- type Cache
- type Element
- type FetchCursor
- type Handle
- type LevelDBPaymentStore
- func (l *LevelDBPaymentStore) Close() error
- func (l *LevelDBPaymentStore) DB() *leveldb.DB
- func (l *LevelDBPaymentStore) GetCheckpoint() (*chainhash.Hash, error)
- func (l *LevelDBPaymentStore) GetHash(height int32) (*chainhash.Hash, error)
- func (l *LevelDBPaymentStore) GetHeight(hash *chainhash.Hash) (int32, error)
- func (l *LevelDBPaymentStore) RollbackTo(deleteFrom, deleteTo int32) error
- func (l *LevelDBPaymentStore) SetCheckpoint(height int32) error
- func (l *LevelDBPaymentStore) StoreBlock(height int32, hash *chainhash.Hash) error
- func (l *LevelDBPaymentStore) Table(tableName string) *PaymentTable
- type P2PStorage
- type PaymentTable
- type PoolHandle
- func (p *PoolHandle) Begin()
- func (p *PoolHandle) Commit() error
- 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
- func (p *PoolHandle) Put(key []byte, value []byte, dummy []byte)
- func (p *PoolHandle) PutN(key []byte, value uint64)
- func (p *PoolHandle) Ready() bool
- func (p *PoolHandle) Remove(key []byte)
- type PoolNB
- func (p *PoolNB) Begin()
- func (p *PoolNB) Commit() error
- 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) LastElement() (Element, bool)
- func (p *PoolNB) NewFetchCursor() *FetchCursor
- func (p *PoolNB) Put(key []byte, nValue []byte, bValue []byte)
- func (p *PoolNB) PutN(key []byte, value uint64)
- func (p *PoolNB) Ready() bool
- func (p *PoolNB) Remove(key []byte)
- type Query
- type Retrieve
- type Transaction
- type TransactionData
- func (t *TransactionData) Abort()
- func (t *TransactionData) Begin() error
- func (t *TransactionData) Commit() error
- func (t *TransactionData) Delete(h Handle, key []byte)
- func (t *TransactionData) Get(h Handle, key []byte) []byte
- func (t *TransactionData) GetN(h Handle, key []byte) (uint64, bool)
- func (t *TransactionData) GetNB(h Handle, key []byte) (uint64, []byte)
- func (t *TransactionData) Has(h Handle, key []byte) bool
- func (t *TransactionData) InUse() bool
- func (t *TransactionData) Put(h Handle, key []byte, value []byte, additional []byte)
- func (t *TransactionData) PutN(h Handle, key []byte, value uint64)
- type Update
Constants ¶
const ( ReadOnly = true ReadWrite = false )
pool access modes
Variables ¶
var CheckpointKey = []byte("checkpoint")
var PaymentStorage struct { Btc P2PStorage Ltc P2PStorage }
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 IsMigrationNeed ¶ added in v0.12.0
func IsMigrationNeed() bool
IsMigrationNeed - check if bitmarks database needs migration
Types ¶
type Access ¶ added in v0.12.0
type Access 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 AccessData ¶ added in v0.12.0
func (*AccessData) Abort ¶ added in v0.12.0
func (d *AccessData) Abort()
func (*AccessData) Begin ¶ added in v0.12.0
func (d *AccessData) Begin() error
func (*AccessData) Commit ¶ added in v0.12.0
func (d *AccessData) Commit() error
func (*AccessData) Delete ¶ added in v0.12.0
func (d *AccessData) Delete(key []byte)
func (*AccessData) DumpTx ¶ added in v0.12.0
func (d *AccessData) DumpTx() []byte
func (*AccessData) InUse ¶ added in v0.12.0
func (d *AccessData) InUse() bool
func (*AccessData) Iterator ¶ added in v0.12.0
func (d *AccessData) Iterator(searchRange *ldb_util.Range) iterator.Iterator
func (*AccessData) Put ¶ added in v0.12.0
func (d *AccessData) 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 LevelDBPaymentStore ¶ added in v0.12.0
type LevelDBPaymentStore struct {
// contains filtered or unexported fields
}
func NewLevelDBPaymentStore ¶ added in v0.12.0
func NewLevelDBPaymentStore(db *leveldb.DB) *LevelDBPaymentStore
func (*LevelDBPaymentStore) Close ¶ added in v0.12.0
func (l *LevelDBPaymentStore) Close() error
func (*LevelDBPaymentStore) DB ¶ added in v0.12.0
func (l *LevelDBPaymentStore) DB() *leveldb.DB
func (*LevelDBPaymentStore) GetCheckpoint ¶ added in v0.12.0
func (l *LevelDBPaymentStore) GetCheckpoint() (*chainhash.Hash, error)
GetCheckpoint returns the hash of the last saved checkpoint in the storage
func (*LevelDBPaymentStore) GetHash ¶ added in v0.12.0
func (l *LevelDBPaymentStore) GetHash(height int32) (*chainhash.Hash, error)
GetHash returns the hash of a give height
func (*LevelDBPaymentStore) GetHeight ¶ added in v0.12.0
func (l *LevelDBPaymentStore) GetHeight(hash *chainhash.Hash) (int32, error)
GetHeight returns height for a specific hash
func (*LevelDBPaymentStore) RollbackTo ¶ added in v0.12.0
func (l *LevelDBPaymentStore) RollbackTo(deleteFrom, deleteTo int32) error
RollbackTo deletes blocks from a block down a another
func (*LevelDBPaymentStore) SetCheckpoint ¶ added in v0.12.0
func (l *LevelDBPaymentStore) SetCheckpoint(height int32) error
SetCheckpoint saves the hash of a give height as a checkpoint
func (*LevelDBPaymentStore) StoreBlock ¶ added in v0.12.0
func (l *LevelDBPaymentStore) StoreBlock(height int32, hash *chainhash.Hash) error
StoreBlock saves a pair of hash and its height
func (*LevelDBPaymentStore) Table ¶ added in v0.12.0
func (l *LevelDBPaymentStore) Table(tableName string) *PaymentTable
type P2PStorage ¶ added in v0.12.0
type P2PStorage interface { DB() *leveldb.DB GetHash(height int32) (*chainhash.Hash, error) GetHeight(hash *chainhash.Hash) (int32, error) StoreBlock(height int32, hash *chainhash.Hash) error GetCheckpoint() (*chainhash.Hash, error) SetCheckpoint(height int32) error RollbackTo(deleteFrom, deleteTo int32) error Close() error }
type PaymentTable ¶ added in v0.12.0
type PaymentTable struct {
// contains filtered or unexported fields
}
func (*PaymentTable) Delete ¶ added in v0.12.0
func (p *PaymentTable) Delete(key []byte) error
remove a key from the database
func (*PaymentTable) Get ¶ added in v0.12.0
func (p *PaymentTable) 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 (*PaymentTable) Has ¶ added in v0.12.0
func (p *PaymentTable) Has(key []byte) bool
Check if a key exists
type PoolHandle ¶
type PoolHandle struct {
// 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) 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
func (*PoolHandle) Put ¶
func (p *PoolHandle) Put(key []byte, value []byte, dummy []byte)
Put - store a key/value bytes pair to the database
func (*PoolHandle) PutN ¶ added in v0.10.0
func (p *PoolHandle) PutN(key []byte, value uint64)
PutN - store a uint8 as an 8 byte sequence
func (*PoolHandle) Ready ¶ added in v0.12.1
func (p *PoolHandle) Ready() bool
Ready - check if db is ready
func (*PoolHandle) Remove ¶ added in v0.12.1
func (p *PoolHandle) Remove(key []byte)
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) LastElement ¶ added in v0.12.1
LastElement - last element
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 Retrieve ¶ added in v0.12.1
type Retrieve interface { Get([]byte) []byte GetN([]byte) (uint64, bool) GetNB([]byte) (uint64, []byte) LastElement() (Element, bool) NewFetchCursor() *FetchCursor }
Retrieve - interface for storage retrieve data
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 - concept from RDBMS
func NewDBTransaction ¶ added in v0.11.0
func NewDBTransaction() (Transaction, error)
type TransactionData ¶ added in v0.12.0
func (*TransactionData) Abort ¶ added in v0.12.0
func (t *TransactionData) Abort()
func (*TransactionData) Begin ¶ added in v0.12.0
func (t *TransactionData) Begin() error
func (*TransactionData) Commit ¶ added in v0.12.0
func (t *TransactionData) Commit() error
func (*TransactionData) Delete ¶ added in v0.12.0
func (t *TransactionData) Delete(h Handle, key []byte)
func (*TransactionData) Get ¶ added in v0.12.0
func (t *TransactionData) Get(h Handle, key []byte) []byte
func (*TransactionData) GetN ¶ added in v0.12.0
func (t *TransactionData) GetN(h Handle, key []byte) (uint64, bool)
func (*TransactionData) GetNB ¶ added in v0.12.0
func (t *TransactionData) GetNB(h Handle, key []byte) (uint64, []byte)
func (*TransactionData) Has ¶ added in v0.12.0
func (t *TransactionData) Has(h Handle, key []byte) bool
func (*TransactionData) InUse ¶ added in v0.12.0
func (t *TransactionData) InUse() bool