storage

package
v0.74.1-pre Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 13 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 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"`
}

DBConfiguration describes configuration for DB. Supported: 'levelDB', 'redisDB'.

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
	STAccount         KeyPrefix = 0x40
	STCoin            KeyPrefix = 0x44
	STSpentCoin       KeyPrefix = 0x45
	STValidator       KeyPrefix = 0x48
	STAsset           KeyPrefix = 0x4c
	STNotification    KeyPrefix = 0x4d
	STContract        KeyPrefix = 0x50
	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(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