Documentation
¶
Overview ¶
Package db contains block related CRUD functionality.
Index ¶
- Constants
- type Block
- type NewBlock
- type NewBlockDoc
- type Store
- func (s Store) AddBlock(ctx context.Context, block NewBlock) (string, string, error)
- func (s Store) AddBlocks(ctx context.Context, blocks []Block) (bool, error)
- func (s Store) GetBlockByHash(ctx context.Context, blockHash string) (Block, error)
- func (s Store) GetBlockByNum(ctx context.Context, blockNum uint64) (Block, error)
- func (s Store) GetBlockTxnSpeed(ctx context.Context) (float64, error)
- func (s Store) GetBlocksPagination(ctx context.Context, latestBlockNum int64, order string, pageNo int64, ...) ([]Block, int64, int64, error)
- func (s Store) GetEarliestSyncedRoundNumber(ctx context.Context) (uint64, error)
- func (s Store) GetLastSyncedRoundNumber(ctx context.Context) (uint64, bool, error)
- func (s Store) GetLatestBlock(ctx context.Context) (Block, error)
- func (s Store) GetNumOfBlocks(ctx context.Context) (int64, error)
Constants ¶
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 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) GetBlockByHash ¶
GetBlockByHash retrieves a block from CouchDB based upon the block hash.
func (Store) GetBlockByNum ¶
GetBlockByNum gets a block from CouchDB based on round number.
func (Store) GetBlockTxnSpeed ¶
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 ¶
GetEarliestSyncedRoundNumber retrieves the earliest round number that is synced to CouchDB.
func (Store) GetLastSyncedRoundNumber ¶
GetLastSyncedRoundNumber retrieves the last round number that is synced to CouchDB.
func (Store) GetLatestBlock ¶
GetLatestBlock retrieves the block that is last synced to Couch.