项目作者: orbitdb

项目描述 :
A bridge between OrbitDB and Powergate, which is itself a bridge between Filecoin and IPFS.
高级语言: JavaScript
项目地址: git://github.com/orbitdb/orbit-db-powergate-io.git
创建时间: 2020-08-25T19:59:42Z
项目社区:https://github.com/orbitdb/orbit-db-powergate-io

开源协议:MIT License

下载


PowergateIO (orbit-db-powergate-io)

A bridge between OrbitDB and Powergate, which is itself a bridge between Filecoin and IPFS.

Install

npm install orbit-db-powergate-io

From Source

  1. $ git clone https://github.com/orbitdb/orbit-db-powergate-io
  2. $ cd orbit-db-powergate-io
  3. $ npm install

Usage

PowergateIO is designed to work with only one configuration option: the gRPC
endpoint of the Powergate node you want to connect to. Everything else should be handled
“under the hood” for you. See below.

Initial Setup

  1. const PowergateIO = require('orbit-db-powergate-io')
  2. const host = 'http://0.0.0.0:6002' // This is the default value
  3. PowergateIO.create(host)
  4. .then((powergateio) => {
  5. console.log(powergateio.wallet) // Will be {} until funded
  6. })

Backing up an OrbitDB Snapshot

PowergateIO is meant to be used from one IPFS node to another, and to replicate
OrbitDB databases between them. So, let’s assume that we have an IPFS node and
OrbitDB running locally, and we’re going to interact with a remote Powergate
instance.

  1. const IPFS = require('ipfs')
  2. const OrbitDB = require('orbit-db')
  3. const PowergateIO = require('orbit-db-powergate-io')
  4. ;(async () => {
  5. const ipfs = await IPFS.create()
  6. const orbitdb = await OrbitDB.createInstance(ipfs)
  7. powergateio = await PowergateIO.create('https://my.hosted.powergate.node')
  8. const addresses = (await powergateio.ipfs.id()).addresses
  9. await ipfs.swarm.connect(addresses[0].toString())
  10. const db = await orbitdb.eventlog('powergate-test')
  11. for (let i = 0; i < 10; i++) {
  12. await db.add(`entry${i}`)
  13. }
  14. jobStatus = await powergateio.storeSnapshot(db.address.toString())
  15. console.log(jobStatus)
  16. // Wait until wallet is funded
  17. // Can take up to 2 minute on testnet
  18. console.log(powergateio.wallet)
  19. await powergateio.stop()
  20. await orbitdb.disconnect()
  21. await ipfs.stop()
  22. })()

Retrieving an OrbitDB Snapshot

Once you’ve stored a snapshot and have made note of the DB address returned,
you can use that db address to retrieve the snapshot!

  1. const IPFS = require('ipfs')
  2. const OrbitDB = require('orbit-db')
  3. const PowergateIO = require('orbit-db-powergate-io')
  4. ;(async () => {
  5. const ipfs = await IPFS.create()
  6. const orbitdb = await OrbitDB.createInstance(ipfs)
  7. const powergateio = await PowergateIO.create('https://my.hosted.powergate.node')
  8. const addresses = (await powergateio.ipfs.id()).addresses
  9. await ipfs.swarm.connect(addresses[0].toString())
  10. const dbAddr = '/orbitdb/zdpuAxkdoDum8Nk2VCxKkHZk8TzqAYPm86mVgoy7wagu2UcZB/powergate-test'
  11. const db2 = await orbitdb.open(dbAddr, { create: true })
  12. const snapshot = await powergateio.retrieveSnapshot(dbAddr)
  13. await db2._oplog.join(snapshots[0].log)
  14. await db2._updateIndex()
  15. })()

For more information, see the API docs. Also,
the tests are heavily commented to detail
what is happening at each step.

Contributing

Issues and pull requests accepted. Please note that several issues have “Help Wanted
and “Good First Issue“ tags!

Developing Locally

It’s highly recommended to install both Docker and Docker compose. From there, make is your
best friends. It gives you the following commands:

  • make up - Spins up all the necessary docker images for local development
  • make lint - Lints your JS code vi standard.js
  • make docs - Compiles the README and JS docstrings into the docs/ folder
  • make down - Spins down all the docker images
  • make clean - Removes ephemeral files and folders like node_modules and package-lock.json
  • make test - Does a whole bunch of the above, in order. use it!
  • make rebuild - runs make clean and make deps to give you a clean slate.

License

MIT (or Apache2.0 at your discretion)

© OrbitDB Community