btclightclient

package
v0.0.0-...-149a895 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MaxForkAge = 8

Variables

This section is empty.

Functions

func BlockHeaderFromHex

func BlockHeaderFromHex(hexStr string) (wire.BlockHeader, error)

func VerifyHash256Merkle

func VerifyHash256Merkle(proof []byte, index uint) bool

follow logic on bitcoin-spv. This is check the tx belong to merkle tree hash in BTC header.

Types

type BTCLightClient

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

func NewBTCLightClient

func NewBTCLightClient(params *chaincfg.Params) *BTCLightClient

func NewBTCLightClientWithData

func NewBTCLightClientWithData(params *chaincfg.Params, headers []wire.BlockHeader, start int) *BTCLightClient

TODO: make it more simple

func (*BTCLightClient) BlocksPerRetarget

func (lc *BTCLightClient) BlocksPerRetarget() int32

func (*BTCLightClient) ChainParams

func (lc *BTCLightClient) ChainParams() *chaincfg.Params

func (*BTCLightClient) CheckHeader

func (lc *BTCLightClient) CheckHeader(parent wire.BlockHeader, header wire.BlockHeader) error

func (*BTCLightClient) CleanUpFork

func (lc *BTCLightClient) CleanUpFork() error

We follow: - select the next finalize block base on 2 conditions:

  • this fork len greater than MaxForkAge
  • this fork is the most powerful fork

- Remove all invalid forks - Update map(height => block) in btcStore

func (*BTCLightClient) CreateNewFork

func (lc *BTCLightClient) CreateNewFork(parent *LightBlock, header wire.BlockHeader) error

func (*BTCLightClient) FindPreviousCheckpoint

func (lc *BTCLightClient) FindPreviousCheckpoint() (blockchain.HeaderCtx, error)

func (*BTCLightClient) ForkAge

func (lc *BTCLightClient) ForkAge(bh chainhash.Hash) (int32, error)

func (*BTCLightClient) InsertHeader

func (lc *BTCLightClient) InsertHeader(header wire.BlockHeader) error

We assume we always insert valid header. Acctually, Cosmos can revert a state when module return error so this assumtion is reasonable

func (*BTCLightClient) LatestBlockHash

func (lc *BTCLightClient) LatestBlockHash() chainhash.Hash

func (*BTCLightClient) MaxRetargetTimespan

func (lc *BTCLightClient) MaxRetargetTimespan() int64

func (*BTCLightClient) MinRetargetTimespan

func (lc *BTCLightClient) MinRetargetTimespan() int64

func (*BTCLightClient) Status

func (lc *BTCLightClient) Status()

query status, use for test

func (*BTCLightClient) VerifyCheckpoint

func (lc *BTCLightClient) VerifyCheckpoint(height int32, hash *chainhash.Hash) bool

func (*BTCLightClient) VerifyTXID

func (lc *BTCLightClient) VerifyTXID(txHash *chainhash.Hash, utxoIdx uint, header *wire.BlockHeader, merklePath []byte) bool

func (*BTCLightClient) VerifyUTXO

func (lc *BTCLightClient) VerifyUTXO(tx *btcutil.Tx, utxoIdx uint, merkleRoot *chainhash.Hash, merklePath []byte) bool

verify UTXO (identified as tx and UTXO index) is in a blocks' Merkle root

type BlockMedianTimeSource

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

func (*BlockMedianTimeSource) AddTimeSample

func (b *BlockMedianTimeSource) AddTimeSample(string, time.Time)

func (*BlockMedianTimeSource) AdjustedTime

func (b *BlockMedianTimeSource) AdjustedTime() time.Time

func (*BlockMedianTimeSource) Offset

func (b *BlockMedianTimeSource) Offset() time.Duration

type Hash256Digest

type Hash256Digest [32]byte

func DoubleHash

func DoubleHash(in []byte) Hash256Digest

func Hash256MerkleStep

func Hash256MerkleStep(a, b []byte) Hash256Digest

