mempool: Add HeaderByHash to Config.
This adds a HeaderByHash method to the mempool Config. This will be used as part of the automatic ticket revocations changes in a subsequent commit.
This commit is contained in:
parent
08921f6e46
commit
7bedd7dc0a
@ -106,6 +106,11 @@ type Config struct {
|
||||
// the current best chain.
|
||||
BestHeight func() int64
|
||||
|
||||
// HeaderByHash returns the block header identified by the given hash or an
|
||||
// error if it doesn't exist. Note that this will return headers from both
|
||||
// the main chain and any side chains.
|
||||
HeaderByHash func(hash *chainhash.Hash) (wire.BlockHeader, error)
|
||||
|
||||
// PastMedianTime defines the function to use in order to access the
|
||||
// median time calculated from the point-of-view of the current chain
|
||||
// tip within the best chain.
|
||||
|
||||
@ -157,6 +157,18 @@ func (s *fakeChain) SetHeight(height int64) {
|
||||
s.Unlock()
|
||||
}
|
||||
|
||||
// HeaderByHash returns the header for the block with the given hash from the
|
||||
// fake chain instance. Blocks can be added to the instance with the AddBlock
|
||||
// function.
|
||||
func (s *fakeChain) HeaderByHash(hash *chainhash.Hash) (wire.BlockHeader, error) {
|
||||
block, ok := s.blocks[*hash]
|
||||
if !ok {
|
||||
return wire.BlockHeader{}, fmt.Errorf("unable to find block %v in fake "+
|
||||
"chain", hash)
|
||||
}
|
||||
return block.MsgBlock().Header, nil
|
||||
}
|
||||
|
||||
// PastMedianTime returns the current median time associated with the fake chain
|
||||
// instance.
|
||||
func (s *fakeChain) PastMedianTime() time.Time {
|
||||
@ -818,6 +830,7 @@ func newPoolHarness(chainParams *chaincfg.Params) (*poolHarness, []spendableOutp
|
||||
BlockByHash: chain.BlockByHash,
|
||||
BestHash: chain.BestHash,
|
||||
BestHeight: chain.BestHeight,
|
||||
HeaderByHash: chain.HeaderByHash,
|
||||
PastMedianTime: chain.PastMedianTime,
|
||||
CalcSequenceLock: chain.CalcSequenceLock,
|
||||
TSpendMinedOnAncestor: chain.TSpendMinedOnAncestor,
|
||||
|
||||
@ -3558,6 +3558,7 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB,
|
||||
BlockByHash: s.chain.BlockByHash,
|
||||
BestHash: func() *chainhash.Hash { return &s.chain.BestSnapshot().Hash },
|
||||
BestHeight: func() int64 { return s.chain.BestSnapshot().Height },
|
||||
HeaderByHash: s.chain.HeaderByHash,
|
||||
CalcSequenceLock: s.chain.CalcSequenceLock,
|
||||
SubsidyCache: s.subsidyCache,
|
||||
SigCache: s.sigCache,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user