package
0.1.1
Repository: https://github.com/tendermint/btcd.git
Documentation: pkg.go.dev

# README

database

Build Status ISC License GoDoc

Package database provides a block and metadata storage database.

Please note that this package is intended to enable btcd to support different database backends and is not something that a client can directly access as only one entity can have the database open at a time (for most database backends), and that entity will be btcd.

When a client wants programmatic access to the data provided by btcd, they'll likely want to use the rpcclient package which makes use of the JSON-RPC API.

However, this package could be extremely useful for any applications requiring Bitcoin block storage capabilities.

The default backend, ffldb, has a strong focus on speed, efficiency, and robustness. It makes use of leveldb for the metadata, flat files for block storage, and strict checksums in key areas to ensure data integrity.

Feature Overview

  • Key/value metadata store
  • Bitcoin block storage
  • Efficient retrieval of block headers and regions (transactions, scripts, etc)
  • Read-only and read-write transactions with both manual and managed modes
  • Nested buckets
  • Iteration support including cursors with seek capability
  • Supports registration of backend databases
  • Comprehensive test coverage

Installation and Updating

$ go get -u github.com/btcsuite/btcd/database

Examples

  • Basic Usage Example
    Demonstrates creating a new database and using a managed read-write transaction to store and retrieve metadata.

  • Block Storage and Retrieval Example
    Demonstrates creating a new database, using a managed read-write transaction to store a block, and then using a managed read-only transaction to fetch the block.

License

Package database is licensed under the copyfree ISC License.

# Packages

No description provided by the author
Package ffldb implements a driver for the database package that uses leveldb for the backing metadata and flat files for block storage.

# Functions

Create initializes and opens a database for the specified type.
DisableLog disables all library log output.
Open opens an existing database for the specified type.
RegisterDriver adds a backend database driver to available interfaces.
SupportedDrivers returns a slice of strings that represent the database drivers that have been registered and are therefore supported.
UseLogger uses a specified Logger to output package logging info.

# Constants

ErrBlockExists indicates a block with the provided hash already exists in the database.
ErrBlockNotFound indicates a block with the provided hash does not exist in the database.
ErrBlockRegionInvalid indicates a region that exceeds the bounds of the specified block was requested.
ErrBucketExists indicates an attempt to create a bucket that already exists.
ErrBucketNameRequired indicates an attempt to create a bucket with a blank name.
ErrBucketNotFound indicates an attempt to access a bucket that has not been created yet.
ErrCorruption indicates a checksum failure occurred which invariably means the database is corrupt.
ErrDbAlreadyOpen indicates open was called on a database that is already open.
ErrDbDoesNotExist indicates open is called for a database that does not exist.
ErrDbExists indicates create is called for a database that already exists.
ErrDbNotOpen indicates a database instance is accessed before it is opened or after it is closed.
ErrDbTypeRegistered indicates two different database drivers attempt to register with the name database type.
ErrDbUnknownType indicates there is no driver registered for the specified database type.
ErrDriverSpecific indicates the Err field is a driver-specific error.
ErrIncompatibleValue indicates the value in question is invalid for the specific requested operation.
ErrInvalid indicates the specified database is not valid.
ErrKeyRequired indicates at attempt to insert a zero-length key.
ErrKeyTooLarge indicates an attmempt to insert a key that is larger than the max allowed key size.
ErrTxClosed indicates an attempt was made to commit or rollback a transaction that has already had one of those operations performed.
ErrTxNotWritable indicates an operation that requires write access to the database was attempted against a read-only transaction.
ErrValueTooLarge indicates an attmpt to insert a value that is larger than max allowed value size.

# Structs

BlockRegion specifies a particular region of a block identified by the specified hash, given an offset and length.
Driver defines a structure for backend drivers to use when they registered themselves as a backend which implements the DB interface.
Error provides a single type for errors that can happen during database operation.

# Interfaces

Bucket represents a collection of key/value pairs.
Cursor represents a cursor over key/value pairs and nested buckets of a bucket.
DB provides a generic interface that is used to store bitcoin blocks and related metadata.
Tx represents a database transaction.

# Type aliases

ErrorCode identifies a kind of error.