mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 07:00:55 +02:00
lnwire: add QueryOptions to QueryChannelRange
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"math"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/lightningnetwork/lnd/tlv"
|
||||
)
|
||||
|
||||
// QueryChannelRange is a message sent by a node in order to query the
|
||||
@@ -27,6 +28,10 @@ type QueryChannelRange struct {
|
||||
// channel ID's should be sent for.
|
||||
NumBlocks uint32
|
||||
|
||||
// QueryOptions is an optional feature bit vector that can be used to
|
||||
// specify additional query options.
|
||||
QueryOptions *QueryOptions
|
||||
|
||||
// ExtraData is the set of data that was appended to this message to
|
||||
// fill out the full maximum transport message size. These fields can
|
||||
// be used to specify optional data such as custom TLV fields.
|
||||
@@ -35,7 +40,9 @@ type QueryChannelRange struct {
|
||||
|
||||
// NewQueryChannelRange creates a new empty QueryChannelRange message.
|
||||
func NewQueryChannelRange() *QueryChannelRange {
|
||||
return &QueryChannelRange{}
|
||||
return &QueryChannelRange{
|
||||
ExtraData: make([]byte, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// A compile time check to ensure QueryChannelRange implements the
|
||||
@@ -46,20 +53,42 @@ var _ Message = (*QueryChannelRange)(nil)
|
||||
// passed io.Reader observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (q *QueryChannelRange) Decode(r io.Reader, pver uint32) error {
|
||||
return ReadElements(r,
|
||||
q.ChainHash[:],
|
||||
&q.FirstBlockHeight,
|
||||
&q.NumBlocks,
|
||||
&q.ExtraData,
|
||||
func (q *QueryChannelRange) Decode(r io.Reader, _ uint32) error {
|
||||
err := ReadElements(
|
||||
r, q.ChainHash[:], &q.FirstBlockHeight, &q.NumBlocks,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var tlvRecords ExtraOpaqueData
|
||||
if err := ReadElements(r, &tlvRecords); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var queryOptions QueryOptions
|
||||
typeMap, err := tlvRecords.ExtractRecords(&queryOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the corresponding TLV types if they were included in the stream.
|
||||
if val, ok := typeMap[QueryOptionsRecordType]; ok && val == nil {
|
||||
q.QueryOptions = &queryOptions
|
||||
}
|
||||
|
||||
if len(tlvRecords) != 0 {
|
||||
q.ExtraData = tlvRecords
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Encode serializes the target QueryChannelRange into the passed io.Writer
|
||||
// observing the protocol version specified.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (q *QueryChannelRange) Encode(w *bytes.Buffer, pver uint32) error {
|
||||
func (q *QueryChannelRange) Encode(w *bytes.Buffer, _ uint32) error {
|
||||
if err := WriteBytes(w, q.ChainHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -72,6 +101,15 @@ func (q *QueryChannelRange) Encode(w *bytes.Buffer, pver uint32) error {
|
||||
return err
|
||||
}
|
||||
|
||||
recordProducers := make([]tlv.RecordProducer, 0, 1)
|
||||
if q.QueryOptions != nil {
|
||||
recordProducers = append(recordProducers, q.QueryOptions)
|
||||
}
|
||||
err := EncodeMessageExtraData(&q.ExtraData, recordProducers...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return WriteBytes(w, q.ExtraData)
|
||||
}
|
||||
|
||||
@@ -93,3 +131,14 @@ func (q *QueryChannelRange) LastBlockHeight() uint32 {
|
||||
}
|
||||
return uint32(lastBlockHeight)
|
||||
}
|
||||
|
||||
// WithTimestamps returns true if the query has asked for timestamps too.
|
||||
func (q *QueryChannelRange) WithTimestamps() bool {
|
||||
if q.QueryOptions == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
queryOpts := RawFeatureVector(*q.QueryOptions)
|
||||
|
||||
return queryOpts.IsSet(QueryOptionTimestampBit)
|
||||
}
|
||||
|
Reference in New Issue
Block a user