Hash256MerkleStep concatenates and hashes two inputs for merkle proving

type HeaderContext

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

func NewHeaderContext

func NewHeaderContext(lightBlock *LightBlock, store Store, fork []*LightBlock) *HeaderContext

func (*HeaderContext) Bits

func (h *HeaderContext) Bits() uint32

func (*HeaderContext) Height

func (h *HeaderContext) Height() int32

func (*HeaderContext) Parent

func (h *HeaderContext) Parent() blockchain.HeaderCtx

func (*HeaderContext) RelativeAncestorCtx

func (h *HeaderContext) RelativeAncestorCtx(
	distance int32) blockchain.HeaderCtx

func (*HeaderContext) Timestamp

func (h *HeaderContext) Timestamp() int64

type LightBlock

type LightBlock struct {
	Height int32
	Header wire.BlockHeader
}

func NewLightBlock

func NewLightBlock(height int32, header wire.BlockHeader) *LightBlock

func (*LightBlock) CalcWork

func (lb *LightBlock) CalcWork() *big.Int

type MemStore

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

func NewMemStore

func NewMemStore() *MemStore

func (*MemStore) AddBlock

func (s *MemStore) AddBlock(parent *LightBlock, header wire.BlockHeader) error

func (*MemStore) IsForkHead

func (s *MemStore) IsForkHead(h chainhash.Hash) bool

func (*MemStore) LatestBlockHashOfFork

func (s *MemStore) LatestBlockHashOfFork() []chainhash.Hash

TODO: convert to iterator rather than returning a map

func (*MemStore) LatestCheckPoint

func (s *MemStore) LatestCheckPoint() *LightBlock

func (*MemStore) LatestHeight

func (s *MemStore) LatestHeight() int64

func (*MemStore) LightBlockAtHeight

func (s *MemStore) LightBlockAtHeight(height int64) *LightBlock

func (*MemStore) LightBlockByHash

func (s *MemStore) LightBlockByHash(hash chainhash.Hash) *LightBlock

func (*MemStore) MostDifficultFork

func (s *MemStore) MostDifficultFork() *LightBlock

func (*MemStore) RemoveBlock

func (s *MemStore) RemoveBlock(h chainhash.Hash)

func (*MemStore) SetBlock

func (s *MemStore) SetBlock(lb *LightBlock, previousPower *big.Int)

func (*MemStore) SetIsHead

func (s *MemStore) SetIsHead(bh chainhash.Hash)

func (*MemStore) SetIsNotHead

func (s *MemStore) SetIsNotHead(bh chainhash.Hash)

func (*MemStore) SetLatestCheckPoint

func (s *MemStore) SetLatestCheckPoint(lb *LightBlock)

func (*MemStore) SetLightBlockByHeight

func (s *MemStore) SetLightBlockByHeight(lb *LightBlock)

func (*MemStore) TotalWorkAtBlock

func (s *MemStore) TotalWorkAtBlock(hash chainhash.Hash) *big.Int

type Store

type Store interface {
	LightBlockAtHeight(int64) *LightBlock
	LatestHeight() int64
	LightBlockByHash(hash chainhash.Hash) *LightBlock
	// check hash h is hash of latest block in remind fork sets.
	IsForkHead(h chainhash.Hash) bool
	LatestCheckPoint() *LightBlock
	AddBlock(parent *LightBlock, header wire.BlockHeader) error
	SetIsHead(bh chainhash.Hash)
	SetIsNotHead(bh chainhash.Hash)
	TotalWorkAtBlock(bh chainhash.Hash) *big.Int
	SetBlock(lb *LightBlock, perviousPower *big.Int)
	SetLatestCheckPoint(lb *LightBlock)
	SetLightBlockByHeight(lb *LightBlock)
	MostDifficultFork() *LightBlock
	LatestBlockHashOfFork() []chainhash.Hash
	RemoveBlock(h chainhash.Hash)
}

Jump to

Keyboard shortcuts

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