@@ -25,6 +25,7 @@ import (
25
25
"time"
26
26
27
27
"github.com/ethersphere/bee/pkg/logging"
28
+ "github.com/ethersphere/bee/pkg/pinning"
28
29
"github.com/ethersphere/bee/pkg/postage"
29
30
"github.com/ethersphere/bee/pkg/postage/batchstore"
30
31
"github.com/ethersphere/bee/pkg/shed"
@@ -62,6 +63,9 @@ type DB struct {
62
63
shed * shed.DB
63
64
tags * tags.Tags
64
65
66
+ // stateStore is needed to access the pinning Service.Pins() method.
67
+ stateStore storage.StateStorer
68
+
65
69
// schema name of loaded data
66
70
schemaName shed.StringField
67
71
@@ -176,7 +180,7 @@ type Options struct {
176
180
// New returns a new DB. All fields and indexes are initialized
177
181
// and possible conflicts with schema from existing database is checked.
178
182
// One goroutine for writing batches is created.
179
- func New (path string , baseKey []byte , o * Options , logger logging.Logger ) (db * DB , err error ) {
183
+ func New (path string , baseKey []byte , ss storage. StateStorer , o * Options , logger logging.Logger ) (db * DB , err error ) {
180
184
if o == nil {
181
185
// default options
182
186
o = & Options {
@@ -185,6 +189,7 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
185
189
}
186
190
187
191
db = & DB {
192
+ stateStore : ss ,
188
193
cacheCapacity : o .Capacity ,
189
194
baseKey : baseKey ,
190
195
tags : o .Tags ,
@@ -241,7 +246,7 @@ func New(path string, baseKey []byte, o *Options, logger logging.Logger) (db *DB
241
246
}
242
247
if schemaName == "" {
243
248
// initial new localstore run
244
- err := db .schemaName .Put (DbSchemaCurrent )
249
+ err := db .schemaName .Put (DBSchemaCurrent )
245
250
if err != nil {
246
251
return nil , err
247
252
}
@@ -585,6 +590,16 @@ func (db *DB) DebugIndices() (indexInfo map[string]int, err error) {
585
590
return indexInfo , err
586
591
}
587
592
593
+ // stateStoreHasPins returns true if the state-store
594
+ // contains any pins, otherwise false is returned.
595
+ func (db * DB ) stateStoreHasPins () (bool , error ) {
596
+ pins , err := pinning .NewService (nil , db .stateStore , nil ).Pins ()
597
+ if err != nil {
598
+ return false , err
599
+ }
600
+ return len (pins ) > 0 , nil
601
+ }
602
+
588
603
// chunkToItem creates new Item with data provided by the Chunk.
589
604
func chunkToItem (ch swarm.Chunk ) shed.Item {
590
605
return shed.Item {
0 commit comments