lint improvments

This commit is contained in:
Fabian Vogelsteller 2016-11-02 15:51:52 +01:00
parent 72859abf7e
commit 58234e5496
No known key found for this signature in database
GPG Key ID: E51EADA77F1A4124
7 changed files with 84 additions and 22 deletions

View File

@ -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'));
------------------------------------------------------------------------------

40
docs/web3-utils.rst Normal file
View File

@ -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'));
------------------------------------------------------------------------------

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -67,4 +67,3 @@ Subscriptions.prototype.buildCall = function() {
};
module.exports = Subscriptions;