2020-03-18 02:23:01 +03:00
|
|
|
package netann
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/btcec"
|
2020-04-06 03:06:38 +03:00
|
|
|
"github.com/lightningnetwork/lnd/input"
|
2020-03-18 02:23:01 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SignAnnouncement signs any type of gossip message that is announced on the
|
|
|
|
// network.
|
|
|
|
func SignAnnouncement(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey,
|
2020-04-06 03:06:38 +03:00
|
|
|
msg lnwire.Message) (input.Signature, error) {
|
2020-03-18 02:23:01 +03:00
|
|
|
|
|
|
|
var (
|
|
|
|
data []byte
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
switch m := msg.(type) {
|
|
|
|
case *lnwire.ChannelAnnouncement:
|
|
|
|
data, err = m.DataToSign()
|
|
|
|
case *lnwire.ChannelUpdate:
|
|
|
|
data, err = m.DataToSign()
|
|
|
|
case *lnwire.NodeAnnouncement:
|
|
|
|
data, err = m.DataToSign()
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("can't sign %T message", m)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("unable to get data to sign: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return signer.SignMessage(pubKey, data)
|
|
|
|
}
|