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

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjpaterno committed Jan 20, 2020
1 parent f7698fa commit 8d900ac
Show file tree
Hide file tree
Showing 28 changed files with 201 additions and 178 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ const debug = require("debug")("ganache");
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 wrongWeb3 = require("web3/package.json").version !== optionalDependencies.web3;
const wrongEthereumJs =
require("ethereumjs-wallet/package.json").version !== optionalDependencies["ethereumjs-wallet"];
if (wrongWeb3 || wrongEthereumJs) {
useBundled();
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/block_tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GanacheBlockTracker.prototype.stop = function() {
//

GanacheBlockTracker.prototype._setCurrentBlock = function(newBlock) {
let block = blockHelper.toJSON(newBlock, true);
const block = blockHelper.toJSON(newBlock, true);
if (this._currentBlock && this._currentBlock.hash === block.hash) {
return;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/blockchain_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ BlockchainDouble.prototype.sortByPriceAndNonce = function() {
const sortedTransactions = [];
while (heap.size() > 0) {
const best = heap.pop();
let address = best.from.toString("hex");
const address = best.from.toString("hex");
if (sortedByNonce[address].length > 0) {
// Push on the next transaction from this account
heap.push(sortedByNonce[address].shift());
Expand Down Expand Up @@ -686,7 +686,7 @@ BlockchainDouble.prototype.processBlock = async function(vm, block, commit, call
}
}

let rcpt = new Receipt(
const rcpt = new Receipt(
tx,
block,
txLogs,
Expand Down Expand Up @@ -827,12 +827,12 @@ BlockchainDouble.prototype.processTransactionTrace = async function(hash, params
let txCurrentlyProcessing = null;
let vm;

let storageStack = {
const storageStack = {
currentDepth: -1,
stack: []
};

let returnVal = {
const returnVal = {
gas: 0,
returnValue: "",
structLogs: []
Expand Down Expand Up @@ -905,7 +905,7 @@ BlockchainDouble.prototype.processTransactionTrace = async function(hash, params
return callback(new Error("Unknown transaction " + targetHash));
}

let targetBlock = receipt.block;
const targetBlock = receipt.block;

// Get the parent of the target block
self.getBlock(targetBlock.header.parentHash, function(err, parent) {
Expand Down Expand Up @@ -1198,7 +1198,7 @@ BlockchainDouble.prototype.getTransactionReceipt = function(hash, callback) {
const pendingTxs = this.pending_transactions;

for (var i = 0; i < pendingTxs.length; i++) {
let pendingTxHash = to.hex(pendingTxs[i].hash());
const pendingTxHash = to.hex(pendingTxs[i].hash());
if (hash === pendingTxHash) {
return callback(null, { tx: pendingTxs[i] });
}
Expand Down
2 changes: 1 addition & 1 deletion lib/database/filedown.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const accessQueue = {
}
},
execute: (lKey, callback) => {
let cache = accessQueue.cache[lKey];
const cache = accessQueue.cache[lKey];
if (cache) {
cache.push(callback);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/database/leveluparrayadapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ LevelUpArrayAdapter.prototype.get = function(index, callback) {
}
if (index >= length) {
// index out of range
let RangeError =
const RangeError =
self.name === "blocks"
? new BlockOutOfRangeError(index, length)
: new LevelUpOutOfRangeError(self.name, index, length);
Expand Down
6 changes: 4 additions & 2 deletions lib/httpServer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const http = require("http");
const { rpcError } = require("./utils/to");

const hasOwnProperty = Object.prototype.hasOwnProperty;

function createCORSResponseHeaders(method, requestHeaders) {
// https://fetch.spec.whatwg.org/#http-requests
const headers = {};
let isCORSRequest = requestHeaders.hasOwnProperty("origin");
const isCORSRequest = hasOwnProperty.call(requestHeaders, "origin");
if (isCORSRequest) {
// OPTIONS preflight requests need a little extra treatment
if (method === "OPTIONS") {
// we only allow POST requests, so it doesn't matter which method the request is asking for
headers["Access-Control-Allow-Methods"] = "POST";
// echo all requested access-control-request-headers back to the response
if (requestHeaders.hasOwnProperty("access-control-request-headers")) {
if (hasOwnProperty.call(requestHeaders, "access-control-request-headers")) {
headers["Access-Control-Allow-Headers"] = requestHeaders["access-control-request-headers"];
}
// Safari needs Content-Length = 0 for a 204 response otherwise it hangs forever
Expand Down
34 changes: 17 additions & 17 deletions lib/provider.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// make sourcemaps work!
require("source-map-support/register");

let ProviderEngine = require("web3-provider-engine");
let SubscriptionSubprovider = require("web3-provider-engine/subproviders/subscriptions");
const ProviderEngine = require("web3-provider-engine");
const SubscriptionSubprovider = require("web3-provider-engine/subproviders/subscriptions");

let RequestFunnel = require("./subproviders/requestfunnel");
let DelayedBlockFilter = require("./subproviders/delayedblockfilter");
let GethDefaults = require("./subproviders/gethdefaults");
let GethApiDouble = require("./subproviders/geth_api_double");
const RequestFunnel = require("./subproviders/requestfunnel");
const DelayedBlockFilter = require("./subproviders/delayedblockfilter");
const GethDefaults = require("./subproviders/gethdefaults");
const GethApiDouble = require("./subproviders/geth_api_double");

let BlockTracker = require("./block_tracker");
const BlockTracker = require("./block_tracker");

let RuntimeError = require("./utils/runtimeerror");
let EventEmitter = require("events");
const RuntimeError = require("./utils/runtimeerror");
const EventEmitter = require("events");

let _ = require("lodash");
const _ = require("lodash");

function Provider(options) {
const self = this;
EventEmitter.call(this);

this.options = options = self._applyDefaultOptions(options || {});

let gethApiDouble = new GethApiDouble(options, this);
const gethApiDouble = new GethApiDouble(options, this);

this.engine = new ProviderEngine({
blockTracker: new BlockTracker({ blockchain: gethApiDouble.state.blockchain })
});

let subscriptionSubprovider = new SubscriptionSubprovider();
const subscriptionSubprovider = new SubscriptionSubprovider();

this.engine.manager = gethApiDouble;
this.engine.addProvider(new RequestFunnel());
Expand Down Expand Up @@ -77,9 +77,9 @@ Provider.prototype.send = function(payload, callback) {
);
}

let self = this;
const self = this;

let externalize = function(payload) {
const externalize = function(payload) {
return _.cloneDeep(payload);
};

Expand All @@ -89,7 +89,7 @@ Provider.prototype.send = function(payload, callback) {
payload = externalize(payload);
}

let intermediary = function(err, result) {
const intermediary = function(err, result) {
// clone result so that we can mutate the response without worrying about
// that messing up assumptions the calling logic might have about us
// mutating things
Expand Down Expand Up @@ -160,7 +160,7 @@ Provider.prototype._processRequestQueue = function() {

self._requestInProgress = true;

let args = self._requestQueue.shift();
const args = self._requestQueue.shift();

if (args) {
self.engine.sendAsync(args.payload, (err, result) => {
Expand Down Expand Up @@ -188,7 +188,7 @@ Provider.prototype.cleanUpErrorObject = function(err, response) {
return response;
}

let errorObject = {
const errorObject = {
error: {
data: {}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
let connectionCounter = 0;
const connections = {};
server.on("connection", (conn) => {
let key = connectionCounter++;
const key = connectionCounter++;
connections[key] = conn;
conn.on("close", () => delete connections[key]);
});
Expand Down
19 changes: 10 additions & 9 deletions lib/statemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ StateManager.prototype._applyDefaultOptions = function(options) {

// generate a randomized default mnemonic
if (!options.mnemonic) {
let randomBytes = random.randomBytes(16, seedrandom(options.seed));
const randomBytes = random.randomBytes(16, seedrandom(options.seed));
options.mnemonic = bip39.entropyToMnemonic(randomBytes.toString("hex"));
}

Expand All @@ -103,7 +103,7 @@ StateManager.prototype.initialize = function(callback) {

var accounts = [];

let defaultBalanceWei = to.hex(Web3.utils.toWei(self.options.default_balance_ether.toString(), "ether"));
const defaultBalanceWei = to.hex(Web3.utils.toWei(self.options.default_balance_ether.toString(), "ether"));

if (self.options.accounts) {
accounts = self.options.accounts.map(self.createAccount.bind(self));
Expand Down Expand Up @@ -137,8 +137,8 @@ StateManager.prototype.initialize = function(callback) {
self.unlocked_accounts = self.options.unlocked_accounts.reduce(function(obj, address) {
// If it doesn't have a hex prefix, must be a number (either a string or number type).
if ((address + "").indexOf("0x") !== 0) {
let idx = parseInt(address);
let account = accounts[idx];
const idx = parseInt(address);
const account = accounts[idx];
if (!account) {
throw new Error(`Account at index ${idx} not found. Max index available is ${accounts.length - 1}.`);
}
Expand Down Expand Up @@ -294,7 +294,7 @@ StateManager.prototype.queueRawTransaction = function(data, callback) {
// Reason: historically we didn't validate chain ids.
let chainId;
if (Buffer.isBuffer(data)) {
let decodedData = rlp.decode(data);
const decodedData = rlp.decode(data);
let v = decodedData[6];
if (v !== undefined) {
v = utils.bufferToInt(v);
Expand All @@ -304,7 +304,7 @@ StateManager.prototype.queueRawTransaction = function(data, callback) {
}
}
}
let common = !chainId
const common = !chainId
? this.blockchain.vm.opts.common
: Common.forCustomChain(
"mainnet", // TODO needs to match chain id
Expand All @@ -317,7 +317,7 @@ StateManager.prototype.queueRawTransaction = function(data, callback) {
},
this.options.hardfork
);
let tx = new Transaction(data, Transaction.types.signed, common);
const tx = new Transaction(data, Transaction.types.signed, common);
// use toLowerCase() to properly handle from addresses meant to be validated.
const from = to.hex(tx.from).toLowerCase();
this._queueTransaction("eth_sendRawTransaction", tx, from, null, callback);
Expand Down Expand Up @@ -352,9 +352,10 @@ StateManager.prototype.queueTransaction = function(method, txJsonRpc, blockNumbe
return callback(new TXRejectedError("Invalid to address"));
}

const isKnownAccount = this.accounts.hasOwnProperty(from);
const hasOwnProperty = Object.prototype.hasOwnProperty;
const isKnownAccount = hasOwnProperty.call(this.accounts, from);

if (method === "eth_sendTransaction" && !this.unlocked_accounts.hasOwnProperty(from)) {
if (method === "eth_sendTransaction" && !hasOwnProperty.call(this.unlocked_accounts, from)) {
const msg = isKnownAccount ? "signer account is locked" : "sender account not recognized";
return callback(new TXRejectedError(msg));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/gas/guestimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = async(vm, runArgs, callback) => {
const base = index === 0;
let start = index;
let stop = 0;
let cost = bn();
const cost = bn();
let sixtyFloorths = bn();
const op = steps.ops[index];
const next = steps.ops[index + 1];
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/to.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let utils = require("ethereumjs-util");
const utils = require("ethereumjs-util");

module.exports = {
buffer: function(val) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ function initData(tx, data) {
}
if (field === "gasLimit") {
if (keys.indexOf("gas") !== -1) {
self["gas"] = data["gas"];
self.gas = data.gas;
}
} else if (field === "data") {
if (keys.indexOf("input") !== -1) {
self["input"] = data["input"];
self.input = data.input;
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe("Accounts", () => {
}

async function runTests(intervalMining = true) {
let expectedNonce = new BN(currentNonce);
const expectedNonce = new BN(currentNonce);
let expectedBlockNum = startingBlockNumber + 1;

if (intervalMining) {
Expand Down
14 changes: 7 additions & 7 deletions test/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const customRequestHeader = "X-PINGOTHER";
function test(host, port) {
describe("CORS", () => {
it("should set response headers correctly in a preflight request", (done) => {
let req = request.options(
const req = request.options(
{
url: "http://" + host + ":" + port,
headers: {
Expand Down Expand Up @@ -50,8 +50,8 @@ function test(host, port) {
});

it("should set response.Access-Control-Allow-Origin to equal request.Origin if request.Origin is set", (done) => {
let origin = "https://localhost:3000";
let req = request.options(
const origin = "https://localhost:3000";
const req = request.options(
{
url: "http://" + host + ":" + port,
headers: {
Expand All @@ -65,8 +65,8 @@ function test(host, port) {
}

let accessControlAllowOrigin = "";

if (response.headers.hasOwnProperty("access-control-allow-origin")) {
const hasOwnProperty = Object.prototype.hasOwnProperty;
if (hasOwnProperty.call(response.headers, "access-control-allow-origin")) {
accessControlAllowOrigin = response.headers["access-control-allow-origin"];
}

Expand All @@ -84,8 +84,8 @@ function test(host, port) {
});

it("should set Access-Control-Allow-Credentials=true if the Origin is set.", (done) => {
let origin = "https://localhost:3000";
let req = request.options(
const origin = "https://localhost:3000";
const req = request.options(
{
url: "http://" + host + ":" + port,
headers: {
Expand Down

0 comments on commit 8d900ac

Please sign in to comment.