multi: add ToChannelAnnouncement helper on ChannelEdgeInfo
So that we have one place that converts from our `models` struct to the `lnwire.ChannelAnnouncement` struct. The commit also refactors netann.CreateChanAnnouncement to only take a ChannelEdgeInfo and get the proof from there instead of needing the proof to be passed in separately. Add ToChannelAnnouncement() method to ChannelEdgeInfo that converts the model struct to a lnwire.ChannelAnnouncement1 message. This: - Centralizes the conversion logic in one place instead of scattered across multiple call sites - Validates that AuthProof is present (can't create announcement without proof) - Currently only supports v1 channels, returning error for v2 Refactor netann.CreateChanAnnouncement to use this helper and remove the separate chanProof parameter since proof is now accessed from within ChannelEdgeInfo. This improves encapsulation and reduces parameter count.
This commit is contained in:
5 files changed
+82
-80
No files matched your search
@@ -199,3 +199,66 @@ func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
|
||||
"this channel")
|
||||
}
|
||||
}
|
||||
|
||||
// ToChannelAnnouncement converts the ChannelEdgeInfo to a
|
||||
// lnwire.ChannelAnnouncement1 message. Returns an error if AuthProof is nil
|
||||
// or if the version is not v1.
|
||||
func (c *ChannelEdgeInfo) ToChannelAnnouncement() (
|
||||
*lnwire.ChannelAnnouncement1, error) {
|
||||
|
||||
// We currently only support v1 channel announcements.
|
||||
if c.Version != lnwire.GossipVersion1 {
|
||||
return nil, fmt.Errorf("unsupported channel version: %d",
|
||||
c.Version)
|
||||
}
|
||||
|
||||
// If there's no auth proof, we can't create a full channel
|
||||
// announcement.
|
||||
if c.AuthProof == nil {
|
||||
return nil, fmt.Errorf("cannot create channel announcement " +
|
||||
"without auth proof")
|
||||
}
|
||||
|
||||
chanID := lnwire.NewShortChanIDFromInt(c.ChannelID)
|
||||
chanAnn := &lnwire.ChannelAnnouncement1{
|
||||
ShortChannelID: chanID,
|
||||
NodeID1: c.NodeKey1Bytes,
|
||||
NodeID2: c.NodeKey2Bytes,
|
||||
ChainHash: c.ChainHash,
|
||||
BitcoinKey1: c.BitcoinKey1Bytes,
|
||||
BitcoinKey2: c.BitcoinKey2Bytes,
|
||||
Features: c.Features.RawFeatureVector,
|
||||
ExtraOpaqueData: c.ExtraOpaqueData,
|
||||
}
|
||||
|
||||
var err error
|
||||
chanAnn.NodeSig1, err = lnwire.NewSigFromECDSARawSignature(
|
||||
c.AuthProof.NodeSig1(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chanAnn.NodeSig2, err = lnwire.NewSigFromECDSARawSignature(
|
||||
c.AuthProof.NodeSig2(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chanAnn.BitcoinSig1, err = lnwire.NewSigFromECDSARawSignature(
|
||||
c.AuthProof.BitcoinSig1(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
chanAnn.BitcoinSig2, err = lnwire.NewSigFromECDSARawSignature(
|
||||
c.AuthProof.BitcoinSig2(),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return chanAnn, nil
|
||||
}
|
||||
Reference in new issue
Block a user