diff --git a/benchmarks/benchmark-append.js b/benchmarks/benchmark-append.js index 475e28de..a13bfe8f 100644 --- a/benchmarks/benchmark-append.js +++ b/benchmarks/benchmark-append.js @@ -18,7 +18,7 @@ let queriesPerSecond = 0 let lastTenSeconds = 0 const queryLoop = async () => { - await log.append(totalQueries.toString()) + await log.append(totalQueries.toString(), 1, false) totalQueries++ lastTenSeconds++ queriesPerSecond++ diff --git a/package-lock.json b/package-lock.json index f7a6227a..97fac9d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1551,9 +1551,9 @@ } }, "acorn": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.3.0.tgz", - "integrity": "sha512-/czfa8BwS88b9gWQVhc8eknunSA2DoJpJyTQkhheIf5E48u1N0R4q/YxxsAeqRrmK9TQ/uYfgLDfZo91UlANIA==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.0.tgz", + "integrity": "sha512-gac8OEcQ2Li1dxIEWGZzsp2BitJxwkwcOm0zHAJLcPJaVvm58FRnk6RkuLRpU1EujipU2ZFODv2P9DLMfnV8mw==", "dev": true }, "acorn-dynamic-import": { @@ -1981,9 +1981,9 @@ "dev": true }, "aws4": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", - "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.0.tgz", + "integrity": "sha512-Uvq6hVe90D0B2WEnUqtdgY1bATGz3mw33nH9Y+dmA+w5DHvUmBgkr5rM/KCHpCsiFNRUfokW/szpPPgMK2hm4A==", "dev": true }, "babel-code-frame": { @@ -13219,11 +13219,26 @@ } }, "orbit-db-io": { - "version": "github:orbitdb/orbit-db-io#da180fdbcff825e830022dd1a2110bbb1ed4736b", - "from": "github:orbitdb/orbit-db-io", + "version": "github:orbitdb/orbit-db-io#cc190eef6a496d5d3a88fccc7bab64fb9a1599a3", + "from": "github:orbitdb/orbit-db-io#feat/pin", "requires": { "cids": "^0.7.1", - "ipld-dag-pb": "^0.17.4" + "ipld-dag-pb": "^0.18.1" + }, + "dependencies": { + "ipld-dag-pb": { + "version": "0.18.1", + "resolved": "https://registry.npmjs.org/ipld-dag-pb/-/ipld-dag-pb-0.18.1.tgz", + "integrity": "sha512-YU2k7kfhV9uliVCAdIyJkYnTLNMdc4FyM2q2dZjfvegdzJFw5Ts8IHnMU77CCLIyD2cc/3xvf9dLIzMIBZpV1A==", + "requires": { + "cids": "~0.7.1", + "class-is": "^1.1.0", + "multicodec": "~0.5.5", + "multihashing-async": "~0.7.0", + "protons": "^1.0.1", + "stable": "~0.1.8" + } + } } }, "orbit-db-keystore": { @@ -15866,9 +15881,9 @@ "dev": true }, "resolve": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.13.0.tgz", - "integrity": "sha512-HHZ3hmOrk5SvybTb18xq4Ek2uLqLO5/goFCYUyvn26nWox4hdlKlfC/+dChIZ6qc4ZeYcN9ekTz0yyHsFgumMw==", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.13.1.tgz", + "integrity": "sha512-CxqObCX8K8YtAhOBRg+lrcdn+LK+WYOS8tSjqSFbjtrI5PnS63QPhZl4+yKfrU9tdsbMu9Anr/amegT87M9Z6w==", "dev": true, "requires": { "path-parse": "^1.0.6" diff --git a/package.json b/package.json index 89a4d027..97d167da 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "json-stringify-deterministic": "^1.0.1", "multihashing-async": "^0.7.0", "orbit-db-identity-provider": "orbitdb/orbit-db-identity-provider#feat/cache", - "orbit-db-io": "orbitdb/orbit-db-io", + "orbit-db-io": "github:orbitdb/orbit-db-io#feat/pin", "p-do-whilst": "^1.1.0", "p-each-series": "^2.1.0", "p-map": "^1.1.1", diff --git a/src/entry.js b/src/entry.js index 74ffc374..4c1f4455 100644 --- a/src/entry.js +++ b/src/entry.js @@ -23,7 +23,7 @@ class Entry { * console.log(entry) * // { hash: null, payload: "hello", next: [] } */ - static async create (ipfs, identity, logId, data, next = [], clock, refs = []) { + static async create (ipfs, identity, logId, data, next = [], clock, refs = [], pin) { if (!isDefined(ipfs)) throw IpfsNotDefinedError() if (!isDefined(identity)) throw new Error('Identity is required, cannot create entry') if (!isDefined(logId)) throw new Error('Entry requires an id') @@ -49,7 +49,7 @@ class Entry { entry.key = identity.publicKey entry.identity = identity.toJSON() entry.sig = signature - entry.hash = await Entry.toMultihash(ipfs, entry) + entry.hash = await Entry.toMultihash(ipfs, entry, pin) return entry } @@ -93,13 +93,13 @@ class Entry { * // "Qm...Foo" * @deprecated */ - static async toMultihash (ipfs, entry) { + static async toMultihash (ipfs, entry, pin = false) { if (!ipfs) throw IpfsNotDefinedError() if (!Entry.isEntry(entry)) throw new Error('Invalid object format, cannot generate entry hash') // // Ensure `entry` follows the correct format const e = Entry.toEntry(entry) - return io.write(ipfs, getWriteFormat(e.v), e, { links: IPLD_LINKS }) + return io.write(ipfs, getWriteFormat(e.v), e, { links: IPLD_LINKS, pin }) } static toEntry (entry, { presigned = false, includeHash = false } = {}) { diff --git a/src/log.js b/src/log.js index 54d13c5a..639538a6 100644 --- a/src/log.js +++ b/src/log.js @@ -256,7 +256,7 @@ class Log extends GSet { * @param {Entry} entry Entry to add * @return {Log} New Log containing the appended value */ - async append (data, pointerCount = 1) { + async append (data, pointerCount = 1, pin = false) { // Update the clock (find the latest clock) const newTime = Math.max(this.clock.time, this.heads.reduce(maxClockTimeReducer, 0)) + 1 this._clock = new Clock(this.clock.id, newTime) @@ -297,7 +297,8 @@ class Log extends GSet { data, nexts, this.clock, - refs + refs, + pin ) const canAppend = await this._access.canAppend(entry, this._identity.provider)