Skip to content

Commit

Permalink
Revert "Revert "Release demux-eos 4.0.0""
Browse files Browse the repository at this point in the history
This reverts commit 3244e22.
  • Loading branch information
Julien Heller committed Feb 25, 2019
1 parent 0f290e0 commit ab2b521
Show file tree
Hide file tree
Showing 43 changed files with 2,119 additions and 1,168 deletions.
49 changes: 0 additions & 49 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ yarn-error.log*

# Editor files
.idea/
.vscode/

dist/
23 changes: 15 additions & 8 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
src
tsconfig.json
tslint.json
dist/**/*.test.*
dist/testHelpers/
docs/
scripts/
src/
.eslintrc.json
.gitignore
.idea
yarn-error.log
.npmignore
.npmrc.template
.nvmrc
.travis.yml
.eslintrc.json
__mocks__
CONTRIBUTING.md
README.md
build-docs.sh
.npmrc.template
scripts/*
tsconfig.json
tslint.json
yarn.lock
yarn-error.log
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.9.4
10.15.1
81 changes: 72 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# demux-js-eos [![Build Status](https://travis-ci.org/EOSIO/demux-js-eos.svg?branch=develop)](https://travis-ci.org/EOSIO/demux-js-eos)

Demux Action Reader implementations to read block and action data from EOSIO-based blockchains.

## Installation

Expand All @@ -14,24 +15,86 @@ npm install demux-eos --save

## Usage

### MongoDB Plugin
This library provides two Action Reader implementations for reading from EOSIO blockchains: `NodeosActionReader` and `MongoActionReader`. **It is currently recomended to use the `MongoActionReader` due to performance and the ability to read inline and deferred actions.**

### MongoActionReader

Reads from a node's attached MongoDB instance when configured to use the MonogoDB Plugin.

#### Setup

To use the `MongoActionReader`, you must first make sure that your environment is properly configured, as it otherwise may yield unpredictable or incorrect results. To set up a proper environment, make sure the following are true:

- The node that has the MongoDB plugin activated:
- Is not producing blocks
- Is connected to the node(s) producing blocks via the `p2p-peer-address` configuration
- Has the `read-mode` configuration set to `read-only`
- Has the `mongodb-update-via-block-num` configuration enabled

This means that in a development environment, you will need to set up at least two Nodeos instances: one to produce blocks, and a peer with the MongoDB plugin activated to populate the attached MongoDB.

For performance, the following settings are also recommended:

- Since the only collections utilized are the `block_states` and `action_traces`, we can save space by not indexing any of the other collections via setting the following options to `false`:
- `mongodb-store-blocks`
- `mongodb-store-transactions`
- `mongodb-store-transaction-traces`
- Use the `mongodb-filter-out` option to isolate which accounts/actions you are indexing to only the actions you are listening for in your Action Handler. This will further reduce space requirements, and may give a performance boost via faster queries and less data for the Action Handler to process. For more information on how to filter, [see the MongoDB Plugin documentation](https://developers.eos.io/eosio-nodeos/docs/mongo_db_plugin#section-options).

#### Inline and Deferred Actions

Unlike the `NodeosActionReader`, inline and deferred actions are able to be captured and passed on to the Action Handler. Additionally, each Action has a `notifiedAccounts` property that lists all accounts notified of the blockchain action (this information is also not available via the `NodeosActionReader`).

#### Example

```javascript
const { BaseActionWatcher } = require("demux")
const { MongoActionReader } = require("demux-eos")

const actionHandler = ... // see https://github.com/EOSIO/demux-js-postgres for a supported ActionHandler
// See supported Action Handlers here: https://github.com/EOSIO/demux-js#class-implementations
const actionHandler = ...

const actionReader = new MongoActionReader(
mongodbHost, // the url of the mongodb instance (mongodb://localhost:27017)
2, // the mongodb plugin starts at block 2
false, // whether or not to only process irreversible blocks
600, // the maximum history length
mongoDbName, // name of the database
"mongo://...", // mongoEndpoint: the url of the mongodb instance
1234, // startAtBlock: the first block relevant to our application
false, // onlyIrreversible: whether or not to only process irreversible blocks
600, // the maximum history length
"EOS", // name of the database
)

const actionWatcher = new BaseActionWatcher(actionReader, actionHander, 500)

await actionReader.initialize() // This must be done before calling watch so the MongoDB connection can be made
// This must be done before calling watch so the MongoDB connection can be made
actionReader.initialize().then(() =>
actionWatcher.watch()
)
```

### NodeosActionReader

Makes requests directly to a specified Nodeos API endpoint to obtain block data.

#### Setup

All that is required is a running Nodeos instance that has the `chain_api_plugin` enabled.

#### Example

```javascript
const { BaseActionWatcher } = require("demux")
const { MongoActionReader } = require("demux-eos")

// See supported Action Handlers here: https://github.com/EOSIO/demux-js#class-implementations
const actionHandler = ...

const actionReader = new MongoActionReader(
"http://...", // mongoEndpoint: the url of the Nodeos API
1234, // startAtBlock: the first block relevant to our application
false, // onlyIrreversible: whether or not to only process irreversible blocks
600, // the maximum history length
)

const actionWatcher = new BaseActionWatcher(actionReader, actionHander, 500)

actionWatcher.watch()
```

26 changes: 26 additions & 0 deletions __mocks__/eosjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Api {
deserializeActions(actionTraces) {
const returnVals = []
for (const at of actionTraces) {
returnVals.push({
account: at.account,
name: at.name,
authorization: at.authorization,
data: {
from: 'useraaaaaaaa',
to: 'userbbbbbbbb',
quantity: '0.0100 EOS',
memo: ''
}
})
}
return returnVals
}
}

class JsonRpc {}

module.exports = {
Api,
JsonRpc
}
39 changes: 39 additions & 0 deletions __mocks__/massive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const massive = () => {
return {
chain: {
account: {
findOne: () => ({
account_name: 'test',
abi: [10, 11, 12],
}),
},
fill_status: {
findOne: () => ({
head: 4,
irreversible: 3,
}),
},
block_info: {
findOne: () => ({
block_index: 4,
block_id: 'qwerty1234',
previous: 'qwerty1233',
timestamp: new Date().toString(),
}),
}
},
query: () => ([
{
account: 'token',
name: 'transfer',
authorization: [{
actor: 'useraaaaaaaa',
permission: 'active',
}],
data: [100, 100, 100, 100, 100, 100, 100],
}
]),
}
}

module.exports = massive
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
},
"license": "MIT",
"devDependencies": {
"@blockone/tslint-config-blockone": "^1.0.0",
"@types/bunyan": "^1.8.5",
"@types/jest": "^23.1.4",
"@types/massive": "^5.4.1",
"@types/mongodb": "^3.1.4",
"@types/node": "^10.5.1",
"@types/node-fetch": "^2.1.6",
"@types/request-promise-native": "^1.0.15",
"eslint": "^4.9.0",
"eslint-config-airbnb-base": "12.1.0",
"eslint-plugin-import": "^2.7.0",
"jest": "^22.4.3",
"release-it": "^7.5.0",
"ts-jest": "^23.0.0",
Expand All @@ -29,8 +29,11 @@
},
"dependencies": {
"bunyan": "^1.8.12",
"demux": "^3.1.3",
"demux": "^3.1.4-8cfe8c1.0",
"eosjs": "^20.0.0-beta3",
"massive": "^5.7.5",
"mongodb": "^3.1.3",
"node-fetch": "^2.3.0",
"request": "^2.87.0",
"request-promise-native": "^1.0.5"
},
Expand All @@ -42,9 +45,9 @@
"compile": "tsc",
"build": "tsc",
"watch": "tsc -w",
"lint": "tslint -c tslint.json src/**/*.ts",
"lint": "tslint -c tslint.json -p tsconfig.json",
"test": "jest",
"build-docs": "./build-docs.sh",
"build-docs": "./scripts/build-docs.sh",
"current-version": "echo $npm_package_version"
},
"jest": {
Expand Down
File renamed without changes.
29 changes: 0 additions & 29 deletions src/MongoActionReader.test.ts

This file was deleted.

Loading

0 comments on commit ab2b521

Please sign in to comment.