chain: add GetBlockHeader support

This commit allows neutrino to simulate the GetBlockHeader RPC, and
allows chain client code to use the call with both btcd/RPC back end
and the neutrino back end.
This commit is contained in:
Alex 2017-09-20 14:33:12 -06:00 committed by Olaoluwa Osuntokun
parent e06434ed75
commit 1b6d7a7ee3
2 changed files with 9 additions and 0 deletions

View file

@ -20,6 +20,7 @@ type Interface interface {
GetBestBlock() (*chainhash.Hash, int32, error)
GetBlock(*chainhash.Hash) (*wire.MsgBlock, error)
GetBlockHash(int64) (*chainhash.Hash, error)
GetBlockHeader(*chainhash.Hash) (*wire.BlockHeader, error)
BlockStamp() (*waddrmgr.BlockStamp, error)
SendRawTransaction(*wire.MsgTx, bool) (*chainhash.Hash, error)
Rescan(*chainhash.Hash, []btcutil.Address, []*wire.OutPoint) error

View file

@ -143,6 +143,14 @@ func (s *NeutrinoClient) GetBlockHash(height int64) (*chainhash.Hash, error) {
return &hash, nil
}
// GetBlockHeader returns the block header for the given block hash, or an error
// if the client has been shut down or the hash doesn't exist or is unknown.
func (s *NeutrinoClient) GetBlockHeader(
blockHash *chainhash.Hash) (*wire.BlockHeader, error) {
header, _, err := s.CS.BlockHeaders.FetchHeader(blockHash)
return header, err
}
// SendRawTransaction replicates the RPC client's SendRawTransaction command.
func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (
*chainhash.Hash, error) {