From 1b6d7a7ee3ccdf4e27553d1b0df89a439fee2e13 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 20 Sep 2017 14:33:12 -0600 Subject: [PATCH] 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. --- chain/interface.go | 1 + chain/neutrino.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/chain/interface.go b/chain/interface.go index 3039445..1608d4d 100644 --- a/chain/interface.go +++ b/chain/interface.go @@ -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 diff --git a/chain/neutrino.go b/chain/neutrino.go index 373e301..b77c665 100644 --- a/chain/neutrino.go +++ b/chain/neutrino.go @@ -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) {