storage

package
v0.78.2-pre Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Bucket = []byte("DB")

Bucket represents bucket used in boltdb to store all the data.

View Source
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

func AppendPrefix(k KeyPrefix, b []byte) []byte

AppendPrefix appends byteslice b to the given KeyPrefix. AppendKeyPrefix(SYSVersion, []byte{0x00, 0x01})

func AppendPrefixInt

func AppendPrefixInt(k KeyPrefix, n int) []byte

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

type Batch interface {
	Delete(k []byte)
	Put(k, v []byte)
}

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) Close

func (s *BoltDBStore) Close() error

Close releases all db resources.

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
	STCoin            KeyPrefix = 0x44
	STSpentCoin       KeyPrefix = 0x45
	STTransfers       KeyPrefix = 0x47
	STValidator       KeyPrefix = 0x48
	STAsset           KeyPrefix = 0x4c
	STNotification    KeyPrefix = 0x4d
	STContract        KeyPrefix = 0x50
	STMigration       KeyPrefix = 0x51
	STStorage         KeyPrefix = 0x70
	STNEP5Transfers   KeyPrefix = 0x72
	STNEP5Balances    KeyPrefix = 0x73
	IXHeaderHashList  KeyPrefix = 0x80
	IXValidatorsCount KeyPrefix = 0x90
	SYSCurrentBlock   KeyPrefix = 0xc0
	SYSCurrentHeader  KeyPrefix = 0xc1
	SYSVersion        KeyPrefix = 0xf0
)

KeyPrefix constants.

func (KeyPrefix) Bytes

func (k KeyPrefix) Bytes() []byte

Bytes returns the bytes representation of KeyPrefix.

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte

	Exists bool
}

KeyValue represents key-value pair.

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 MemBatch

type MemBatch struct {
	Put     []KeyValue
	Deleted []KeyValue
}

MemBatch represents a changeset to be persisted.

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.

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) Batch

func (s *RedisStore) Batch() Batch

Batch implements the Store interface.

func (*RedisStore) Close

func (s *RedisStore) Close() error

Close implements the Store interface.

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.

Jump to

Keyboard shortcuts

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