graph/db: split HasNode into two methods
HasNode currently is very v1 specific since it returns a time.Time timestamp which is specific to V1 node announcements. However, it is mostly only used for the "exists" return value. So here we split it up into HasNode which just checks existence and HasV1Node which retains the same behavaiour as before.
This commit is contained in:
8 files changed
+100
-25
No files matched your search
+29
-2
@@ -53,6 +53,7 @@ type SQLQueries interface {
|
||||
DeleteUnconnectedNodes(ctx context.Context) ([][]byte, error)
|
||||
DeleteNodeByPubKey(ctx context.Context, arg sqlc.DeleteNodeByPubKeyParams) (sql.Result, error)
|
||||
DeleteNode(ctx context.Context, id int64) error
|
||||
NodeExists(ctx context.Context, arg sqlc.NodeExistsParams) (bool, error)
|
||||
|
||||
GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]sqlc.GraphNodeExtraType, error)
|
||||
GetNodeExtraTypesBatch(ctx context.Context, ids []int64) ([]sqlc.GraphNodeExtraType, error)
|
||||
@@ -283,14 +284,14 @@ func (s *SQLStore) FetchNode(ctx context.Context,
|
||||
return node, nil
|
||||
}
|
||||
|
||||
// HasNode determines if the graph has a vertex identified by the
|
||||
// HasV1Node determines if the graph has a vertex identified by the
|
||||
// target node identity public key. If the node exists in the database, a
|
||||
// timestamp of when the data for the node was lasted updated is returned along
|
||||
// with a true boolean. Otherwise, an empty time.Time is returned with a false
|
||||
// boolean.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) HasNode(ctx context.Context,
|
||||
func (s *SQLStore) HasV1Node(ctx context.Context,
|
||||
pubKey [33]byte) (time.Time, bool, error) {
|
||||
|
||||
var (
|
||||
@@ -326,6 +327,32 @@ func (s *SQLStore) HasNode(ctx context.Context,
|
||||
return lastUpdate, exists, nil
|
||||
}
|
||||
|
||||
// HasNode determines if the graph has a vertex identified by the
|
||||
// target node identity public key.
|
||||
//
|
||||
// NOTE: part of the Store interface.
|
||||
func (s *SQLStore) HasNode(ctx context.Context, pubKey [33]byte) (bool, error) {
|
||||
var (
|
||||
v = lnwire.GossipVersion1
|
||||
exists bool
|
||||
)
|
||||
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
var err error
|
||||
exists, err = db.NodeExists(ctx, sqlc.NodeExistsParams{
|
||||
Version: int16(v),
|
||||
PubKey: pubKey[:],
|
||||
})
|
||||
|
||||
return err
|
||||
}, sqldb.NoOpReset)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("unable to check if node (%x) "+
|
||||
"exists: %w", pubKey, err)
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// AddrsForNode returns all known addresses for the target node public key
|
||||
// that the graph DB is aware of. The returned boolean indicates if the
|
||||
// given node is unknown to the graph DB or not.
|
||||
|
||||
Reference in new issue
Block a user