Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod+lightning+chainkit: update to lnd v0.17.1-beta.rc1 and expose GetBlockHeader #161

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions chainkit_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type ChainKitClient interface {
GetBlock(ctx context.Context, hash chainhash.Hash) (*wire.MsgBlock,
error)

// GetBlockHeader returns a block header given the corresponding block
// hash.
GetBlockHeader(ctx context.Context,
hash chainhash.Hash) (*wire.BlockHeader, error)

// GetBestBlock returns the latest block hash and current height of the
// valid most-work chain.
GetBestBlock(ctx context.Context) (chainhash.Hash, int32, error)
Expand Down Expand Up @@ -77,6 +82,33 @@ func (s *chainKitClient) GetBlock(ctxParent context.Context,
return msgBlock, nil
}

// GetBlockHeader returns a block header given the corresponding block hash.
func (s *chainKitClient) GetBlockHeader(ctxParent context.Context,
jharveyb marked this conversation as resolved.
Show resolved Hide resolved
hash chainhash.Hash) (*wire.BlockHeader, error) {

ctx, cancel := context.WithTimeout(ctxParent, s.timeout)
defer cancel()

macaroonAuth := s.chainMac.WithMacaroonAuth(ctx)
req := &chainrpc.GetBlockHeaderRequest{
BlockHash: hash[:],
}
resp, err := s.client.GetBlockHeader(macaroonAuth, req)
if err != nil {
return nil, err
}

// Convert raw block header bytes into wire.BlockHeader.
blockHeader := &wire.BlockHeader{}
blockReader := bytes.NewReader(resp.RawBlockHeader)
err = blockHeader.Deserialize(blockReader)
if err != nil {
return nil, err
}

return blockHeader, nil
}

// GetBestBlock returns the block hash and current height from the valid
// most-work chain.
func (s *chainKitClient) GetBestBlock(ctxParent context.Context) (chainhash.Hash,
Expand Down
Loading