From d1ace4f344616fb6fa8643872c1f9cac89f8549e Mon Sep 17 00:00:00 2001 From: holisticode Date: Thu, 7 Feb 2019 09:49:19 -0500 Subject: swarm: Debug API and HasChunks() API endpoint (#18980) (cherry picked from commit 41597c2856d6ac7328baca1340c3e36ab0edd382) --- swarm/storage/ldbstore.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'swarm/storage/ldbstore.go') diff --git a/swarm/storage/ldbstore.go b/swarm/storage/ldbstore.go index 635d33429..a2f24eff0 100644 --- a/swarm/storage/ldbstore.go +++ b/swarm/storage/ldbstore.go @@ -969,6 +969,18 @@ func (s *LDBStore) Get(_ context.Context, addr Address) (chunk Chunk, err error) return s.get(addr) } +// Has queries the underlying DB if a chunk with the given address is stored +// Returns true if the chunk is found, false if not +func (s *LDBStore) Has(_ context.Context, addr Address) bool { + s.lock.RLock() + defer s.lock.RUnlock() + + ikey := getIndexKey(addr) + _, err := s.db.Get(ikey) + + return err == nil +} + // TODO: To conform with other private methods of this object indices should not be updated func (s *LDBStore) get(addr Address) (chunk *chunk, err error) { if s.closed { -- cgit