# chronobank-middleware

> chronobank's middleware installer

Latest version **1.0.8** (published 2018-04-12) · AGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install chronobank-middleware
pnpm add chronobank-middleware
yarn add chronobank-middleware
bun add chronobank-middleware
```

Provides the command `dmt`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2018-04-12 |
| First published | 2017-11-24 |
| Weekly downloads | 0 |
| License | AGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 59.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | chronobank |
| Maintainers | zuev.egor |
| Keywords | chonobank, middleware |

## Links

- npm: https://www.npmjs.com/package/chronobank-middleware
- Repository: https://github.com/ChronoBank/Middleware
- Homepage: http://chronobank.io
- Issues: https://github.com/ChronoBank/Middleware/issues
- npm.io page: https://npm.io/package/chronobank-middleware

## Dependencies (10)

- [chalk](https://npm.io/package/chalk.md) ^2.1.0
- [bunyan](https://npm.io/package/bunyan.md) ^1.8.12
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [request](https://npm.io/package/request.md) ^2.83.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^4.0.2
- [inquirer](https://npm.io/package/inquirer.md) ^3.2.3
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.2
- [download-git-repo](https://npm.io/package/download-git-repo.md) ^1.0.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2018-04-12
- 1.0.6 — 2018-04-10
- 1.0.5 — 2018-03-28
- 1.0.4 — 2018-02-08
- 1.0.2 — 2017-12-08
- 1.0.1 — 2017-11-24

## README

# Middleware [![Build Status](https://travis-ci.org/ChronoBank/Middleware.svg?branch=master)](https://travis-ci.org/ChronoBank/Middleware)

Middleware service installer

### Installation

first do:
```
npm install -g chronobank-middleware
```

then init skeleton of project:
```
dmt init
```

finally run installer:
```
dmt install
```

You should see available modules to install in cli. Check modules you want to install to - and the rest of the work installer will handle.

#### Installation without CLI

If you don't have a chance to run cli - then you can just pass modules, you will to install as args:

```
dmt install middleware-eth-blockprocessor middleware-eth-rest
```
This will run install the following modules from latest master branch

In order, to obtain certain release (tag) you can do like that:

```
dmt install middleware-eth-blockprocessor#0.0.5 middleware-eth-rest#0.0.5
```

### Modules
The middleware consists of components called 'modules'. Each of them is responsible for certain functionality. Most modules are optional. The only necessary one is blockprocessor, which is responsible for interaction with blockchain node and notify other services about new txs and blocks.

### Configure
There are 2 possible scenarious of running the middleware modules:

##### via .env

To apply your configuration, create a .env file in root folder of project (in case it's not present already).
Below is the expamle configuration:

```
MONGO_URI=mongodb://localhost:27017/data
REST_PORT=8081
IPFS_NODES=http://localhost:5001, http://localhost:5001
SCHEDULE_JOB=30 * * * * *
RABBIT_SERVICE_NAME=app_eth
RABBIT_URI=amqp://localhost:5672
SMART_CONTRACTS_EVENTS_TTL=0
SM_EVENTS=setHash:newHash:oldHash
NETWORK=development
WEB3_URI=/tmp/development/geth.ipc
```

The options are presented below:

| name | description|
| ------ | ------ |
| MONGO_URI   | the URI string for mongo connection
| REST_PORT   | rest plugin port
| IPFS_NODES   | should contain a comma separated uri connection strings for ipfs nodes
| SCHEDULE_JOB   | a configuration for ipfs pin plugin in a cron based format
| RABBIT_SERVICE_NAME   | namespace for all rabbitmq queues, like 'app_eth_transaction'
| RABBIT_URI   | rabbitmq URI connection string
| SMART_CONTRACTS_EVENTS_TTL   | how long should we keep events in db (should be set in seconds)
| SM_EVENTS   | smart contract's event definition for hash create/update (ipfs multihash). Has the following signature: 'event_name:new_hash_field:old_hash_field'. 3 argument (old_hash_field) is optional
| NETWORK   | network name (alias)- is used for connecting via ipc (see block processor section)
| WEB3_URI   | the path to ipc interface

In this case, you should run the processes from the root folder, like that:
```
node core/blockProcessor
```

##### via ecosystem.config.js

If you want to run a cluster, then you need to install pm2 manager first:
```
npm install -g pm2
```

And edit the ecosystem.config.js according your needs:
```
apps = [
    {
      name: 'block_processor',
      script: 'core/middleware-eth-blockprocessor',
      env: {
        MONGO_URI: 'mongodb://localhost:27017/data',
        RABBIT_URI: 'amqp://localhost:5672',
        RABBIT_SERVICE_NAME: 'app_eth',
        NETWORK: 'development',
        WEB3_URI: '/tmp/development/geth.ipc'
      }
    },
    {
      name: 'balance_processor',
      script: 'core/middleware-eth-balance-processor',
      env: {
        MONGO_URI: 'mongodb://localhost:27017/data',
        RABBIT_URI: 'amqp://localhost:5672',
        RABBIT_SERVICE_NAME: 'app_eth',
        NETWORK: 'development',
        WEB3_URI: '/tmp/development/geth.ipc'
      }
    },
    {
      name: 'rest',
      script: 'core/middleware-eth-rest',
      env: {
        MONGO_URI: 'mongodb://localhost:27017/data',
        REST_PORT: 8081,
        NETWORK: 'development',
        WEB3_URI: '/tmp/development/geth.ipc'
      }
    },
    {
      name: 'ipfs',
      script: 'core/middleware-eth-ipfs',
      env: {
        MONGO_URI: 'mongodb://localhost:27017/data',
        RABBIT_URI: 'amqp://localhost:5672',
        RABBIT_SERVICE_NAME: 'app_eth',
        IPFS_NODES: 'http://localhost:5001',
        SCHEDULE_JOB: '30 * * * * *',
        SM_EVENTS: 'setHash:newHash:oldHash'
      }
    },
    {
      name: 'chrono_sc_processor',
      script: 'core/middleware-eth-chrono-sc-processor',
      env: {
        MONGO_URI: 'mongodb://localhost:27017/data',
        RABBIT_URI: 'amqp://localhost:5672',
        SMART_CONTRACTS_EVENTS_TTL: 0,
        RABBIT_SERVICE_NAME: 'app_eth',
        NETWORK: 'development',
        WEB3_URI: '/tmp/development/geth.ipc'
      }
    },
    {
      name: 'erc20_processor',
      script: 'core/middleware-eth-erc20',
      env: {
        MONGO_URI: 'mongodb://localhost:27017/data',
        RABBIT_URI: 'amqp://localhost:5672',
        RABBIT_SERVICE_NAME: 'app_eth',
        NETWORK: 'development',
        WEB3_URI: '/tmp/development/geth.ipc'
      }
    }
  ];
