Documentation ¶
Index ¶
- Constants
- func BlockHeaderFromHex(hexStr string) (wire.BlockHeader, error)
- func VerifyHash256Merkle(proof []byte, index uint) bool
- type BTCLightClient
- func (lc *BTCLightClient) BlocksPerRetarget() int32
- func (lc *BTCLightClient) ChainParams() *chaincfg.Params
- func (lc *BTCLightClient) CheckHeader(parent wire.BlockHeader, header wire.BlockHeader) error
- func (lc *BTCLightClient) CleanUpFork() error
- func (lc *BTCLightClient) CreateNewFork(parent *LightBlock, header wire.BlockHeader) error
- func (lc *BTCLightClient) FindPreviousCheckpoint() (blockchain.HeaderCtx, error)
- func (lc *BTCLightClient) ForkAge(bh chainhash.Hash) (int32, error)
- func (lc *BTCLightClient) InsertHeader(header wire.BlockHeader) error
- func (lc *BTCLightClient) LatestBlockHash() chainhash.Hash
- func (lc *BTCLightClient) MaxRetargetTimespan() int64
- func (lc *BTCLightClient) MinRetargetTimespan() int64
- func (lc *BTCLightClient) Status()
- func (lc *BTCLightClient) VerifyCheckpoint(height int32, hash *chainhash.Hash) bool
- func (lc *BTCLightClient) VerifyTXID(txHash *chainhash.Hash, utxoIdx uint, header *wire.BlockHeader, ...) bool
- func (lc *BTCLightClient) VerifyUTXO(tx *btcutil.Tx, utxoIdx uint, merkleRoot *chainhash.Hash, merklePath []byte) bool
- type BlockMedianTimeSource
- type Hash256Digest
- type HeaderContext
- type LightBlock
- type MemStore
- func (s *MemStore) AddBlock(parent *LightBlock, header wire.BlockHeader) error
- func (s *MemStore) IsForkHead(h chainhash.Hash) bool
- func (s *MemStore) LatestBlockHashOfFork() []chainhash.Hash
- func (s *MemStore) LatestCheckPoint() *LightBlock
- func (s *MemStore) LatestHeight() int64
- func (s *MemStore) LightBlockAtHeight(height int64) *LightBlock
- func (s *MemStore) LightBlockByHash(hash chainhash.Hash) *LightBlock
- func (s *MemStore) MostDifficultFork() *LightBlock
- func (s *MemStore) RemoveBlock(h chainhash.Hash)
- func (s *MemStore) SetBlock(lb *LightBlock, previousPower *big.Int)
- func (s *MemStore) SetIsHead(bh chainhash.Hash)
- func (s *MemStore) SetIsNotHead(bh chainhash.Hash)
- func (s *MemStore) SetLatestCheckPoint(lb *LightBlock)
- func (s *MemStore) SetLightBlockByHeight(lb *LightBlock)
- func (s *MemStore) TotalWorkAtBlock(hash chainhash.Hash) *big.Int
- type Store
Constants ¶
View Source
const MaxForkAge = 8
Variables ¶
This section is empty.
Functions ¶
func BlockHeaderFromHex ¶
func BlockHeaderFromHex(hexStr string) (wire.BlockHeader, error)
func VerifyHash256Merkle ¶
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) 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) LatestBlockHashOfFork ¶
TODO: convert to iterator rather than returning a map
func (*MemStore) LatestCheckPoint ¶
func (s *MemStore) LatestCheckPoint() *LightBlock
func (*MemStore) LatestHeight ¶
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 (*MemStore) SetIsNotHead ¶
func (*MemStore) SetLatestCheckPoint ¶
func (s *MemStore) SetLatestCheckPoint(lb *LightBlock)
func (*MemStore) SetLightBlockByHeight ¶
func (s *MemStore) SetLightBlockByHeight(lb *LightBlock)
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) }
Click to show internal directories.
Click to hide internal directories.