Skip to content

Commit b79fb2a

Browse files
committed
graph/db: add FundingPKScript method on ChannelEdgeInfo
1 parent 1511123 commit b79fb2a

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

graph/db/graph_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,14 +2006,9 @@ func TestGraphPruning(t *testing.T) {
20062006
t.Fatalf("unable to add node: %v", err)
20072007
}
20082008

2009-
btcKey1 := edgeInfo.BitcoinKey1Bytes.UnwrapOr(route.Vertex{})
2010-
btcKey2 := edgeInfo.BitcoinKey2Bytes.UnwrapOr(route.Vertex{})
2011-
pkScript, err := genMultiSigP2WSH(
2012-
btcKey1[:], btcKey2[:],
2013-
)
2014-
if err != nil {
2015-
t.Fatalf("unable to gen multi-sig p2wsh: %v", err)
2016-
}
2009+
pkScript, err := edgeInfo.FundingPKScript()
2010+
require.NoError(t, err)
2011+
20172012
edgePoints = append(edgePoints, EdgePoint{
20182013
FundingPkScript: pkScript,
20192014
OutPoint: op,

graph/db/kv_store.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,15 +4113,7 @@ func (c *KVStore) ChannelView() ([]EdgePoint, error) {
41134113
return err
41144114
}
41154115

4116-
btcKey1 := edgeInfo.BitcoinKey1Bytes.UnwrapOr(
4117-
route.Vertex{},
4118-
)
4119-
btcKey2 := edgeInfo.BitcoinKey2Bytes.UnwrapOr(
4120-
route.Vertex{},
4121-
)
4122-
pkScript, err := genMultiSigP2WSH(
4123-
btcKey1[:], btcKey2[:],
4124-
)
4116+
pkScript, err := edgeInfo.FundingPKScript()
41254117
if err != nil {
41264118
return err
41274119
}

graph/db/models/channel_edge_info.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/btcsuite/btcd/chaincfg/chainhash"
1010
"github.com/btcsuite/btcd/wire"
1111
"github.com/lightningnetwork/lnd/fn/v2"
12+
"github.com/lightningnetwork/lnd/input"
1213
"github.com/lightningnetwork/lnd/lnwire"
1314
"github.com/lightningnetwork/lnd/routing/route"
1415
)
@@ -221,6 +222,38 @@ func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
221222
}
222223
}
223224

225+
// FundingPKScript returns the funding output's pkScript for the channel.
226+
func (c *ChannelEdgeInfo) FundingPKScript() ([]byte, error) {
227+
switch c.Version {
228+
case lnwire.GossipVersion1:
229+
btc1Key, err := c.BitcoinKey1Bytes.UnwrapOrErr(
230+
fmt.Errorf("missing bitcoin key 1"),
231+
)
232+
if err != nil {
233+
return nil, err
234+
}
235+
btc2Key, err := c.BitcoinKey2Bytes.UnwrapOrErr(
236+
fmt.Errorf("missing bitcoin key 2"),
237+
)
238+
if err != nil {
239+
return nil, err
240+
}
241+
242+
witnessScript, err := input.GenMultiSigScript(
243+
btc1Key[:], btc2Key[:],
244+
)
245+
if err != nil {
246+
return nil, err
247+
}
248+
249+
return input.WitnessScriptHash(witnessScript)
250+
251+
default:
252+
return nil, fmt.Errorf("unsupported channel version: %d",
253+
c.Version)
254+
}
255+
}
256+
224257
// ToChannelAnnouncement converts the ChannelEdgeInfo to a
225258
// lnwire.ChannelAnnouncement1 message. Returns an error if AuthProof is nil
226259
// or if the version is not v1.

graph/db/sql_store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,6 +2761,7 @@ func (s *SQLStore) ChannelView() ([]EdgePoint, error) {
27612761
handleChannel := func(_ context.Context,
27622762
channel sqlc.ListChannelsPaginatedRow) error {
27632763

2764+
// TODO(elle): update to handle V2 channels.
27642765
pkScript, err := genMultiSigP2WSH(
27652766
channel.BitcoinKey1, channel.BitcoinKey2,
27662767
)

0 commit comments

Comments
 (0)