txdb

package
v0.0.0-...-6d4bf48 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package txdb provides storage for Chain Protocol blockchain data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeSnapshot

func DecodeSnapshot(data []byte) (*state.Snapshot, error)

DecodeSnapshot decodes a snapshot from the Chain Core's binary, protobuf representation of the snapshot.

func ListenBlocks

func ListenBlocks(ctx context.Context, dbURL string) (<-chan uint64, error)

Types

type Store

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

A Store encapsulates storage for blockchain validation. It satisfies the interface protocol.Store, and provides additional methods for querying current data.

func NewStore

func NewStore(db pg.DB) *Store

NewStore creates and returns a new Store object.

For testing purposes, it is usually much faster and more convenient to use package chain/protocol/memstore instead.

func (*Store) FinalizeBlock

func (s *Store) FinalizeBlock(ctx context.Context, height uint64) error

func (*Store) GetBlock

func (s *Store) GetBlock(ctx context.Context, height uint64) (*legacy.Block, error)

GetBlock looks up the block with the provided block height. If no block is found at that height, it returns an error that wraps sql.ErrNoRows.

func (*Store) GetRawBlock

func (s *Store) GetRawBlock(ctx context.Context, height uint64) ([]byte, error)

GetRawBlock queries the database for the block at the provided height. The block is returned as raw bytes.

func (*Store) GetSnapshot

func (s *Store) GetSnapshot(ctx context.Context, height uint64) ([]byte, error)

GetSnapshot returns the state snapshot stored at the provided height, in Chain Core's binary protobuf representation. If no snapshot exists at the provided height, an error is returned.

func (*Store) Height

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

Height returns the height of the blockchain.

func (*Store) LatestSnapshot

func (s *Store) LatestSnapshot(ctx context.Context) (*state.Snapshot, uint64, error)

LatestSnapshot returns the most recent state snapshot stored in the database and its corresponding block height.

func (*Store) LatestSnapshotInfo

func (s *Store) LatestSnapshotInfo(ctx context.Context) (height uint64, size uint64, err error)

LatestSnapshotInfo returns the height and size of the most recent state snapshot stored in the database.

func (*Store) SaveBlock

func (s *Store) SaveBlock(ctx context.Context, block *legacy.Block) error

SaveBlock persists a new block in the database.

func (*Store) SaveSnapshot

func (s *Store) SaveSnapshot(ctx context.Context, height uint64, snapshot *state.Snapshot) error

SaveSnapshot saves a state snapshot to the database.

Directories

Path Synopsis
internal
storage
Package storage is a generated protocol buffer package.
Package storage is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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