```

Options are the same, as in .env. The only difference, is that they are specified for each app in a separate way.
Modules, which are not installed - will be ignored in configuration

After all is done, just start cluster with:
```
pm2 start ecosystem.config.js
```

### SDK

Beside modules installation, the middleware installer let you init the service sdk constructor. This constructor can be used to create your own microservices around current middleware infrastructure!
The sdk is based on node-red, which means you can create your own solution with web UI and without code at all.
In order to install it, type:
```
dmt starter <module-name>
```
This will init the preflight project inside the specified dir (module-name).

##### сonfigure SDK

To apply your configuration, create a .env file in root folder of repo (in case it's not present already).
Below is the expamle configuration:

```
MONGO_ACCOUNTS_URI=mongodb://localhost:27017/data
MONGO_ACCOUNTS_COLLECTION_PREFIX=eth

NODERED_MONGO_URI=mongodb://localhost:27018/data
NODE_RED_MONGO_COLLECTION_PREFIX=rest

REST_PORT=8081
NODERED_AUTO_SYNC_MIGRATIONS=1
USE_HTTP_SERVER=1
```

The options are presented below:

| name | description|
| ------ | ------ |
| MONGO_URI   | the URI string for mongo connection
| MONGO_COLLECTION_PREFIX   | the default prefix for all mongo collections. The default value is 'eth'
| MONGO_ACCOUNTS_URI   | the URI string for mongo connection, which holds users accounts (if not specified, then default MONGO_URI connection will be used)
| MONGO_ACCOUNTS_COLLECTION_PREFIX   | the collection prefix for accounts collection in mongo (If not specified, then the default MONGO_COLLECTION_PREFIX will be used)
| NODERED_MONGO_URI   | the URI string for mongo connection, which holds data collections (for instance, processed block's height). In case, it's not specified, then default MONGO_URI connection will be used)
| NODE_RED_MONGO_COLLECTION_PREFIX   | the collection prefix for node-red collections in mongo (If not specified, then the collections will be created without prefix)
| REST_PORT   | rest plugin port
| USE_HTTP_SERVER   | enable or disable http server. Recommended to set to false in production, in case you don't use any http interface
| NODERED_AUTO_SYNC_MIGRATIONS   | autosync migrations on start (default = yes)


License
----
 [GNU AGPLv3](LICENSE)

Copyright
----
LaborX PTY

---
_Source: https://npm.io/package/chronobank-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
