From 583c7a3b60e3858d036c104ef06d9efdcb84059f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 21 Oct 2019 14:22:49 -0400 Subject: [PATCH] support disabling database --- src/{ => database}/database.js | 0 src/database/nullDatabase.js | 43 ++++++++++++++++++++++++++++++++++ src/subspace.js | 11 ++++++--- 3 files changed, 51 insertions(+), 3 deletions(-) rename src/{ => database}/database.js (100%) create mode 100644 src/database/nullDatabase.js diff --git a/src/database.js b/src/database/database.js similarity index 100% rename from src/database.js rename to src/database/database.js diff --git a/src/database/nullDatabase.js b/src/database/nullDatabase.js new file mode 100644 index 0000000..36164ac --- /dev/null +++ b/src/database/nullDatabase.js @@ -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; diff --git a/src/subspace.js b/src/subspace.js index 42078d6..ff5d2bc 100644 --- a/src/subspace.js +++ b/src/subspace.js @@ -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);