Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add Eslint and prettier (#202)
Browse files Browse the repository at this point in the history
Added Eslint and prettier formatting, cleaned up linter errors throughout application, and fixed any broken tests.
  • Loading branch information
eshaben authored and davidmurdoch committed Oct 24, 2018
1 parent 398125f commit 7fb71a8
Show file tree
Hide file tree
Showing 81 changed files with 7,018 additions and 4,737 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ try {
// make sure these exist before we try to load ganache with native modules
const optionalDependencies = require("./package.json").optionalDependencies;
const wrongWeb3 = require("web3/package.json").version !== optionalDependencies["web3"];
const wrongEthereumJs = require("ethereumjs-wallet/package.json").version !== optionalDependencies["ethereumjs-wallet"];
const wrongEthereumJs = require(
"ethereumjs-wallet/package.json"
).version !== optionalDependencies["ethereumjs-wallet"];
if (wrongWeb3 || wrongEthereumJs) {
useBundled();
} else {
Expand All @@ -28,8 +30,8 @@ function useBundled() {
module.exports = require("./build/ganache.core.node.js");
module.exports._webpacked = true;
debug("Optional dependencies not installed; exporting ganache-core from `./build` directory.");
} catch(webpackError) {
} catch (webpackError) {
debug("ganache-core could not be exported; optional dependencies nor webpack build available for export.");
throw webpackError;
}
}
}
91 changes: 48 additions & 43 deletions lib/block_tracker.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,71 @@
// this replaces `eth-block-tracker` in the provider-engine, as that block tracker is meant to work with
// an external provider instance

const EventEmitter = require('events')
const BlockSerializer = require('./database/blockserializer')
var blockHelper = require('./utils/block_helper');
const to = require('./utils/to')
const EventEmitter = require("events");
var blockHelper = require("./utils/block_helper");

function GanacheBlockTracker(opts) {
opts = opts || {}
EventEmitter.apply(this)
if (!opts.blockchain) throw new Error('RpcBlockTracker - no blockchain specified.')
if (!opts.blockchain.on) throw new Error('RpcBlockTracker - blockchain is not an EventEmitter.')
this._blockchain = opts.blockchain
this.start = this.start.bind(this)
this.stop = this.stop.bind(this)
this.getTrackingBlock = this.getTrackingBlock.bind(this)
this.awaitCurrentBlock = this.awaitCurrentBlock.bind(this)
this._setCurrentBlock = this._setCurrentBlock.bind(this)
opts = opts || {};
EventEmitter.apply(this);
if (!opts.blockchain) {
throw new Error("RpcBlockTracker - no blockchain specified.");
}
if (!opts.blockchain.on) {
throw new Error("RpcBlockTracker - blockchain is not an EventEmitter.");
}
this._blockchain = opts.blockchain;
this.start = this.start.bind(this);
this.stop = this.stop.bind(this);
this.getTrackingBlock = this.getTrackingBlock.bind(this);
this.awaitCurrentBlock = this.awaitCurrentBlock.bind(this);
this._setCurrentBlock = this._setCurrentBlock.bind(this);
}

GanacheBlockTracker.prototype = Object.create(EventEmitter.prototype)
GanacheBlockTracker.prototype.constructor = GanacheBlockTracker
GanacheBlockTracker.prototype = Object.create(EventEmitter.prototype);
GanacheBlockTracker.prototype.constructor = GanacheBlockTracker;

GanacheBlockTracker.prototype.getTrackingBlock = function() {
return this._currentBlock
}
return this._currentBlock;
};

GanacheBlockTracker.prototype.getCurrentBlock = function() {
return this._currentBlock
}
return this._currentBlock;
};

GanacheBlockTracker.prototype.awaitCurrentBlock = function() {
const self = this
const self = this;
// return if available
if (this._currentBlock) return this._currentBlock
if (this._currentBlock) {
return this._currentBlock;
}
// wait for "sync" event
return new Promise(resolve => this.once('block', resolve))
.then(() => self._currentBlock)
}
return new Promise((resolve) => this.once("block", resolve)).then(() => self._currentBlock);
};

GanacheBlockTracker.prototype.start = function(opts = {}) {
this._blockchain.on('block', this._setCurrentBlock)
return Promise.resolve()
}
this._blockchain.on("block", this._setCurrentBlock);
return Promise.resolve();
};

GanacheBlockTracker.prototype.stop = function() {
this._isRunning = false
this._blockchain.removeListener('block', this._setCurrentBlock)
}
this._isRunning = false;
this._blockchain.removeListener("block", this._setCurrentBlock);
};

//
// private
//
//
// private
//

GanacheBlockTracker.prototype._setCurrentBlock = function(newBlock) {
let block = blockHelper.toJSON(newBlock, true)
if (this._currentBlock && (this._currentBlock.hash === block.hash)) return
const oldBlock = this._currentBlock
this._currentBlock = block
this.emit('latest', block)
this.emit('sync', { block, oldBlock })
this.emit('block', block)
}
let block = blockHelper.toJSON(newBlock, true);
if (this._currentBlock && this._currentBlock.hash === block.hash) {
return;
}
const oldBlock = this._currentBlock;
this._currentBlock = block;
this.emit("latest", block);
this.emit("sync", { block, oldBlock });
this.emit("block", block);
};

module.exports = GanacheBlockTracker
module.exports = GanacheBlockTracker;

0 comments on commit 7fb71a8

Please sign in to comment.