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
+38
-6
@@ -3433,11 +3433,12 @@ func (c *KVStore) fetchLightningNode(tx kvdb.RTx,
|
||||
return node, nil
|
||||
}
|
||||
|
||||
// HasNode 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.
|
||||
func (c *KVStore) HasNode(_ context.Context,
|
||||
// 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.
|
||||
func (c *KVStore) HasV1Node(_ context.Context,
|
||||
nodePub [33]byte) (time.Time, bool, error) {
|
||||
|
||||
var (
|
||||
@@ -3457,7 +3458,6 @@ func (c *KVStore) HasNode(_ context.Context,
|
||||
// exit early.
|
||||
nodeBytes := nodes.Get(nodePub[:])
|
||||
if nodeBytes == nil {
|
||||
exists = false
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3485,6 +3485,38 @@ func (c *KVStore) HasNode(_ context.Context,
|
||||
return updateTime, exists, nil
|
||||
}
|
||||
|
||||
// HasNode determines if the graph has a vertex identified by the target node
|
||||
// identity public key.
|
||||
func (c *KVStore) HasNode(_ context.Context, nodePub [33]byte) (bool, error) {
|
||||
var exists bool
|
||||
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.ReadBucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return ErrGraphNotFound
|
||||
}
|
||||
|
||||
// If a key for this serialized public key isn't found, we can
|
||||
// exit early.
|
||||
nodeBytes := nodes.Get(nodePub[:])
|
||||
if nodeBytes == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
exists = true
|
||||
|
||||
return nil
|
||||
}, func() {
|
||||
exists = false
|
||||
})
|
||||
if err != nil {
|
||||
return exists, err
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
// nodeTraversal is used to traverse all channels of a node given by its
|
||||
// public key and passes channel information into the specified callback.
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user