btc

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 9 Imported by: 0

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