multi: add models.Node V1 constructor
Add a version field to models.Node and a V1 constructor for it.
This commit is contained in:
1 parent
8f205e2d1c
commit
80e70096cb
18 files changed
+443
-340
No files matched your search
+15
-16
@@ -226,18 +226,7 @@ func (s *Server) ImportGraph(ctx context.Context,
|
||||
|
||||
var err error
|
||||
for _, rpcNode := range graph.Nodes {
|
||||
node := &models.Node{
|
||||
LastUpdate: time.Unix(
|
||||
int64(rpcNode.LastUpdate), 0,
|
||||
),
|
||||
Alias: rpcNode.Alias,
|
||||
// NOTE: this is a workaround to ensure that
|
||||
// HaveAnnouncement() returns true so that the other
|
||||
// fields are properly persisted. However,
|
||||
AuthSigBytes: []byte{0},
|
||||
}
|
||||
|
||||
node.PubKeyBytes, err = parsePubKey(rpcNode.PubKey)
|
||||
pubKeyBytes, err := parsePubKey(rpcNode.PubKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -254,15 +243,25 @@ func (s *Server) ImportGraph(ctx context.Context,
|
||||
}
|
||||
|
||||
featureVector := lnwire.NewRawFeatureVector(featureBits...)
|
||||
node.Features = lnwire.NewFeatureVector(
|
||||
featureVector, featureNames,
|
||||
)
|
||||
|
||||
node.Color, err = lncfg.ParseHexColor(rpcNode.Color)
|
||||
nodeColor, err := lncfg.ParseHexColor(rpcNode.Color)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node := models.NewV1Node(pubKeyBytes, &models.NodeV1Fields{
|
||||
LastUpdate: time.Unix(
|
||||
int64(rpcNode.LastUpdate), 0,
|
||||
),
|
||||
Alias: rpcNode.Alias,
|
||||
Features: featureVector,
|
||||
Color: nodeColor,
|
||||
// NOTE: this is a workaround to ensure that
|
||||
// HaveAnnouncement() returns true so that the other
|
||||
// fields are properly persisted. However,
|
||||
AuthSigBytes: []byte{0},
|
||||
})
|
||||
|
||||
if err := graphDB.AddNode(ctx, node); err != nil {
|
||||
return nil, fmt.Errorf("unable to add node %v: %w",
|
||||
rpcNode.PubKey, err)
|
||||
|
||||
Reference in new issue
Block a user