datastore

package
v0.0.0-...-8576238 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is the error returned for when a resource could not be
	// found in the datastore.
	ErrNotFound = errors.New("not found")
)

Functions

This section is empty.

Types

type BlockManager

type BlockManager interface {
	Creater
	Configurer
	Stater
	BlockStorer
}

BlockManager pulls together all interfaces required to implement a database storage driver for storing coin blocks.

type BlockStorer

type BlockStorer interface {
	// Last returns the last known block stored of the provided coin.
	Last(ctx context.Context, coin string) (*capi.Block, error)
	// List enables filtering for blocks in the datastore.
	List(ctx context.Context, coin string, query ListBlocksRequest) ([]*capi.Block, error)
	// Create creating a block in the datastore.
	Create(ctx context.Context, coin string, newEntity *capi.Block) (*capi.Block, error)
	// CreateBulk enables bulk creation of blocks in the datastore.
	CreateBulk(ctx context.Context, coin string, query []*capi.Block) ([]*capi.Block, error)
	// Get enables retrieving a block given an ID.
	Get(ctx context.Context, coin string, id string) (block *capi.Block, err error)
	// GetByHash enables retrieving a block given a block Hash.
	GetByHash(ctx context.Context, coin string, hash string) (block *capi.Block, err error)
	// Update enables updating a block resource in the datastore.
	Update(ctx context.Context, coin string, id string, updatedEntity *capi.Block) (*capi.Block, error)
	// Delete removes a block from the datastore.
	Delete(ctx context.Context, coin string, id string) (err error)
}

BlockManager enables datastore implementers to filter for, create, update and delete blockchain block resources for multiple coins.

type Blocks

type Blocks struct {
	// dbpath is the path to where the boltdb datafiles are stored.
	DBPath string

	// DB contains the boltdb handler to access the underlying buckets.
	DB *bolt.DB

	// Coins contains the list of coins supported by the underlying DB.
	Coins []string
	// Options are specific boltdb configurations.
	Options *bolt.Options
	// contains filtered or unexported fields
}

Blocks provides a boltdb backed datastore implementation for storing blocks.

func (*Blocks) Close

func (b *Blocks) Close() error

Close implements stater.Close.

func (*Blocks) Configure

func (b *Blocks) Configure(ctx context.Context, coins []string) (err error)

Configure implements Configurer.Configure

func (*Blocks) Create

func (b *Blocks) Create(ctx context.Context, coin string, newEntity *capi.Block) (block *capi.Block, err error)

Create creating a block in the datastore.

func (*Blocks) CreateBulk

func (b *Blocks) CreateBulk(ctx context.Context, coin string, newEntities []*capi.Block) (blocks []*capi.Block, err error)

CreateBulk enables bulk creation of blocks in the datastore.

func (*Blocks) CreateSchema

func (b *Blocks) CreateSchema(ctx context.Context, coins []string) (err error)

CreateSchema implements datastore.Creater

func (*Blocks) Delete

func (b *Blocks) Delete(ctx context.Context, coin string, id string) (err error)

Delete removes a block from the datastore.

func (*Blocks) Get

func (b *Blocks) Get(ctx context.Context, coin string, id string) (block *capi.Block, err error)

Get enables retrieving a block given an ID.

func (*Blocks) GetByHash

func (b *Blocks) GetByHash(ctx context.Context, coin string, hash string) (block *capi.Block, err error)

GetByHash enables retrieving a block given a block hash.

func (*Blocks) IsCreated

func (b *Blocks) IsCreated(ctx context.Context, coins []string) bool

IsCreated returns a bool to trigger required creation logic

func (*Blocks) Last

func (b *Blocks) Last(ctx context.Context, coin string) (block *capi.Block, err error)

LastID returns the last known ID stored of the provided coin.

func (*Blocks) List

func (b *Blocks) List(ctx context.Context, coin string, query ListBlocksRequest) (blocks []*capi.Block, err error)

List enables filtering for blocks in the datastore.

func (*Blocks) Update

func (b *Blocks) Update(ctx context.Context, coin string, id string, updatedEntity *capi.Block) (block *capi.Block, err error)

Update enables updating a block resource in the datastore.

type Configurer

type Configurer interface {
	// Configure provides a hook to configure the database.
	// coins is provided as a parameter in case individual tables require being
	// configured per coin.
	Configure(ctx context.Context, coins []string) error
}

Configurer provides an interface for required configuration that may be required on startup. For example, ensuring indices are configured e.t.c.

type CreateTransactionRequest

type CreateTransactionRequest struct {
	Transaction *capi.Transaction
}

CreateTransactionRequest creates a Transaction.

type Creater

type Creater interface {
	// CreateSchema provides a hook for the underlying storage to perform
	// operations in order to create the required store for a given resource.
	// coins is provided as a parameter in case individual tables are required
	// to be created per coin.
	CreateSchema(ctx context.Context, coins []string) error
}

Creater provides an interface for any required setup that may be needed on first initialization for a given datastore.

type Datastore

type Datastore struct {
	Blocks       BlockManager
	Transactions TransactionManager
	// contains filtered or unexported fields
}

Datastore provides the concrete implementation of a datastore.

func NewBoltDB

