Documentation ¶
Index ¶
- Variables
- func AppendPrefix(k KeyPrefix, b []byte) []byte
- func AppendPrefixInt(k KeyPrefix, n int) []byte
- type BadgerDBBatch
- type BadgerDBOptions
- type BadgerDBStore
- func (b *BadgerDBStore) Batch() Batch
- func (b *BadgerDBStore) Close() error
- func (b *BadgerDBStore) Delete(key []byte) error
- func (b *BadgerDBStore) Get(key []byte) ([]byte, error)
- func (b *BadgerDBStore) Put(key, value []byte) error
- func (b *BadgerDBStore) PutBatch(batch Batch) error
- func (b *BadgerDBStore) Seek(key []byte, f func(k, v []byte))
- type Batch
- type BoltDBOptions
- type BoltDBStore
- func (s *BoltDBStore) Batch() Batch
- func (s *BoltDBStore) Close() error
- func (s *BoltDBStore) Delete(key []byte) error
- func (s *BoltDBStore) Get(key []byte) (val []byte, err error)
- func (s *BoltDBStore) Put(key, value []byte) error
- func (s *BoltDBStore) PutBatch(batch Batch) error
- func (s *BoltDBStore) Seek(key []byte, f func(k, v []byte))
- type DBConfiguration
- type KeyPrefix
- type KeyValue
- type LevelDBOptions
- type LevelDBStore
- func (s *LevelDBStore) Batch() Batch
- func (s *LevelDBStore) Close() error
- func (s *LevelDBStore) Delete(key []byte) error
- func (s *LevelDBStore) Get(key []byte) ([]byte, error)
- func (s *LevelDBStore) Put(key, value []byte) error
- func (s *LevelDBStore) PutBatch(batch Batch) error
- func (s *LevelDBStore) Seek(key []byte, f func(k, v []byte))
- type MemBatch
- type MemCachedStore
- type MemoryBatch
- type MemoryStore
- func (s *MemoryStore) Batch() Batch
- func (s *MemoryStore) Close() error
- func (s *MemoryStore) Delete(key []byte) error
- func (s *MemoryStore) Get(key []byte) ([]byte, error)
- func (s *MemoryStore) Put(key, value []byte) error
- func (s *MemoryStore) PutBatch(batch Batch) error
- func (s *MemoryStore) Seek(key []byte, f func(k, v []byte))
- func (s *MemoryStore) SeekAll(key []byte, f func(k, v []byte))
- type RedisDBOptions
- type RedisStore
- func (s *RedisStore) Batch() Batch
- func (s *RedisStore) Close() error
- func (s *RedisStore) Delete(k []byte) error
- func (s *RedisStore) Get(k []byte) ([]byte, error)
- func (s *RedisStore) Put(k, v []byte) error
- func (s *RedisStore) PutBatch(b Batch) error
- func (s *RedisStore) Seek(k []byte, f func(k, v []byte))
- type Store
Constants ¶
This section is empty.
Variables ¶
var Bucket = []byte("DB")
Bucket represents bucket used in boltdb to store all the data.
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is an error returned by Store implementations when a certain key is not found.
Functions ¶
func AppendPrefix ¶
AppendPrefix appends byteslice b to the given KeyPrefix. AppendKeyPrefix(SYSVersion, []byte{0x00, 0x01})
func AppendPrefixInt ¶
AppendPrefixInt append int n to the given KeyPrefix. AppendPrefixInt(SYSCurrentHeader, 10001)
Types ¶
type BadgerDBBatch ¶ added in v0.75.0
type BadgerDBBatch struct {
// contains filtered or unexported fields
}
BadgerDBBatch is a wrapper around badger.WriteBatch, compatible with Batch interface
func (*BadgerDBBatch) Delete ¶ added in v0.75.0
func (b *BadgerDBBatch) Delete(key []byte)
Delete implements the Batch interface
func (*BadgerDBBatch) Put ¶ added in v0.75.0
func (b *BadgerDBBatch) Put(key, value []byte)
Put implements the Batch interface
type BadgerDBOptions ¶ added in v0.75.0
type BadgerDBOptions struct {
Dir string `yaml:"BadgerDir"`
}
BadgerDBOptions configuration for BadgerDB.
type BadgerDBStore ¶ added in v0.75.0
type BadgerDBStore struct {
// contains filtered or unexported fields
}
BadgerDBStore is the official storage implementation for storing and retrieving blockchain data.
func NewBadgerDBStore ¶ added in v0.75.0
func NewBadgerDBStore(cfg BadgerDBOptions) (*BadgerDBStore, error)
NewBadgerDBStore returns a new BadgerDBStore object that will initialize the database found at the given path.
func (*BadgerDBStore) Batch ¶ added in v0.75.0
func (b *BadgerDBStore) Batch() Batch
Batch implements the Batch interface and returns a badgerdb compatible Batch.
func (*BadgerDBStore) Close ¶ added in v0.75.0
func (b *BadgerDBStore) Close() error
Close releases all db resources.
func (*BadgerDBStore) Delete ¶ added in v0.75.0
func (b *BadgerDBStore) Delete(key []byte) error
Delete implements the Store interface.
func (*BadgerDBStore) Get ¶ added in v0.75.0
func (b *BadgerDBStore) Get(key []byte) ([]byte, error)
Get implements the Store interface.
func (*BadgerDBStore) Put ¶ added in v0.75.0
func (b *BadgerDBStore) Put(key, value []byte) error
Put implements the Store interface.
func (*BadgerDBStore) PutBatch ¶ added in v0.75.0
func (b *BadgerDBStore) PutBatch(batch Batch) error
PutBatch implements the Store interface.
func (*BadgerDBStore) Seek ¶ added in v0.75.0
func (b *BadgerDBStore) Seek(key []byte, f func(k, v []byte))
Seek implements the Store interface.
type Batch ¶
Batch represents an abstraction on top of batch operations. Each Store implementation is responsible of casting a Batch to its appropriate type.
type BoltDBOptions ¶
type BoltDBOptions struct {
FilePath string `yaml:"FilePath"`
}
BoltDBOptions configuration for boltdb.
type BoltDBStore ¶
type BoltDBStore struct {
// contains filtered or unexported fields
}
BoltDBStore it is the storage implementation for storing and retrieving blockchain data.
func NewBoltDBStore ¶
func NewBoltDBStore(cfg BoltDBOptions) (*BoltDBStore, error)
NewBoltDBStore returns a new ready to use BoltDB storage with created bucket.
func (*BoltDBStore) Batch ¶
func (s *BoltDBStore) Batch() Batch
Batch implements the Batch interface and returns a boltdb compatible Batch.
func (*BoltDBStore) Delete ¶
func (s *BoltDBStore) Delete(key []byte) error
Delete implements the Store interface.
func (*BoltDBStore) Get ¶
func (s *BoltDBStore) Get(key []byte) (val []byte, err error)
Get implements the Store interface.
func (*BoltDBStore) Put ¶
func (s *BoltDBStore) Put(key, value []byte) error
Put implements the Store interface.
func (*BoltDBStore) PutBatch ¶
func (s *BoltDBStore) PutBatch(batch Batch) error
PutBatch implements the Store interface.
func (*BoltDBStore) Seek ¶
func (s *BoltDBStore) Seek(key []byte, f func(k, v []byte))
Seek implements the Store interface.
type DBConfiguration ¶
type DBConfiguration struct { Type string `yaml:"Type"` LevelDBOptions LevelDBOptions `yaml:"LevelDBOptions"` RedisDBOptions RedisDBOptions `yaml:"RedisDBOptions"` BoltDBOptions BoltDBOptions `yaml:"BoltDBOptions"` BadgerDBOptions BadgerDBOptions `yaml:"BadgerDBOptions"` }
DBConfiguration describes configuration for DB. Supported: 'levelDB', 'redisDB', 'boltDB', 'badgerDB'.
type KeyPrefix ¶
type KeyPrefix uint8
KeyPrefix is a constant byte added as a prefix for each key stored.
const ( DataBlock KeyPrefix = 0x01 DataTransaction KeyPrefix = 0x02 DataMPT KeyPrefix = 0x03 STAccount KeyPrefix = 0x40 STNotification KeyPrefix = 0x4d STContractID KeyPrefix = 0x51 STStorage KeyPrefix = 0x70 STNEP17Transfers KeyPrefix = 0x72 STNEP17Balances KeyPrefix = 0x73 IXHeaderHashList KeyPrefix = 0x80 SYSCurrentBlock KeyPrefix = 0xc0 SYSCurrentHeader KeyPrefix = 0xc1 SYSVersion KeyPrefix = 0xf0 )
KeyPrefix constants.
type LevelDBOptions ¶
type LevelDBOptions struct {
DataDirectoryPath string `yaml:"DataDirectoryPath"`
}
LevelDBOptions configuration for LevelDB.
type LevelDBStore ¶
type LevelDBStore struct {
// contains filtered or unexported fields
}
LevelDBStore is the official storage implementation for storing and retrieving blockchain data.
func NewLevelDBStore ¶
func NewLevelDBStore(cfg LevelDBOptions) (*LevelDBStore, error)
NewLevelDBStore returns a new LevelDBStore object that will initialize the database found at the given path.
func (*LevelDBStore) Batch ¶
func (s *LevelDBStore) Batch() Batch
Batch implements the Batch interface and returns a leveldb compatible Batch.
func (*LevelDBStore) Close ¶
func (s *LevelDBStore) Close() error
Close implements the Store interface.
func (*LevelDBStore) Delete ¶
func (s *LevelDBStore) Delete(key []byte) error
Delete implements the Store interface.
func (*LevelDBStore) Get ¶
func (s *LevelDBStore) Get(key []byte) ([]byte, error)
Get implements the Store interface.
func (*LevelDBStore) Put ¶
func (s *LevelDBStore) Put(key, value []byte) error
Put implements the Store interface.
func (*LevelDBStore) PutBatch ¶
func (s *LevelDBStore) PutBatch(batch Batch) error
PutBatch implements the Store interface.
func (*LevelDBStore) Seek ¶
func (s *LevelDBStore) Seek(key []byte, f func(k, v []byte))
Seek implements the Store interface.
type MemCachedStore ¶
type MemCachedStore struct { MemoryStore // contains filtered or unexported fields }
MemCachedStore is a wrapper around persistent store that caches all changes being made for them to be later flushed in one batch.
func NewMemCachedStore ¶
func NewMemCachedStore(lower Store) *MemCachedStore
NewMemCachedStore creates a new MemCachedStore object.
func (*MemCachedStore) Close ¶
func (s *MemCachedStore) Close() error
Close implements Store interface, clears up memory and closes the lower layer Store.
func (*MemCachedStore) Get ¶
func (s *MemCachedStore) Get(key []byte) ([]byte, error)
Get implements the Store interface.
func (*MemCachedStore) GetBatch ¶
func (s *MemCachedStore) GetBatch() *MemBatch
GetBatch returns currently accumulated changeset.
func (*MemCachedStore) Persist ¶
func (s *MemCachedStore) Persist() (int, error)
Persist flushes all the MemoryStore contents into the (supposedly) persistent store ps.
func (*MemCachedStore) Seek ¶
func (s *MemCachedStore) Seek(key []byte, f func(k, v []byte))
Seek implements the Store interface.
type MemoryBatch ¶
type MemoryBatch struct {
MemoryStore
}
MemoryBatch is an in-memory batch compatible with MemoryStore.
func (*MemoryBatch) Delete ¶
func (b *MemoryBatch) Delete(k []byte)
Delete implements Batch interface.
func (*MemoryBatch) Put ¶
func (b *MemoryBatch) Put(k, v []byte)
Put implements the Batch interface.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory implementation of a Store, mainly used for testing. Do not use MemoryStore in production.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new MemoryStore object.
func (*MemoryStore) Batch ¶
func (s *MemoryStore) Batch() Batch
Batch implements the Batch interface and returns a compatible Batch.
func (*MemoryStore) Close ¶
func (s *MemoryStore) Close() error
Close implements Store interface and clears up memory. Never returns an error.
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(key []byte) error
Delete implements Store interface. Never returns an error.
func (*MemoryStore) Get ¶
func (s *MemoryStore) Get(key []byte) ([]byte, error)
Get implements the Store interface.
func (*MemoryStore) Put ¶
func (s *MemoryStore) Put(key, value []byte) error
Put implements the Store interface. Never returns an error.
func (*MemoryStore) PutBatch ¶
func (s *MemoryStore) PutBatch(batch Batch) error
PutBatch implements the Store interface. Never returns an error.
func (*MemoryStore) Seek ¶
func (s *MemoryStore) Seek(key []byte, f func(k, v []byte))
Seek implements the Store interface.
func (*MemoryStore) SeekAll ¶ added in v0.92.0
func (s *MemoryStore) SeekAll(key []byte, f func(k, v []byte))
SeekAll is like seek but also iterates over deleted items.
type RedisDBOptions ¶
type RedisDBOptions struct { Addr string `yaml:"Addr"` Password string `yaml:"Password"` DB int `yaml:"DB"` }
RedisDBOptions configuration for RedisDB.
type RedisStore ¶
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore holds the client and maybe later some more metadata.
func NewRedisStore ¶
func NewRedisStore(cfg RedisDBOptions) (*RedisStore, error)
NewRedisStore returns an new initialized - ready to use RedisStore object.
func (*RedisStore) Delete ¶
func (s *RedisStore) Delete(k []byte) error
Delete implements the Store interface.
func (*RedisStore) Get ¶
func (s *RedisStore) Get(k []byte) ([]byte, error)
Get implements the Store interface.
func (*RedisStore) Put ¶
func (s *RedisStore) Put(k, v []byte) error
Put implements the Store interface.
func (*RedisStore) PutBatch ¶
func (s *RedisStore) PutBatch(b Batch) error
PutBatch implements the Store interface.
func (*RedisStore) Seek ¶
func (s *RedisStore) Seek(k []byte, f func(k, v []byte))
Seek implements the Store interface.
type Store ¶
type Store interface { Batch() Batch Delete(k []byte) error Get([]byte) ([]byte, error) Put(k, v []byte) error PutBatch(Batch) error // Seek can guarantee that provided key (k) and value (v) are the only valid until the next call to f. // Key and value slices should not be modified. Seek(k []byte, f func(k, v []byte)) Close() error }
Store is anything that can persist and retrieve the blockchain. information.
func NewStore ¶
func NewStore(cfg DBConfiguration) (Store, error)
NewStore creates storage with preselected in configuration database type.