lnwire: add new FundingFlag type for OpenChannel
In this commit we add a new type to the lnwire package: FundingFlag. This type will serve as an enum to describe the possible flags that can be used within the ChannelFlags field in the OpenChannel struct. We also define the first assigned flag: FFAnnounceChannel, which indicates if the initiator of the funding flow wishes to announce the channel to the greater network.
This commit is contained in:
parent
1b69940a84
commit
9a2c2cdf86
@ -86,6 +86,12 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if _, err := w.Write(b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
case FundingFlag:
|
||||
var b [1]byte
|
||||
b[0] = uint8(e)
|
||||
if _, err := w.Write(b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
case uint16:
|
||||
var b [2]byte
|
||||
binary.BigEndian.PutUint16(b[:], e)
|
||||
@ -388,6 +394,12 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
*e = b[0]
|
||||
case *FundingFlag:
|
||||
var b [1]uint8
|
||||
if _, err := r.Read(b[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
*e = FundingFlag(b[0])
|
||||
case *uint16:
|
||||
var b [2]byte
|
||||
if _, err := io.ReadFull(r, b[:]); err != nil {
|
||||
|
@ -154,7 +154,7 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
FeePerKiloWeight: uint32(r.Int63()),
|
||||
CsvDelay: uint16(r.Int31()),
|
||||
MaxAcceptedHTLCs: uint16(r.Int31()),
|
||||
ChannelFlags: byte(r.Int31()),
|
||||
ChannelFlags: FundingFlag(uint8(r.Int31())),
|
||||
}
|
||||
|
||||
if _, err := r.Read(req.ChainHash[:]); err != nil {
|
||||
|
@ -8,6 +8,17 @@ import (
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
|
||||
// FundingFlag represents the possible bit mask values for the ChannelFlags
|
||||
// field within the OpenChannel struct.
|
||||
type FundingFlag uint8
|
||||
|
||||
const (
|
||||
// FFAnnounceChannel is a FundingFlag that when set, indicates the
|
||||
// initiator of a funding flow wishes to announce the channel to the
|
||||
// greater network.
|
||||
FFAnnounceChannel FundingFlag = 1 << iota
|
||||
)
|
||||
|
||||
// OpenChannel is the message Alice sends to Bob if we should like to create a
|
||||
// channel with Bob where she's the sole provider of funds to the channel.
|
||||
// Single funder channels simplify the initial funding workflow, are supported
|
||||
@ -101,7 +112,7 @@ type OpenChannel struct {
|
||||
// channel to specify further behavior surrounding the channel.
|
||||
// Currently, the least significant bit of this bit field indicates the
|
||||
// initiator of the channel wishes to advertise this channel publicly.
|
||||
ChannelFlags byte
|
||||
ChannelFlags FundingFlag
|
||||
}
|
||||
|
||||
// A compile time check to ensure OpenChannel implements the lnwire.Message
|
||||
|
Loading…
Reference in New Issue
Block a user