lnwire: add LastBlockHeight method to QueryChannelRange

This commit is contained in:
Wilmer Paulino 2019-12-13 16:08:30 -08:00
parent c7c0853531
commit c4723ce3db
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -2,6 +2,7 @@ package lnwire
import ( import (
"io" "io"
"math"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
) )
@ -75,3 +76,14 @@ func (q *QueryChannelRange) MaxPayloadLength(uint32) uint32 {
// 32 + 4 + 4 // 32 + 4 + 4
return 40 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)
}