From c4723ce3db715602596fc1af87f935a49dcea2b1 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 13 Dec 2019 16:08:30 -0800 Subject: [PATCH] lnwire: add LastBlockHeight method to QueryChannelRange --- lnwire/query_channel_range.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lnwire/query_channel_range.go b/lnwire/query_channel_range.go index f910cb98..9546fcd3 100644 --- a/lnwire/query_channel_range.go +++ b/lnwire/query_channel_range.go @@ -2,6 +2,7 @@ package lnwire import ( "io" + "math" "github.com/btcsuite/btcd/chaincfg/chainhash" ) @@ -75,3 +76,14 @@ func (q *QueryChannelRange) MaxPayloadLength(uint32) uint32 { // 32 + 4 + 4 return 40 } + +// LastBlockHeight returns the last block height covered by the range of a +// QueryChannelRange message. +func (q *QueryChannelRange) LastBlockHeight() uint32 { + // Handle overflows by casting to uint64. + lastBlockHeight := uint64(q.FirstBlockHeight) + uint64(q.NumBlocks) - 1 + if lastBlockHeight > math.MaxUint32 { + return math.MaxUint32 + } + return uint32(lastBlockHeight) +}