multi: add GetBlockHeader to BlockChainIO

This commit is contained in:
Jonathan Harvey-Buschel 2023-10-26 12:09:56 -04:00 committed by Olaoluwa Osuntokun
parent 35bfd27467
commit b04927f688
7 changed files with 61 additions and 0 deletions

View File

@ -187,6 +187,10 @@ func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
return nil, nil
}
func (*mockChainIO) GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error) {
return nil, nil
}
type chanArbTestCtx struct {
t *testing.T

View File

@ -32,3 +32,10 @@ func (c *ChainIO) GetBlockHash(blockHeight int64) (*chainhash.Hash, error) {
func (c *ChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error) {
return nil, nil
}
// GetBlockHeader currently returns dummy values.
func (c *ChainIO) GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader,
error) {
return nil, nil
}

View File

@ -45,6 +45,24 @@ func (h *HarnessRPC) GetBlock(
return resp
}
// GetBlockHeader makes an RPC call to chain kit client's GetBlockHeader and
// asserts.
func (h *HarnessRPC) GetBlockHeader(
req *chainrpc.GetBlockHeaderRequest) *chainrpc.GetBlockHeaderResponse {
if req == nil {
req = &chainrpc.GetBlockHeaderRequest{}
}
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel()
resp, err := h.ChainKit.GetBlockHeader(ctxt, req)
h.NoError(err, "GetBlockHeader")
return resp
}
// GetBlockHash makes an RPC call to chain kit client's GetBlockHash and
// asserts.
func (h *HarnessRPC) GetBlockHash(

View File

@ -149,6 +149,15 @@ func (b *BtcWallet) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
return b.chain.GetBlock(blockHash)
}
// GetBlockHeader returns a block header for the block with the given hash.
//
// This method is a part of the lnwallet.BlockChainIO interface.
func (b *BtcWallet) GetBlockHeader(
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
return b.chain.GetBlockHeader(blockHash)
}
// GetBlockHash returns the hash of the block in the best blockchain at the
// given height.
//

View File

@ -562,6 +562,9 @@ type BlockChainIO interface {
// GetBlock returns the block in the main chain identified by the given
// hash.
GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
// GetBlockHeader returns the block header for the given block hash.
GetBlockHeader(blockHash *chainhash.Hash) (*wire.BlockHeader, error)
}
// MessageSigner represents an abstract object capable of signing arbitrary

View File

@ -364,3 +364,9 @@ func (*mockChainIO) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock,
return nil, nil
}
func (*mockChainIO) GetBlockHeader(
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
return nil, nil
}

View File

@ -228,6 +228,20 @@ func (m *mockChain) GetBlock(blockHash *chainhash.Hash) (*wire.MsgBlock, error)
return block, nil
}
func (m *mockChain) GetBlockHeader(
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
m.RLock()
defer m.RUnlock()
block, ok := m.blocks[*blockHash]
if !ok {
return nil, fmt.Errorf("block not found")
}
return &block.Header, nil
}
type mockChainView struct {
sync.RWMutex