From 58234e5496d1a59b9c26cc0009c65a119ef3a848 Mon Sep 17 00:00:00 2001 From: Fabian Vogelsteller Date: Wed, 2 Nov 2016 15:51:52 +0100 Subject: [PATCH] lint improvments --- docs/web3-eth.rst | 33 ++++++++++++++++++++++++++++--- docs/web3-utils.rst | 40 ++++++++++++++++++++++++++++++++++++++ lib/web3/contract.js | 23 ++++++++++------------ lib/web3/method.js | 4 ++-- lib/web3/requestmanager.js | 2 +- lib/web3/subscription.js | 1 - lib/web3/subscriptions.js | 3 +-- 7 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 docs/web3-utils.rst diff --git a/docs/web3-eth.rst b/docs/web3-eth.rst index 9d8b775..00f01d3 100644 --- a/docs/web3-eth.rst +++ b/docs/web3-eth.rst @@ -6,7 +6,34 @@ Some text ------------------------------------------------------------------------------ -web3.version -============ +example +===================== -XYZ +.. code-block:: javascript + + web3.setProvider(myProvider) + +When called changes the current provider for all modules. + +---------- +Parameters +---------- + +``Object`` - a valid provider with at least ``send``, ``on`` function + +------- +Returns +------- + +``undefined`` + +------- +Example +------- + +.. code-block:: javascript + + web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); + + +------------------------------------------------------------------------------ diff --git a/docs/web3-utils.rst b/docs/web3-utils.rst new file mode 100644 index 0000000..2366fa4 --- /dev/null +++ b/docs/web3-utils.rst @@ -0,0 +1,40 @@ +======== +web3.utils +======== + +This package provides utility functions for ethereum dapps and other web3.js packages. + + +------------------------------------------------------------------------------ + +sha3 +===================== + +.. code-block:: javascript + + web3.utils.sha3(myProvider) + +When called changes the current provider for all modules. + +---------- +Parameters +---------- + +``Object`` - a valid provider with at least ``send``, ``on`` function + +------- +Returns +------- + +``undefined`` + +------- +Example +------- + +.. code-block:: javascript + + web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); + + +------------------------------------------------------------------------------ diff --git a/lib/web3/contract.js b/lib/web3/contract.js index 151011f..673a6d4 100644 --- a/lib/web3/contract.js +++ b/lib/web3/contract.js @@ -83,11 +83,12 @@ var Contract = function(jsonInterface, address, options) { Object.defineProperty(this, 'jsonInterface', { set: function(value){ _this._jsonInterface = value.map(function(method) { + var func; // constructor if (method.type === 'constructor') { method.signature = 'constructor'; - var func = _this._createTxObject.bind({ + func = _this._createTxObject.bind({ method: method, parent: _this }); @@ -99,7 +100,7 @@ var Contract = function(jsonInterface, address, options) { // function } else if (method.type === 'function') { method.signature = '0x'+ sha3(utils.transformToFullName(method)).slice(0, 8); - var func = _this._createTxObject.bind({ + func = _this._createTxObject.bind({ method: method, parent: _this }); @@ -163,10 +164,9 @@ Contract.prototype._web3 = {}; // web3 is attached here in eth.js * @method _checkListener * @param {String} type * @param {String} event - * @param {Function} func * @return {Object} the contract instance */ -Contract.prototype._checkListener = function(type, event, func){ +Contract.prototype._checkListener = function(type, event){ if(event === type) { throw new Error('The event "'+ type +'" is a reserved event name, you can\'t use it.'); } @@ -347,7 +347,7 @@ Contract.prototype._encodeMethodABI = function _encodeMethodABI(methodSignature, var returnValue = (signature) ? signature + paramsABI : paramsABI; if(!returnValue) - throw new Error('Couldn\'t find a matching contract method named "'+ this._method.name +'".') + throw new Error('Couldn\'t find a matching contract method named "'+ this._method.name +'".'); else return returnValue; } @@ -630,7 +630,7 @@ Contract.prototype.once = function(event, options, callback) { * @return {Object} the event subscription */ Contract.prototype.on = function(event, options, callback){ - var subOptions = this._generateEventOptions.apply(this, arguments); + var subOptions = this._generateEventOptions.apply(this, [event, options, callback]); // prevent the event "newListener" and "removeListener" from being overwritten @@ -665,7 +665,7 @@ Contract.prototype.on = function(event, options, callback){ * @return {Object} the promievent */ Contract.prototype.getPastEvents = function(event, options, callback){ - var subOptions = this._generateEventOptions.apply(this, arguments); + var subOptions = this._generateEventOptions.apply(this, [event, options, callback]); var getPastLogs = new Method({ name: 'getPastLogs', @@ -690,8 +690,7 @@ Contract.prototype.getPastEvents = function(event, options, callback){ * @returns {Object} an object with functions to call the methods */ Contract.prototype._createTxObject = function _createTxObject(){ - var _this = this, - txObject = {}; + var txObject = {}; if(this.method.type === 'function') { @@ -740,12 +739,10 @@ Contract.prototype._executeMethod = function _executeMethod(type){ } // get the options - options = (utils.isObject(args[args.length - 1])) - ? args.pop() - : {}; + options = (utils.isObject(args[args.length - 1])) ? args.pop() : {}; // get the makeRequest argument - makeRequest = (args[args.length - 1] === true)? args.pop() : false; + var makeRequest = (args[args.length - 1] === true)? args.pop() : false; options.from = options.from || this._parent.options.from; diff --git a/lib/web3/method.js b/lib/web3/method.js index 0baed53..e11d1fc 100644 --- a/lib/web3/method.js +++ b/lib/web3/method.js @@ -24,7 +24,7 @@ var utils = require('../utils/utils'); var errors = require('./errors'); var eventifiedPromise = require('./eventifiedPromise.js'); -var Method = function (options, parent) { +var Method = function (options) { this.name = options.name; this.call = options.call; this.params = options.params || 0; @@ -151,7 +151,7 @@ Method.prototype.buildCall = function() { method.requestManager.send(payload, function (err, result) { - var result = method.formatOutput(result); + result = method.formatOutput(result); // TODO? if afterProcess is available // if(method.afterProcessor) diff --git a/lib/web3/requestmanager.js b/lib/web3/requestmanager.js index e200f87..87ad4fe 100644 --- a/lib/web3/requestmanager.js +++ b/lib/web3/requestmanager.js @@ -78,7 +78,7 @@ RequestManager.prototype.send = function (data, callback) { var payload = Jsonrpc.toPayload(data.method, data.params); this.provider.send(payload, function (err, result) { - if(payload.id !== result.id) return callback(new Error('Wrong response id "'+ result.id +'" (expected: "'+ payload.id +'") in '+ JSON.stringify(payload)));; + if(payload.id !== result.id) return callback(new Error('Wrong response id "'+ result.id +'" (expected: "'+ payload.id +'") in '+ JSON.stringify(payload))); if (err) { return callback(err); diff --git a/lib/web3/subscription.js b/lib/web3/subscription.js index 23e08d2..9acb309 100644 --- a/lib/web3/subscription.js +++ b/lib/web3/subscription.js @@ -232,7 +232,6 @@ Subscription.prototype.subscribe = function() { // re-subscribe, if connection fails if(_this.options.requestManager.provider.once) { _this._reconnectIntervalId = setInterval(function () { - console.log('reconnect') _this.options.requestManager.provider.reconnect(); }, 500); diff --git a/lib/web3/subscriptions.js b/lib/web3/subscriptions.js index e6c89d2..046c420 100644 --- a/lib/web3/subscriptions.js +++ b/lib/web3/subscriptions.js @@ -46,7 +46,7 @@ Subscriptions.prototype.attachToObject = function (obj) { obj[name[0]] = obj[name[0]] || {}; obj[name[0]][name[1]] = func; } else { - obj[name[0]] = func; + obj[name[0]] = func; } }; @@ -67,4 +67,3 @@ Subscriptions.prototype.buildCall = function() { }; module.exports = Subscriptions; -