mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 07:00:55 +02:00
graph/db: refactor buildNode to not take a pointer
Since the type returned from the DB is not a pointer. This will be useful later on.
This commit is contained in:
@@ -192,7 +192,7 @@ func migrateNodes(ctx context.Context, kvBackend kvdb.Backend,
|
|||||||
pub, id, dbNode.ID)
|
pub, id, dbNode.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
migratedNode, err := buildNode(ctx, sqlDB, &dbNode)
|
migratedNode, err := buildNode(ctx, sqlDB, dbNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not build migrated node "+
|
return fmt.Errorf("could not build migrated node "+
|
||||||
"from dbNode(db id: %d, node pub: %x): %w",
|
"from dbNode(db id: %d, node pub: %x): %w",
|
||||||
|
@@ -3231,7 +3231,7 @@ func getNodeByPubKey(ctx context.Context, db SQLQueries,
|
|||||||
return 0, nil, fmt.Errorf("unable to fetch node: %w", err)
|
return 0, nil, fmt.Errorf("unable to fetch node: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err := buildNode(ctx, db, &dbNode)
|
node, err := buildNode(ctx, db, dbNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, fmt.Errorf("unable to build node: %w", err)
|
return 0, nil, fmt.Errorf("unable to build node: %w", err)
|
||||||
}
|
}
|
||||||
@@ -3256,7 +3256,7 @@ func buildCacheableChannelInfo(scid []byte, capacity int64, node1Pub,
|
|||||||
// record. The node's features, addresses and extra signed fields are also
|
// record. The node's features, addresses and extra signed fields are also
|
||||||
// fetched from the database and set on the node.
|
// fetched from the database and set on the node.
|
||||||
func buildNode(ctx context.Context, db SQLQueries,
|
func buildNode(ctx context.Context, db SQLQueries,
|
||||||
dbNode *sqlc.GraphNode) (*models.LightningNode, error) {
|
dbNode sqlc.GraphNode) (*models.LightningNode, error) {
|
||||||
|
|
||||||
// NOTE: buildNode is only used to load the data for a single node, and
|
// NOTE: buildNode is only used to load the data for a single node, and
|
||||||
// so no paged queries will be performed. This means that it's ok to
|
// so no paged queries will be performed. This means that it's ok to
|
||||||
@@ -3276,7 +3276,7 @@ func buildNode(ctx context.Context, db SQLQueries,
|
|||||||
// from the provided sqlc.GraphNode and batchNodeData. If the node does have
|
// from the provided sqlc.GraphNode and batchNodeData. If the node does have
|
||||||
// features/addresses/extra fields, then the corresponding fields are expected
|
// features/addresses/extra fields, then the corresponding fields are expected
|
||||||
// to be present in the batchNodeData.
|
// to be present in the batchNodeData.
|
||||||
func buildNodeWithBatchData(dbNode *sqlc.GraphNode,
|
func buildNodeWithBatchData(dbNode sqlc.GraphNode,
|
||||||
batchData *batchNodeData) (*models.LightningNode, error) {
|
batchData *batchNodeData) (*models.LightningNode, error) {
|
||||||
|
|
||||||
if dbNode.Version != int16(ProtocolV1) {
|
if dbNode.Version != int16(ProtocolV1) {
|
||||||
@@ -3364,7 +3364,7 @@ func forEachNodeInBatch(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, dbNode := range nodes {
|
for _, dbNode := range nodes {
|
||||||
node, err := buildNodeWithBatchData(&dbNode, batchData)
|
node, err := buildNodeWithBatchData(dbNode, batchData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to build node(id=%d): %w",
|
return fmt.Errorf("unable to build node(id=%d): %w",
|
||||||
dbNode.ID, err)
|
dbNode.ID, err)
|
||||||
@@ -4235,12 +4235,12 @@ func buildNodes(ctx context.Context, db SQLQueries, dbNode1,
|
|||||||
dbNode2 sqlc.GraphNode) (*models.LightningNode, *models.LightningNode,
|
dbNode2 sqlc.GraphNode) (*models.LightningNode, *models.LightningNode,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
node1, err := buildNode(ctx, db, &dbNode1)
|
node1, err := buildNode(ctx, db, dbNode1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
node2, err := buildNode(ctx, db, &dbNode2)
|
node2, err := buildNode(ctx, db, dbNode2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -5090,7 +5090,7 @@ func forEachNodePaginated(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
processItem := func(ctx context.Context, dbNode sqlc.GraphNode,
|
processItem := func(ctx context.Context, dbNode sqlc.GraphNode,
|
||||||
batchData *batchNodeData) error {
|
batchData *batchNodeData) error {
|
||||||
|
|
||||||
node, err := buildNodeWithBatchData(&dbNode, batchData)
|
node, err := buildNodeWithBatchData(dbNode, batchData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to build "+
|
return fmt.Errorf("unable to build "+
|
||||||
"node(id=%d): %w", dbNode.ID, err)
|
"node(id=%d): %w", dbNode.ID, err)
|
||||||
|
Reference in New Issue
Block a user