• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

orbitdb/orbit-db-powergate-io: A bridge between OrbitDB and Powergate, which is ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

orbitdb/orbit-db-powergate-io

开源软件地址:

https://github.com/orbitdb/orbit-db-powergate-io

开源编程语言:

JavaScript 98.4%

开源软件介绍:

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

$ git clone https://github.com/orbitdb/orbit-db-powergate-io
$ cd orbit-db-powergate-io
$ 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

const PowergateIO = require('orbit-db-powergate-io')

const host = 'http://0.0.0.0:6002' // This is the default value
PowergateIO.create(host)
  .then((powergateio) => {
    console.log(powergateio.wallet) // Will be {} until funded
  })

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.

const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
const PowergateIO = require('orbit-db-powergate-io')

;(async () => {
  const ipfs = await IPFS.create()
  const orbitdb = await OrbitDB.createInstance(ipfs)
  powergateio = await PowergateIO.create('https://my.hosted.powergate.node')

  const addresses = (await powergateio.ipfs.id()).addresses
  await ipfs.swarm.connect(addresses[0].toString())

  const db = await orbitdb.eventlog('powergate-test')
  for (let i = 0; i < 10; i++) {
    await db.add(`entry${i}`)
  }

  jobStatus = await powergateio.storeSnapshot(db.address.toString())
  console.log(jobStatus)

  // Wait until wallet is funded
  // Can take up to 2 minute on testnet
  console.log(powergateio.wallet)

  await powergateio.stop()
  await orbitdb.disconnect()
  await ipfs.stop()
})()

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!

const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
const PowergateIO = require('orbit-db-powergate-io')

;(async () => {
  const ipfs = await IPFS.create()
  const orbitdb = await OrbitDB.createInstance(ipfs)
  const powergateio = await PowergateIO.create('https://my.hosted.powergate.node')

  const addresses = (await powergateio.ipfs.id()).addresses
  await ipfs.swarm.connect(addresses[0].toString())

  const dbAddr = '/orbitdb/zdpuAxkdoDum8Nk2VCxKkHZk8TzqAYPm86mVgoy7wagu2UcZB/powergate-test'
  const db2 = await orbitdb.open(dbAddr, { create: true })
  const snapshot = await powergateio.retrieveSnapshot(dbAddr)

  await db2._oplog.join(snapshots[0].log)
  await db2._updateIndex()
})()

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap