autopilot/graph: define addRandNode
This commit is contained in:
parent
5224c94aaf
commit
aeeff4714d
@ -270,6 +270,30 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
||||||
|
nodeKey, err := randKey()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dbNode := &channeldb.LightningNode{
|
||||||
|
HaveNodeAnnouncement: true,
|
||||||
|
Addresses: []net.Addr{
|
||||||
|
&net.TCPAddr{
|
||||||
|
IP: bytes.Repeat([]byte("a"), 16),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Features: lnwire.NewFeatureVector(nil, lnwire.GlobalFeatures),
|
||||||
|
AuthSigBytes: testSig.Serialize(),
|
||||||
|
}
|
||||||
|
dbNode.AddPubKey(nodeKey)
|
||||||
|
if err := d.db.AddLightningNode(dbNode); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodeKey, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// memChannelGraph is an implementation of the autopilot.ChannelGraph backed by
|
// memChannelGraph is an implementation of the autopilot.ChannelGraph backed by
|
||||||
// an in-memory graph.
|
// an in-memory graph.
|
||||||
type memChannelGraph struct {
|
type memChannelGraph struct {
|
||||||
@ -407,6 +431,24 @@ func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
return &edge1, &edge2, nil
|
return &edge1, &edge2, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *memChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
||||||
|
newPub, err := randKey()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
vertex := memNode{
|
||||||
|
pub: newPub,
|
||||||
|
addrs: []net.Addr{
|
||||||
|
&net.TCPAddr{
|
||||||
|
IP: bytes.Repeat([]byte("a"), 16),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
m.graph[NewNodeID(newPub)] = vertex
|
||||||
|
|
||||||
|
return newPub, nil
|
||||||
|
}
|
||||||
|
|
||||||
// memNode is a purely in-memory implementation of the autopilot.Node
|
// memNode is a purely in-memory implementation of the autopilot.Node
|
||||||
// interface.
|
// interface.
|
||||||
type memNode struct {
|
type memNode struct {
|
||||||
|
@ -182,6 +182,8 @@ type testGraph interface {
|
|||||||
|
|
||||||
addRandChannel(*btcec.PublicKey, *btcec.PublicKey,
|
addRandChannel(*btcec.PublicKey, *btcec.PublicKey,
|
||||||
btcutil.Amount) (*ChannelEdge, *ChannelEdge, error)
|
btcutil.Amount) (*ChannelEdge, *ChannelEdge, error)
|
||||||
|
|
||||||
|
addRandNode() (*btcec.PublicKey, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDiskChanGraph() (testGraph, func(), error) {
|
func newDiskChanGraph() (testGraph, func(), error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user