btc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URL      string
	Password string
	Username string
}

Config is a struct that contains the configuration needed to connect to a Bitcoin node.

type Digest

type Digest [32]byte

Digests represents a 32-byte little-endian Bitcoin digest.

func (Digest) String

func (d Digest) String() string

type Handle

type Handle interface {
	// GetHeaderByHeight returns the block header from the longest block chain at
	// the given block height.
	GetHeaderByHeight(height int64) (*Header, error)

	// GetHeaderByDigest returns the block header for given digest (hash).
	GetHeaderByDigest(digest Digest) (*Header, error)

	// GetBlockCount returns the number of blocks in the longest blockchain
	GetBlockCount() (int64, error)
}

Handle represents a handle to the Bitcoin chain.

func Connect

func Connect(
	ctx context.Context,
	config *Config,
) (Handle, error)

Connect connects to the Bitcoin chain and returns a chain handle.

func ConnectLocal

func ConnectLocal() (Handle, error)

ConnectLocal connects to the local Bitcoin chain and returns a chain handle.

type Header struct {
	// Hash is the hash of the block.
	Hash Digest
	// Height is the height of the block in the Bitcoin blockchain.
	Height int64
	// PrevHash is the hash of the previous block.
	PrevHash Digest
	// MerkleRoot is the hash of the root of the merkle tree of transactions in
	// the block.
	MerkleRoot Digest
	// Raw is the serialized data of the block header (80-byte little-endian).
	Raw []byte
}

Header represents a Bitcoin block header.

func (*Header) Equals

func (h *Header) Equals(other *Header) bool

func (*Header) String

func (h *Header) String() string

type LocalChain

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

LocalChain represents a local Bitcoin chain.

func (*LocalChain) AppendHeader

func (lc *LocalChain) AppendHeader(header *Header)

AppendHeader appends internal header for testing purposes.

func (*LocalChain) GetBlockCount

func (lc *LocalChain) GetBlockCount() (int64, error)

GetBlockCount returns the number of blocks in the longest blockchain

func (*LocalChain) GetHeaderByDigest

func (lc *LocalChain) GetHeaderByDigest(
	digest Digest,
) (*Header, error)

GetHeaderByDigest returns the block header for given digest (hash).

func (*LocalChain) GetHeaderByHeight

func (lc *LocalChain) GetHeaderByHeight(height int64) (*Header, error)

GetHeaderByHeight returns the block header from the longest block chain at the given block height.

func (*LocalChain) SetHeaders

func (lc *LocalChain) SetHeaders(headers []*Header)

SetHeaders sets internal headers for testing purposes.

func (*LocalChain) SetOrphanedHeaders

func (lc *LocalChain) SetOrphanedHeaders(headers []*Header)

SetOrphanedHeaders sets internal orphaned headers for testing purposes.

Jump to

Keyboard shortcuts

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