btc

package
v0.0.0-...-420fffb Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeaderLen is the fixed length of a Bitcoin block header in bytes.
	HeaderLen = 80
	// HeaderHashLen is length of hash of a BTC header
	HeaderHashLen = 32
)

Variables

This section is empty.

Functions

func GetValidBackends

func GetValidBackends() map[SupportedBackend]bool

GetValidBackends returns a map of supported Bitcoin backend types

func GetValidNetParams

func GetValidNetParams() map[string]bool

GetValidNetParams returns a map of valid Bitcoin network parameters

func NewBlockHeader

func NewBlockHeader(data []byte) (*wire.BlockHeader, error)

NewBlockHeader creates a block header from bytes. Returns error if deserialization fails.

Types

type BlockEvent

type BlockEvent struct {
	BlockHeader *wire.BlockHeader
	Type        EventType
	Height      int64
}

BlockEvent contains information about a blockchain event

func NewBlockEvent

func NewBlockEvent(evtType EventType, blockHeight int64, blockHeader *wire.BlockHeader) *BlockEvent

NewBlockEvent creates a new block event with the given parameters

type EventType

type EventType int

EventType represents different types of blockchain events

const (
	// BlockDisconnected is triggered when a block is removed from the chain
	BlockDisconnected EventType = iota
	// BlockConnected is triggered when a block is added to the chain
	BlockConnected
)

type HeaderBytes

type HeaderBytes []byte

HeaderBytes represents a Bitcoin block header as a byte slice.

func NewHeaderBytesFromBlockHeader

func NewHeaderBytesFromBlockHeader(header *wire.BlockHeader) HeaderBytes

NewHeaderBytesFromBlockHeader creates a new HeaderBytes from a wire.BlockHeader.

func (*HeaderBytes) Eq

func (b *HeaderBytes) Eq(other *HeaderBytes) bool

Eq checks if two HeaderBytes are equal by comparing their hashes.

func (*HeaderBytes) FromBlockHeader

func (b *HeaderBytes) FromBlockHeader(header *wire.BlockHeader)

FromBlockHeader converts a wire.BlockHeader to HeaderBytes. Panics if serialization or validation fails.

func (*HeaderBytes) Hash

func (b *HeaderBytes) Hash() *HeaderHashBytes

Hash returns the hash of the block header as HeaderHashBytes.

func (HeaderBytes) Marshal

func (b HeaderBytes) Marshal() ([]byte, error)

Marshal returns the byte slice representation of HeaderBytes.

func (*HeaderBytes) Size

func (b *HeaderBytes) Size() int

Size returns the length of the HeaderBytes in bytes.

func (HeaderBytes) ToBlockHeader

func (b HeaderBytes) ToBlockHeader() *wire.BlockHeader

ToBlockHeader converts HeaderBytes to a wire.BlockHeader. Panics if conversion fails.

func (*HeaderBytes) Unmarshal

func (b *HeaderBytes) Unmarshal(data []byte) error

Unmarshal validates and sets HeaderBytes from a byte slice. Returns error if data length is not 80 bytes or if data is not a valid block header.

type HeaderHashBytes

type HeaderHashBytes []byte

HeaderHashBytes represents a Bitcoin header hash as a byte slice

func NewHeaderHashBytesFromChainhash

func NewHeaderHashBytesFromChainhash(hash *chainhash.Hash) HeaderHashBytes

NewHeaderHashBytesFromChainhash creates a new HeaderHashBytes from a chainhash.Hash

func (*HeaderHashBytes) Eq

func (b *HeaderHashBytes) Eq(other *HeaderHashBytes) bool

Eq checks if two HeaderHashBytes are equal

func (*HeaderHashBytes) FromChainhash

func (b *HeaderHashBytes) FromChainhash(hash *chainhash.Hash)

FromChainhash sets the HeaderHashBytes from a chainhash.Hash

func (HeaderHashBytes) Marshal

func (b HeaderHashBytes) Marshal() ([]byte, error)

Marshal returns the byte slice representation of the header hash

func (*HeaderHashBytes) Size

func (b *HeaderHashBytes) Size() int

Size returns the length of the header hash in bytes

func (*HeaderHashBytes) String

func (b *HeaderHashBytes) String() string

String returns the string representation of the header hash

func (HeaderHashBytes) ToChainhash

func (b HeaderHashBytes) ToChainhash() *chainhash.Hash

ToChainhash converts the HeaderHashBytes to a chainhash.Hash pointer

func (*HeaderHashBytes) Unmarshal

func (b *HeaderHashBytes) Unmarshal(data []byte) error

Unmarshal validates and sets the header hash from a byte slice

type SupportedBackend

type SupportedBackend string

SupportedBackend represents a supported Bitcoin backend implementation (btcd, bitcoind)

const (
	Btcd     SupportedBackend = "btcd"
	Bitcoind SupportedBackend = "bitcoind"
)

Constants defining the supported Bitcoin backend implementations.

func (SupportedBackend) String

func (b SupportedBackend) String() string

type SupportedNetwork

type SupportedNetwork string

SupportedNetwork represents a supported Bitcoin network type (mainnet, testnet, etc.)

const (
	Mainnet SupportedNetwork = "mainnet"
	Testnet SupportedNetwork = "testnet"
	Simnet  SupportedNetwork = "simnet"
	Regtest SupportedNetwork = "regtest"
	Signet  SupportedNetwork = "signet"
)

Constants defining the supported Bitcoin networks.

func (SupportedNetwork) String

func (n SupportedNetwork) String() string

Jump to

Keyboard shortcuts

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