storage

package
v0.51.0-pre Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: MIT Imports: 17 Imported by: 0

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

func CurrentBlockHeight

func CurrentBlockHeight(s Store) (uint32, error)

CurrentBlockHeight returns the current block height found in the underlying Store.

func CurrentHeaderHeight

func CurrentHeaderHeight(s Store) (i uint32, h util.Uint256, err error)

CurrentHeaderHeight returns the current header height and hash from the underlying Store.

func HeaderHashes

func HeaderHashes(s Store) ([]util.Uint256, error)

HeaderHashes returns a sorted list of header hashes retrieved from the given underlying Store.

func PutVersion

func PutVersion(s Store, v string) error

PutVersion will store the given version in the underlying Store.

func Version

func Version(s Store) (string, error)

Version will attempt to get the current version stored in the underlying Store.

Types

type Batch

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

Batch represents an abstraction on top of batch operations. Each Store implementation is responsible of casting a Batch to its appropriate type.

type BoltDBBatch

type BoltDBBatch struct {
	// contains filtered or unexported fields
}

BoltDBBatch simple batch implementation to satisfy the Store interface.

func (*BoltDBBatch) Len

func (b *BoltDBBatch) Len() int

Len implements the Batch interface.

func (*BoltDBBatch) Put

func (b *BoltDBBatch) Put(k, v []byte)

Put implements the Batch interface.

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) 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
	STContract        KeyPrefix = 0x50
	STStorage         KeyPrefix = 0x70
	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 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 return 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) 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 MemoryBatch

type MemoryBatch struct {
	// contains filtered or unexported fields
}

MemoryBatch a in-memory batch compatible with MemoryStore.

func (*MemoryBatch) Len

func (b *MemoryBatch) Len() int

Len implements the Batch interface.

func (*MemoryBatch) Put

func (b *MemoryBatch) Put(k, v []byte)

Put implements the Batch interface.

type MemoryStore

type MemoryStore struct {
	*sync.RWMutex
	// 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.

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.

func (*MemoryStore) PutBatch

func (s *MemoryStore) PutBatch(batch Batch) error

PutBatch implements the Store interface.

func (*MemoryStore) Seek

func (s *MemoryStore) Seek(key []byte, f func(k, v []byte))

Seek implements the Store interface.

type RedisBatch

type RedisBatch struct {
	// contains filtered or unexported fields
}

RedisBatch simple batch implementation to satisfy the Store interface.

func NewRedisBatch

func NewRedisBatch() *RedisBatch

NewRedisBatch returns a new ready to use RedisBatch.

func (*RedisBatch) Len

func (b *RedisBatch) Len() int

Len implements the Batch interface.

func (*RedisBatch) Put

func (b *RedisBatch) Put(k, v []byte)

Put implements the Batch 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) 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
	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