support disabling database

This commit is contained in:
Iuri Matias 2019-10-21 14:22:49 -04:00
parent 5a7ed7238b
commit 583c7a3b60
3 changed files with 51 additions and 3 deletions

View File

@ -0,0 +1,43 @@
class NullDatabase {
constructor(_dbFilename, events, cb) {
this.events = events;
if (cb) {
cb();
}
}
databaseInitialize(cb) {
if (cb) {
cb();
}
}
getLastKnownEvent() {
return {
firstKnownBlock: 0,
lastKnownBlock: 0
};
}
getEventsFor(eventKey) {
return [];
}
eventExists(eventKey, eventId) {
return false;
}
recordEvent(eventKey, values) {
}
deleteEvent(eventKey, eventId) {
}
deleteNewestBlocks(eventKey, gteBlockNum) {
}
}
export default NullDatabase;

View File

@ -1,7 +1,8 @@
import { ReplaySubject } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';
import equal from 'fast-deep-equal';
import Database from './database.js';
import Database from './database/database.js';
import NullDatabase from './database/nullDatabase.js';
import Events from 'events';
import Web3Eth from 'web3-eth';
import {isAddress} from './utils';
@ -25,6 +26,7 @@ export default class Subspace {
this.options.callInterval = options.callInterval || 0;
this.options.dbFilename = options.dbFilename || 'subspace.db';
this.latestBlockNumber = undefined;
this.disableDatabase = options.disableDatabase;
this.newBlocksSubscription = null;
this.intervalTracker = null;
@ -33,8 +35,11 @@ export default class Subspace {
init() {
return new Promise((resolve, reject) => {
this._db = new Database(this.options.dbFilename, this.events);
this.db = this._db.db;
if (this.disableDatabase === true) {
this._db = new NullDatabase("", this.events);
} else {
this._db = new Database(this.options.dbFilename, this.events);
}
this.eventSyncer = new EventSyncer(this.web3, this.events, this._db);
this.logSyncer = new LogSyncer(this.web3, this.events, this._db);