dbbadger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnspentBadgerholdKeyPrefix       = "bh_Unspent"
	LockedUnspentBadgerholdKeyPrefix = "bh_LockedUnspent"
)
View Source
const (
	TradeBadgerholdKeyPrefix = "bh_Trade"
)

Variables

View Source
var (
	// ErrMarketInvalidRequest ...
	ErrMarketInvalidRequest = errors.New("requested market is null")
	// ErrMarketNotFound ...
	ErrMarketNotFound = errors.New("market not found")
)
View Source
var (
	// ErrTradeNotFound ...
	ErrTradeNotFound = errors.New("trade not found")
)
View Source
var (
	// ErrVaultNotFound ...
	ErrVaultNotFound = errors.New("vault not found")
)

Functions

func EncodeKey

func EncodeKey(key interface{}, typeName string) ([]byte, error)

EncodeKey encodes key values with a type prefix which allows multiple different types to exist in the badger DB

func JSONDecode

func JSONDecode(data []byte, value interface{}) error

JSONDecode is a custom JSON based decoder for badger

func JSONEncode

func JSONEncode(value interface{}) ([]byte, error)

JSONEncode is a custom JSON based encoder for badger

func NewMarketRepositoryImpl

func NewMarketRepositoryImpl(db *DbManager) domain.MarketRepository

NewMarketRepositoryImpl initialize a badger implementation of the domain.MarketRepository

func NewTradeRepositoryImpl

func NewTradeRepositoryImpl(db *DbManager) domain.TradeRepository

func NewUnspentRepositoryImpl

func NewUnspentRepositoryImpl(db *DbManager) domain.UnspentRepository

func NewVaultRepositoryImpl

func NewVaultRepositoryImpl(db *DbManager) domain.VaultRepository

Types

type DbManager

type DbManager struct {
	Store        *badgerhold.Store
	PriceStore   *badgerhold.Store
	UnspentStore *badgerhold.Store
}

DbManager holds all the badgerhold stores in a single data structure.

func NewDbManager

func NewDbManager(baseDbDir string, logger badger.Logger) (*DbManager, error)

NewDbManager opens (or creates if not exists) the badger store on disk. It expects a base data dir and an optional logger. It creates a dedicated directory for main and prices stores, while the unspent repository lives in memory.

func (DbManager) NewPricesTransaction

func (d DbManager) NewPricesTransaction() ports.Transaction

NewPricesTransaction implements the DbManager interface

func (DbManager) NewTransaction

func (d DbManager) NewTransaction() ports.Transaction

NewTransaction implements the DbManager interface

func (DbManager) NewUnspentsTransaction

func (d DbManager) NewUnspentsTransaction() ports.Transaction

NewUnspentsTransaction implements the DbManager interface

func (DbManager) RunPricesTransaction

func (d DbManager) RunPricesTransaction(
	ctx context.Context,
	readOnly bool,
	handler func(ctx context.Context) (interface{}, error),
) (interface{}, error)

RunPricesTransaction invokes the given handler and retries in case the unspents transaction returns a conflict error

func (DbManager) RunTransaction

func (d DbManager) RunTransaction(
	ctx context.Context,
	readOnly bool,
	handler func(ctx context.Context) (interface{}, error),
) (interface{}, error)

RunTransaction invokes the given handler and retries in case the transaction returns a conflict error

func (DbManager) RunUnspentsTransaction

func (d DbManager) RunUnspentsTransaction(
	ctx context.Context,
	readOnly bool,
	handler func(ctx context.Context) (interface{}, error),
) (interface{}, error)

RunUnspentsTransaction invokes the given handler and retries in case the unspents transaction returns a conflict error

type LockedUnspent

type LockedUnspent struct {
	TradeID uuid.UUID
}

Jump to

Keyboard shortcuts

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