support disabling database
This commit is contained in:
parent
5a7ed7238b
commit
583c7a3b60
|
@ -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;
|
|
@ -1,7 +1,8 @@
|
||||||
import { ReplaySubject } from 'rxjs';
|
import { ReplaySubject } from 'rxjs';
|
||||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||||
import equal from 'fast-deep-equal';
|
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 Events from 'events';
|
||||||
import Web3Eth from 'web3-eth';
|
import Web3Eth from 'web3-eth';
|
||||||
import {isAddress} from './utils';
|
import {isAddress} from './utils';
|
||||||
|
@ -25,6 +26,7 @@ export default class Subspace {
|
||||||
this.options.callInterval = options.callInterval || 0;
|
this.options.callInterval = options.callInterval || 0;
|
||||||
this.options.dbFilename = options.dbFilename || 'subspace.db';
|
this.options.dbFilename = options.dbFilename || 'subspace.db';
|
||||||
this.latestBlockNumber = undefined;
|
this.latestBlockNumber = undefined;
|
||||||
|
this.disableDatabase = options.disableDatabase;
|
||||||
|
|
||||||
this.newBlocksSubscription = null;
|
this.newBlocksSubscription = null;
|
||||||
this.intervalTracker = null;
|
this.intervalTracker = null;
|
||||||
|
@ -33,8 +35,11 @@ export default class Subspace {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._db = new Database(this.options.dbFilename, this.events);
|
if (this.disableDatabase === true) {
|
||||||
this.db = this._db.db;
|
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.eventSyncer = new EventSyncer(this.web3, this.events, this._db);
|
||||||
this.logSyncer = new LogSyncer(this.web3, this.events, this._db);
|
this.logSyncer = new LogSyncer(this.web3, this.events, this._db);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue