Giter Club home page Giter Club logo

demux-js-bitshares's Introduction

demux-js-bitshares

Demux BitShares is a Demux plugin for sourcing Bitshares blockchain events to deterministically update queryable datastores and trigger side effects.

Overview

The default implementation BitsharesActionReader uses BitShares get_block API to retrieve blocks one by one from the a BitShares core API node. Using this approach virtual operations like fill_order are not available, and synchronization time is very long.

To avoid those issues, an alternative implementation BitsharesElasticSearchActionReader uses ElasticSearch as backend, this requires a node with ElasticSearch Bitshares plugin activated, and demux-bitshares 1.1+.

Installation

# Using yarn
yarn add demux-bitshares

# Using npm
npm install demux-bitshares --save

Example

// Let's read from a BitShares core node
const { BitsharesActionReader } = require("demux-bitshares")

// Assuming you've created your own subclass of AbstractActionHandler
const MyActionHandler = require("./MyActionHandler")

// Ties everything together in a polling loop
const  { BaseActionWatcher } = require("demux")

// Import Updaters and Effects, which are arrays of objects:
// [ { actionType: string, (updater|effect): function }, ... ] 
const updaters = require("./updaters")
const effects = require("./effects")

const actionReader = new BitsharesActionReader(
  "http://some-bitshares-endpoint:9080", // Locally hosted node needed for reasonable indexing speed
  12345678, // First block to retrieve relevant to this application.
)

const actionHandler = new MyActionHandler(
  updaters,
  effects,
)

const actionWatcher = new BaseActionWatcher(
  actionReader,
  actionHandler,
  1500, // Poll at twice the block interval for less latency
)

actionWatcher.watch() // Start watch loop

For more complete examples, see the examples directory.

Virtual operations

By default in Bitshares block, implicit operations like fill_order are not included. Those are called 'virtual operations'. To retrieve virtual operations you can use an ElasticSearch backend instead of an Bitshares API node. Use BitsharesElasticSearchActionReader to do so:

const actionReader = new BitsharesElasticSearchActionReader(
  {
    host: "https://some-es-bitshares-cluster/", // ES cluster to connect to.
    httpAuth: "user:password" // Credentials to ES.
  },
  28999264, // First block to retrieve relevant to this application.
)

You can get the full configuration options to connect to the ElasticSearch cluster here.

Possible improvements:

  • Batch block retrieval in ElasticSearch implementation.

demux-js-bitshares's People

Contributors

zapata avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.