@@ -22,7 +22,7 @@ const DefaultOptions = {
22
22
}
23
23
24
24
class Store {
25
- constructor ( ipfs , id , address , options ) {
25
+ constructor ( ipfs , peerId , address , options ) {
26
26
// Set the options
27
27
let opts = Object . assign ( { } , DefaultOptions )
28
28
Object . assign ( opts , options )
@@ -32,20 +32,20 @@ class Store {
32
32
this . _type = 'store'
33
33
34
34
// Create IDs, names and paths
35
- this . id = id
35
+ this . id = address . toString ( )
36
+ this . uid = peerId
36
37
this . address = address
37
38
this . dbname = address . path || ''
38
39
this . events = new EventEmitter ( )
39
40
40
41
// External dependencies
41
42
this . _ipfs = ipfs
42
43
this . _cache = options . cache
43
- this . _index = new this . options . Index ( this . id )
44
44
45
45
this . _keystore = options . keystore
46
46
this . _key = options && options . key
47
47
? options . key
48
- : this . _keystore . getKey ( id ) || this . _keystore . createKey ( id )
48
+ : this . _keystore . getKey ( peerId ) || this . _keystore . createKey ( peerId )
49
49
// FIX: duck typed interface
50
50
this . _ipfs . keystore = this . _keystore
51
51
@@ -60,6 +60,9 @@ class Store {
60
60
// Create the operations log
61
61
this . _oplog = new Log ( this . _ipfs , this . id , null , null , null , this . _key , this . access . write )
62
62
63
+ // Create the index
64
+ this . _index = new this . options . Index ( this . uid )
65
+
63
66
// Replication progress info
64
67
this . _replicationStatus = new ReplicationInfo ( )
65
68
@@ -98,7 +101,7 @@ class Store {
98
101
const onLoadCompleted = async ( logs , have ) => {
99
102
try {
100
103
for ( let log of logs ) {
101
- await this . _oplog . join ( log , - 1 , this . _oplog . id )
104
+ await this . _oplog . join ( log )
102
105
}
103
106
this . _replicationStatus . queued -= logs . length
104
107
this . _replicationStatus . buffered = this . _replicator . _buffer . length
@@ -179,7 +182,7 @@ class Store {
179
182
await this . close ( )
180
183
await this . _cache . destroy ( )
181
184
// Reset
182
- this . _index = new this . options . Index ( this . id )
185
+ this . _index = new this . options . Index ( this . uid )
183
186
this . _oplog = new Log ( this . _ipfs , this . id , null , null , null , this . _key , this . access . write )
184
187
this . _cache = this . options . cache
185
188
}
@@ -196,8 +199,8 @@ class Store {
196
199
197
200
await mapSeries ( heads , async ( head ) => {
198
201
this . _recalculateReplicationMax ( head . clock . time )
199
- let log = await Log . fromEntryHash ( this . _ipfs , head . hash , this . _oplog . id , amount , this . _oplog . values , this . key , this . access . write , this . _onLoadProgress . bind ( this ) )
200
- await this . _oplog . join ( log , amount , this . _oplog . id )
202
+ let log = await Log . fromEntryHash ( this . _ipfs , head . hash , this . _oplog . id , amount , this . _oplog . values , this . _key , this . access . write , this . _onLoadProgress . bind ( this ) )
203
+ await this . _oplog . join ( log , amount )
201
204
} )
202
205
203
206
// Update the index
@@ -388,7 +391,7 @@ class Store {
388
391
this . _recalculateReplicationMax ( snapshotData . values . reduce ( maxClock , 0 ) )
389
392
if ( snapshotData ) {
390
393
const log = await Log . fromJSON ( this . _ipfs , snapshotData , - 1 , this . _key , this . access . write , 1000 , onProgress )
391
- await this . _oplog . join ( log , - 1 , this . _oplog . id )
394
+ await this . _oplog . join ( log )
392
395
await this . _updateIndex ( )
393
396
this . events . emit ( 'replicated' , this . address . toString ( ) )
394
397
}
0 commit comments