Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 90d42b4

Browse files
authored
Merge pull request #22 from orbitdb/feat/latest-ipfs-log
Use IDs as per latest ipfs-log
2 parents 73f9473 + 691b058 commit 90d42b4

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

package-lock.json

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author": "Haad",
1717
"license": "MIT",
1818
"dependencies": {
19-
"ipfs-log": "~4.0.6",
19+
"ipfs-log": "orbitdb/ipfs-log",
2020
"logplease": "^1.2.14",
2121
"p-each-series": "^1.0.0",
2222
"readable-stream": "~2.3.3"

src/Store.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const DefaultOptions = {
2222
}
2323

2424
class Store {
25-
constructor (ipfs, id, address, options) {
25+
constructor (ipfs, peerId, address, options) {
2626
// Set the options
2727
let opts = Object.assign({}, DefaultOptions)
2828
Object.assign(opts, options)
@@ -32,20 +32,20 @@ class Store {
3232
this._type = 'store'
3333

3434
// Create IDs, names and paths
35-
this.id = id
35+
this.id = address.toString()
36+
this.uid = peerId
3637
this.address = address
3738
this.dbname = address.path || ''
3839
this.events = new EventEmitter()
3940

4041
// External dependencies
4142
this._ipfs = ipfs
4243
this._cache = options.cache
43-
this._index = new this.options.Index(this.id)
4444

4545
this._keystore = options.keystore
4646
this._key = options && options.key
4747
? options.key
48-
: this._keystore.getKey(id) || this._keystore.createKey(id)
48+
: this._keystore.getKey(peerId) || this._keystore.createKey(peerId)
4949
// FIX: duck typed interface
5050
this._ipfs.keystore = this._keystore
5151

@@ -60,6 +60,9 @@ class Store {
6060
// Create the operations log
6161
this._oplog = new Log(this._ipfs, this.id, null, null, null, this._key, this.access.write)
6262

63+
// Create the index
64+
this._index = new this.options.Index(this.uid)
65+
6366
// Replication progress info
6467
this._replicationStatus = new ReplicationInfo()
6568

@@ -98,7 +101,7 @@ class Store {
98101
const onLoadCompleted = async (logs, have) => {
99102
try {
100103
for (let log of logs) {
101-
await this._oplog.join(log, -1, this._oplog.id)
104+
await this._oplog.join(log)
102105
}
103106
this._replicationStatus.queued -= logs.length
104107
this._replicationStatus.buffered = this._replicator._buffer.length
@@ -179,7 +182,7 @@ class Store {
179182
await this.close()
180183
await this._cache.destroy()
181184
// Reset
182-
this._index = new this.options.Index(this.id)
185+
this._index = new this.options.Index(this.uid)
183186
this._oplog = new Log(this._ipfs, this.id, null, null, null, this._key, this.access.write)
184187
this._cache = this.options.cache
185188
}
@@ -196,8 +199,8 @@ class Store {
196199

197200
await mapSeries(heads, async (head) => {
198201
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)
201204
})
202205

203206
// Update the index
@@ -388,7 +391,7 @@ class Store {
388391
this._recalculateReplicationMax(snapshotData.values.reduce(maxClock, 0))
389392
if (snapshotData) {
390393
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)
392395
await this._updateIndex()
393396
this.events.emit('replicated', this.address.toString())
394397
}

0 commit comments

Comments
 (0)