channeldb: add ChannelFlags to OpenChannel struct

This commit adds the ChannelFlags field, of type
lnwire.FundingFlags, to the OpenChannel struct,
including serialization for database storage.
This is done to preserve the flags that were
sent during channel opening, currently used
to determine whether a channel should be made
public or not after opening.
This commit is contained in:
Johan T. Halseth 2017-11-13 17:09:59 -08:00 committed by Olaoluwa Osuntokun
parent 17d1d5dc9c
commit 48e22219c0
2 changed files with 16 additions and 4 deletions

View File

@ -316,6 +316,10 @@ type OpenChannel struct {
// for normal transactional use.
NumConfsRequired uint16
// ChannelFlags holds the flags that were sent as part of the
// open_channel message.
ChannelFlags lnwire.FundingFlag
// IdentityPub is the identity public key of the remote node this
// channel has been established with.
IdentityPub *btcec.PublicKey
@ -1442,8 +1446,8 @@ func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
channel.ShortChanID, channel.IsPending, channel.IsInitiator,
channel.FundingBroadcastHeight, channel.NumConfsRequired,
channel.IdentityPub, channel.Capacity, channel.TotalMSatSent,
channel.TotalMSatReceived,
channel.ChannelFlags, channel.IdentityPub, channel.Capacity,
channel.TotalMSatSent, channel.TotalMSatReceived,
); err != nil {
return err
}
@ -1542,8 +1546,8 @@ func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
&channel.ShortChanID, &channel.IsPending, &channel.IsInitiator,
&channel.FundingBroadcastHeight, &channel.NumConfsRequired,
&channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent,
&channel.TotalMSatReceived,
&channel.ChannelFlags, &channel.IdentityPub, &channel.Capacity,
&channel.TotalMSatSent, &channel.TotalMSatReceived,
); err != nil {
return err
}

View File

@ -135,6 +135,10 @@ func writeElement(w io.Writer, element interface{}) error {
if err := binary.Write(w, byteOrder, e); err != nil {
return err
}
case lnwire.FundingFlag:
if err := binary.Write(w, byteOrder, e); err != nil {
return err
}
default:
return fmt.Errorf("Unknown type in writeElement: %T", e)
@ -287,6 +291,10 @@ func readElement(r io.Reader, element interface{}) error {
if err := binary.Read(r, byteOrder, e); err != nil {
return err
}
case *lnwire.FundingFlag:
if err := binary.Read(r, byteOrder, e); err != nil {
return err
}
default:
return fmt.Errorf("Unknown type in readElement: %T", e)