db

package
v0.0.0-...-8401909 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package db contains block related CRUD functionality.

Index

Constants

View Source
const (
	DocType = "block"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	NewBlockDoc
	ID  string `json:"_id,omitempty"`
	Rev string `json:"_rev,omitempty"`
}

Block represents the data structure of a block document.

type NewBlock

type NewBlock struct {
	models.Block
	Proposer  string `json:"proposer"`
	BlockHash string `json:"block-hash"`
}

NewBlock represents the data structure for constructing a new block data

type NewBlockDoc

type NewBlockDoc struct {
	NewBlock
	DocType string `json:"doc_type"`
}

type Store

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

func NewStore

func NewStore(log *zap.SugaredLogger, couchClient *kivik.Client, dbName string) Store

NewStore constructs a block store for api access.

func (Store) AddBlock

func (s Store) AddBlock(ctx context.Context, block NewBlock) (string, string, error)

AddBlock adds a block to CouchDB using block hash as ID.

func (Store) AddBlocks

func (s Store) AddBlocks(ctx context.Context, blocks []Block) (bool, error)

AddBlocks add blocks to CouchDB using their block hashes as IDs.

func (Store) GetBlockByHash

func (s Store) GetBlockByHash(ctx context.Context, blockHash string) (Block, error)

GetBlockByHash retrieves a block from CouchDB based upon the block hash.

func (Store) GetBlockByNum

func (s Store) GetBlockByNum(ctx context.Context, blockNum uint64) (Block, error)

GetBlockByNum gets a block from CouchDB based on round number.

func (Store) GetBlockTxnSpeed

func (s Store) GetBlockTxnSpeed(ctx context.Context) (float64, error)

GetBlockTxnSpeed compares the latest 10 blocks it could find in the database and finds the average transaction speed

func (Store) GetBlocksPagination

func (s Store) GetBlocksPagination(ctx context.Context, latestBlockNum int64, order string, pageNo int64, limit int64) ([]Block, int64, int64, error)

GetBlocksPagination retrieves a list of blocks based upon the following parameters: latestBlockNum: the latest block number that user knows about order: desc/asc pageNo: the number of pages the user wants to look at limit: number of blocks per page https://docs.couchdb.org/en/main/ddocs/views/pagination.html

func (Store) GetEarliestSyncedRoundNumber

func (s Store) GetEarliestSyncedRoundNumber(ctx context.Context) (uint64, error)

GetEarliestSyncedRoundNumber retrieves the earliest round number that is synced to CouchDB.

func (Store) GetLastSyncedRoundNumber

func (s Store) GetLastSyncedRoundNumber(ctx context.Context) (uint64, bool, error)

GetLastSyncedRoundNumber retrieves the last round number that is synced to CouchDB.

func (Store) GetLatestBlock

func (s Store) GetLatestBlock(ctx context.Context) (Block, error)

GetLatestBlock retrieves the block that is last synced to Couch.

func (Store) GetNumOfBlocks

func (s Store) GetNumOfBlocks(ctx context.Context) (int64, error)

GetNumOfBlocks retrieves the number of blocks that exist in the database.

Jump to

Keyboard shortcuts

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