mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-03 08:20:30 +02:00
multi: add GetBlockHeader to BlockChainIO
This commit is contained in:
parent
35bfd27467
commit
b04927f688
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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.
|
||||
//
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user