How to use the ipfs-log.fromIpfsHash function in ipfs-log

To help you get started, we’ve selected a few ipfs-log examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github orbitdb / orbit-db / src / OrbitDB.js View on Github external
return new Promise((resolve, reject) => {
      if(hash && hash !== this.lastWrite && this._logs[channel]) {
        this.events[channel].emit('load', 'sync', channel);
        const oldCount = this._logs[channel].items.length;
        Log.fromIpfsHash(this._ipfs, hash).then((other) => {
          this._logs[channel].join(other).then((merged) => {
            // Only emit the event if something was added
            const joinedCount = this._logs[channel].items.length - oldCount;
            if(joinedCount > 0) {
              Cache.set(channel, hash);
              // Cache the payloads
              this._cacheOperations(this._logs[channel])
                .then(() => {
                  this.events[channel].emit('sync', channel, hash);
                  this.events[channel].emit('loaded', 'sync', channel);
                  resolve();
                })
                .catch(reject);
            } else {
              this.events[channel].emit('loaded', 'sync', channel);
              resolve();
github orbitdb / orbit-db / src / stores / Store.js View on Github external
sync(hash) {
    if(!hash || hash === this._lastWrite)
      return Promise.resolve([]);

    const oldCount = this._oplog.items.length;
    let newItems = [];
    this.events.emit('load', this.dbname);
    return Log.fromIpfsHash(this._ipfs, hash)
      .then((log) => this._oplog.join(log))
      .then((merged) => newItems = merged)
      .then(() => Log.getIpfsHash(this._ipfs, this._oplog))
      .then((hash) => Cache.set(this.dbname, hash))
      .then(() => this._index.updateIndex(this._oplog, newItems))
      .then(() => {
        if(newItems.length > 0)
          this.events.emit('readable', this.dbname);
      })
      .then(() => newItems)
  }
github orbitdb / orbit-db / src / stores / Store.js View on Github external
return Cache.loadCache(this.options.cacheFile).then(() => {
      const cached = Cache.get(this.dbname);
      if(cached) {
        return Log.fromIpfsHash(this._ipfs, cached)
          .then((log) => this._oplog.join(log))
          .then((merged) => this._index.updateIndex(this._oplog, merged))
          .then(() => this.events.emit('readable', this.dbname))
          .then(() => this.events);
      }

      return Promise.resolve(this.events);
    });
  }

ipfs-log

Append-only log CRDT on IPFS

MIT
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis