Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Heller committed Feb 25, 2019
2 parents ab2b521 + 05121d6 commit 50d9ec6
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 2,068 deletions.
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "demux-eos",
"version": "3.1.0",
"version": "4.0.0",
"description": "Demux-js Action Reader implementations for EOSIO blockchains",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -20,16 +20,16 @@
"@types/node-fetch": "^2.1.6",
"@types/request-promise-native": "^1.0.15",
"jest": "^22.4.3",
"release-it": "^7.5.0",
"ts-jest": "^23.0.0",
"tslint": "^5.10.0",
"tslint-eslint-rules": "^5.3.1",
"typedoc": "^0.11.1",
"typescript": "^2.9.2"
},
"dependencies": {
"@types/express": "^4.16.1",
"bunyan": "^1.8.12",
"demux": "^3.1.4-8cfe8c1.0",
"demux": "^4.0.0",
"eosjs": "^20.0.0-beta3",
"massive": "^5.7.5",
"mongodb": "^3.1.3",
Expand All @@ -38,13 +38,10 @@
"request-promise-native": "^1.0.5"
},
"peerDependencies": {
"demux": "^3.1.3"
"demux": "4.0.0"
},
"scripts": {
"release": "release-it",
"compile": "tsc",
"build": "tsc",
"watch": "tsc -w",
"build": "rm -rf dist/* && tsc",
"lint": "tslint -c tslint.json -p tsconfig.json",
"test": "jest",
"build-docs": "./scripts/build-docs.sh",
Expand Down
1 change: 1 addition & 0 deletions scripts/build-docs.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rm -rf docs/*
./node_modules/.bin/typedoc --mode file --theme minimal --target "ES6" --exclude "**/*.test.ts,**/testHelpers/*" --hideGenerator --excludeExternals --excludeNotExported --includeDeclarations --readme none --out docs
16 changes: 15 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { Action } from 'demux'
import { Action, ActionReaderOptions } from 'demux'

export interface NodeosActionReaderOptions extends ActionReaderOptions {
nodeosEndpoint?: string
}

export interface MongoActionReaderOptions extends ActionReaderOptions {
mongoEndpoint?: string
dbName?: string
}

export interface StateHistoryPostgresActionReaderOptions extends ActionReaderOptions {
massiveConfig: any
dbSchema?: string
}

export interface EosAuthorization {
actor: string
Expand Down
14 changes: 12 additions & 2 deletions src/mongo/MongoActionReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ describe('MongoActionReader', () => {
let reader: any

beforeEach(async () => {
reader = new MongoActionReader('mongodb://127.0.0.1:27017', 0, false, 'EOS')
reader = new MongoActionReader({
startAtBlock: 0,
onlyIrreversible: false,
mongoEndpoint: 'mongodb://127.0.0.1:27017',
dbName: 'EOS'
})
await reader.initialize()
})

Expand All @@ -29,7 +34,12 @@ describe('MongoActionReader', () => {
})

it('throws if not correctly initialized', async () => {
const failedReader = new MongoActionReader('mongodb://127.0.0.1:27017', 0, false, 'failed')
const failedReader = new MongoActionReader({
startAtBlock: 0,
onlyIrreversible: false,
mongoEndpoint: 'mongodb://127.0.0.1:27017',
dbName: 'failed',
})
const result = failedReader.getNextBlock()
expect(result).rejects.toThrow(NotInitializedError)
})
Expand Down
20 changes: 8 additions & 12 deletions src/mongo/MongoActionReader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Logger from 'bunyan'
import { AbstractActionReader, NotInitializedError } from 'demux'
import { Db, MongoClient } from 'mongodb'
import {
Expand All @@ -8,27 +7,24 @@ import {
RetrieveHeadBlockError,
RetrieveIrreversibleBlockError,
} from '../errors'
import { MongoActionReaderOptions } from '../interfaces'
import { retry } from '../utils'
import { MongoBlock } from './MongoBlock'

/**
* Implementation of an ActionReader that reads blocks from a mongodb instance.
*/
export class MongoActionReader extends AbstractActionReader {
protected log: Logger

private mongodb: Db | null
public dbName: string
protected mongoEndpoint: string
private readonly requiredCollections: Set<string> = new Set(['action_traces', 'block_states'])
private mongodb: Db | null

constructor(
protected mongoEndpoint: string = 'mongodb://127.0.0.1:27017',
public startAtBlock: number = 1,
protected onlyIrreversible: boolean = false,
public dbName: string = 'EOS',
) {
super({startAtBlock, onlyIrreversible})
constructor(options: MongoActionReaderOptions = {}) {
super(options)
this.mongoEndpoint = options.mongoEndpoint ? options.mongoEndpoint : 'mongodb://127.0.0.1:27017'
this.dbName = options.dbName ? options.dbName : 'EOS'
this.mongodb = null
this.log = Logger.createLogger({ name: 'demux' })
}

public async getHeadBlockNumber(numRetries: number = 120, waitTimeMs: number = 250): Promise<number> {
Expand Down
6 changes: 5 additions & 1 deletion src/nodeos/NodeosActionReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ describe('NodeosActionReader', () => {
})

beforeEach(() => {
reader = new NodeosActionReader('', 10, false)
reader = new NodeosActionReader({
nodeosEndpoint: '',
startAtBlock: 10,
onlyIrreversible: false
})
})

it('returns head block number', async () => {
Expand Down
14 changes: 4 additions & 10 deletions src/nodeos/NodeosActionReader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Logger from 'bunyan'
import { AbstractActionReader, NotInitializedError } from 'demux'
import request from 'request-promise-native'
import { RetrieveBlockError, RetrieveHeadBlockError, RetrieveIrreversibleBlockError } from '../errors'
import { NodeosActionReaderOptions } from '../interfaces'
import { retry } from '../utils'
import { NodeosBlock } from './NodeosBlock'

Expand All @@ -12,17 +12,11 @@ import { NodeosBlock } from './NodeosBlock'
*/
export class NodeosActionReader extends AbstractActionReader {
protected nodeosEndpoint: string
protected log: Logger

constructor(
nodeosEndpoint: string = 'http://localhost:8888',
public startAtBlock: number = 1,
protected onlyIrreversible: boolean = false,
) {
super({startAtBlock, onlyIrreversible})
constructor(options: NodeosActionReaderOptions = {}) {
super(options)
const nodeosEndpoint = options.nodeosEndpoint ? options.nodeosEndpoint : 'http://localhost:8888'
this.nodeosEndpoint = nodeosEndpoint.replace(/\/+$/g, '') // Removes trailing slashes

this.log = Logger.createLogger({ name: 'demux' })
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/state-history/StateHistoryPostgresActionReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { StateHistoryPostgresActionReader } from './StateHistoryPostgresActionRe
describe('StateHistoryPostgresActionReader', () => {
let reader: any
beforeEach(async () => {
reader = new StateHistoryPostgresActionReader(
{},
{
reader = new StateHistoryPostgresActionReader({
massiveConfig: {
host: 'localhost',
port: 5432,
database: 'statehistory',
user: 'docker',
password: 'docker'
},
'chain'
)
dbSchema: 'chain',
})

await reader.setup()
})
Expand Down
13 changes: 7 additions & 6 deletions src/state-history/StateHistoryPostgresActionReader.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { AbstractActionReader, ActionReaderOptions, NotInitializedError } from 'demux'
import { AbstractActionReader, NotInitializedError } from 'demux'
import massive from 'massive'
import { StateHistoryPostgresActionReaderOptions } from '../interfaces'
import { StateHistoryPostgresBlock } from './StateHistoryPostgresBlock'

export class StateHistoryPostgresActionReader extends AbstractActionReader {
private db: any
private massiveInstance: massive.Database | null = null
private massiveConfig: any
private dbSchema: string

constructor(
options: ActionReaderOptions,
private massiveConfig: any,
private dbSchema: string = 'chain',
) {
constructor(options: StateHistoryPostgresActionReaderOptions) {
super(options)
this.massiveConfig = options.massiveConfig
this.dbSchema = options.dbSchema ? options.dbSchema : 'chain'
}

public async getHeadBlockNumber(): Promise<number> {
Expand Down
Loading

0 comments on commit 50d9ec6

Please sign in to comment.