multi: add GetBlockHeader to BlockChainIO

This commit is contained in:
Jonathan Harvey-Buschel committed 2023-10-27 11:05:27 -04:00
1 parent 7a8803e3cf
commit 6edd1e1220
7 files changed
+61

No files matched your search

+4
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
+7
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
}
+18
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(
+9
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.
//
+3
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
+6
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
}
+14
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