func NewBoltDB(config *capi.Config) (*Datastore, error)

NewBoltDB returns a new BoltDB backed datastore.

func NewDatastore

func NewDatastore(config *capi.Config) (store *Datastore, err error)

NewDatastore returns a configured datastore.

func (*Datastore) Close

func (s *Datastore) Close() error

func (*Datastore) ConfigureSchemas

func (s *Datastore) ConfigureSchemas(ctx context.Context) error

ConfigureSchemas ensures that on start up, each resource is configured.

func (*Datastore) CreateSchemas

func (s *Datastore) CreateSchemas(ctx context.Context) error

CreateSchemas checks that each resource is created, if not, creates it.

type DeleteTransactionRequest

type DeleteTransactionRequest struct {
	ID string
}

DeleteTransactionRequest deletes the specified transaction.

type ListBlocksRequest

type ListBlocksRequest struct {
	// WalletID enables filtering blocks based on the a Wallet.
	WalletID string `json:"walletId"`
	// TransactionID enables filtering blocks based on a Transaction.
	TransactionID string `json:"TransactionId"`
}

ListBlocksRequest enables filtering blocks based on the following parameters.

type ListTransactionsRequest

type ListTransactionsRequest struct {
	// WalletID enables filtering transactions based on a Wallet.
	WalletID string `json:"walletId"`
}

ListTransactionsRequest enables filtering transactions based on the following parameters.

type Manager

type Manager interface {
	Creater
	Configurer
	Stater
}

Manager brings together the interfaces required to manage a datastore.

type Stater

type Stater interface {
	// IsCreated returns a bool to trigger crea
	IsCreated(ctx context.Context, coins []string) bool
	// Close enables datastore connections to be closed.
	Close() error
}

Stater provides simple state management for the datastore in order to provide state information based on coin.

type TransactionManager

type TransactionManager interface {
	Creater
	Configurer
	Stater
	TransactionStorer
}

TransactionManager pulls together all interfaces required to implement a database storage driver for storing coin transactions.

type TransactionStorer

type TransactionStorer interface {
	// List enables filtering for transactions in the datastore.
	List(ctx context.Context, coin string, query ListTransactionsRequest) (transactions []*capi.Transaction, err error)
	// Create creating a transaction in the datastore.
	Create(ctx context.Context, coin string, query CreateTransactionRequest) (transaction *capi.Transaction, err error)
	// CreateBulk enables bulk creation of transactions in the datastore.
	CreateBulk(ctx context.Context, coin string, query []CreateTransactionRequest) (transactions []*capi.Transaction, err error)
	// Update enables updating a transaction resource in the datastore.
	Update(ctx context.Context, coin string, query UpdateTransactionRequest) (transaction *capi.Transaction, err error)
	// Delete removes a transaction from the datastore.
	Delete(ctx context.Context, coin string, query DeleteTransactionRequest) (err error)
}

TransactionManager enables datastore implementers to filter for, create, update and delete blockchain transaction resources for multiple coins.

type Transactions

type Transactions struct {
	// dbpath is the path to where the boltdb datafiles are stored.
	DBPath string

	// DB contains the boltdb handler to access the underlying buckets.
	DB *bolt.DB

	// Coins contains the list of coins supported by the underlying DB.
	Coins []string
	// Options are specific boltdb configurations.
	Options *bolt.Options
	// contains filtered or unexported fields
}

Transactions provides a boltdb backed datastore implementation for storing blockchain transactions.

func (*Transactions) Close

func (t *Transactions) Close() error

Close implements stater.Close.

func (*Transactions) Configure

func (b *Transactions) Configure(ctx context.Context, coins []string) (err error)

Configure implements Configurer.Configure

func (*Transactions) Create

func (b *Transactions) Create(ctx context.Context, coin string, query CreateTransactionRequest) (transaction *capi.Transaction, err error)

Create creates a transaction in the datastore.

func (*Transactions) CreateBulk

func (b *Transactions) CreateBulk(ctx context.Context, coin string, query []CreateTransactionRequest) (transactions []*capi.Transaction, err error)

CreateBulk enables bulk creation of transactions in the datastore.

func (*Transactions) CreateSchema

func (b *Transactions) CreateSchema(ctx context.Context, coins []string) (err error)

CreateSchema implements datastore.Creater

func (*Transactions) Delete

func (b *Transactions) Delete(ctx context.Context, coin string, query DeleteTransactionRequest) (err error)

Delete removes a transaction from the datastore.

func (*Transactions) IsCreated

func (b *Transactions) IsCreated(ctx context.Context, coins []string) bool

IsCreated returns a bool to trigger crea

func (*Transactions) List

func (b *Transactions) List(ctx context.Context, coin string, query ListTransactionsRequest) (transactions []*capi.Transaction, err error)

List enables filtering for transactions in the datastore.

func (*Transactions) Update

func (b *Transactions) Update(ctx context.Context, coin string, query UpdateTransactionRequest) (transaction *capi.Transaction, err error)

Update enables updating a transaction resource in the datastore.

type UpdateTransactionRequest

type UpdateTransactionRequest struct {
	ID          string
	Transaction *capi.Transaction
}

UpdateTransactionRequest updates the transaction, with the newly provided resource.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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