web3
Advanced tools
Comparing version 0.19.1 to 0.20.0
{ | ||
"version": "0.19.1" | ||
"version": "0.20.0" | ||
} |
@@ -17,3 +17,3 @@ /* | ||
*/ | ||
/** | ||
/** | ||
* @file allevents.js | ||
@@ -80,3 +80,3 @@ * @author Marek Kotewicz <marek@ethdev.com> | ||
var formatter = this.decode.bind(this); | ||
return new Filter(this._requestManager, o, watches.eth(), formatter, callback); | ||
return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); | ||
}; | ||
@@ -83,0 +83,0 @@ |
@@ -17,3 +17,3 @@ /* | ||
*/ | ||
/** | ||
/** | ||
* @file event.js | ||
@@ -89,3 +89,3 @@ * @author Marek Kotewicz <marek@ethdev.com> | ||
* Should be used to encode indexed params and options to one final object | ||
* | ||
* | ||
* @method encode | ||
@@ -121,3 +121,3 @@ * @param {Object} indexed | ||
} | ||
if (utils.isArray(value)) { | ||
@@ -144,3 +144,3 @@ return value.map(function (v) { | ||
SolidityEvent.prototype.decode = function (data) { | ||
data.data = data.data || ''; | ||
@@ -151,7 +151,7 @@ data.topics = data.topics || []; | ||
var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); | ||
var indexedParams = coder.decodeParams(this.types(true), indexedData); | ||
var indexedParams = coder.decodeParams(this.types(true), indexedData); | ||
var notIndexedData = data.data.slice(2); | ||
var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); | ||
var result = formatters.outputLogFormatter(data); | ||
@@ -191,6 +191,6 @@ result.event = this.displayName(); | ||
} | ||
var o = this.encode(indexed, options); | ||
var formatter = this.decode.bind(this); | ||
return new Filter(this._requestManager, o, watches.eth(), formatter, callback); | ||
return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); | ||
}; | ||
@@ -197,0 +197,0 @@ |
@@ -52,3 +52,4 @@ /* | ||
/// @returns options string or object | ||
var getOptions = function (options) { | ||
var getOptions = function (options, type) { | ||
/*jshint maxcomplexity: 6 */ | ||
@@ -61,16 +62,23 @@ if (utils.isString(options)) { | ||
// make sure topics, get converted to hex | ||
options.topics = options.topics || []; | ||
options.topics = options.topics.map(function(topic){ | ||
return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); | ||
}); | ||
return { | ||
topics: options.topics, | ||
from: options.from, | ||
to: options.to, | ||
address: options.address, | ||
fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), | ||
toBlock: formatters.inputBlockNumberFormatter(options.toBlock) | ||
}; | ||
switch(type) { | ||
case 'eth': | ||
// make sure topics, get converted to hex | ||
options.topics = options.topics || []; | ||
options.topics = options.topics.map(function(topic){ | ||
return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); | ||
}); | ||
return { | ||
topics: options.topics, | ||
from: options.from, | ||
to: options.to, | ||
address: options.address, | ||
fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), | ||
toBlock: formatters.inputBlockNumberFormatter(options.toBlock) | ||
}; | ||
case 'shh': | ||
return options; | ||
} | ||
}; | ||
@@ -83,3 +91,3 @@ | ||
@param {Object} self | ||
@param {funciton} | ||
@param {function} callback | ||
*/ | ||
@@ -136,3 +144,3 @@ var getLogsAtStart = function(self, callback){ | ||
var Filter = function (requestManager, options, methods, formatter, callback, filterCreationErrorCallback) { | ||
var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { | ||
var self = this; | ||
@@ -145,3 +153,3 @@ var implementation = {}; | ||
this.requestManager = requestManager; | ||
this.options = getOptions(options); | ||
this.options = getOptions(options, type); | ||
this.implementation = implementation; | ||
@@ -148,0 +156,0 @@ this.filterId = null; |
@@ -0,1 +1,3 @@ | ||
'use strict' | ||
/* | ||
@@ -193,7 +195,7 @@ This file is part of web3.js. | ||
var outputLogFormatter = function(log) { | ||
if(log.blockNumber !== null) | ||
if(log.blockNumber) | ||
log.blockNumber = utils.toDecimal(log.blockNumber); | ||
if(log.transactionIndex !== null) | ||
if(log.transactionIndex) | ||
log.transactionIndex = utils.toDecimal(log.transactionIndex); | ||
if(log.logIndex !== null) | ||
if(log.logIndex) | ||
log.logIndex = utils.toDecimal(log.logIndex); | ||
@@ -277,2 +279,5 @@ | ||
var outputSyncingFormatter = function(result) { | ||
if (!result) { | ||
return result; | ||
} | ||
@@ -279,0 +284,0 @@ result.startingBlock = utils.toDecimal(result.startingBlock); |
@@ -68,3 +68,6 @@ /* | ||
// filter the options object but not arguments that are arrays | ||
return !(utils.isObject(a) === true && utils.isArray(a) === false); | ||
return !( (utils.isObject(a) === true) && | ||
(utils.isArray(a) === false) && | ||
(utils.isBigNumber(a) === false) | ||
); | ||
}); | ||
@@ -71,0 +74,0 @@ if (inputArgs.length !== this._inputTypes.length) { |
@@ -25,5 +25,4 @@ /* | ||
var errors = require('./errors') | ||
var errors = require('./errors'); | ||
// workaround to use httpprovider in different envs | ||
@@ -33,9 +32,9 @@ | ||
if (typeof window !== 'undefined' && window.XMLHttpRequest) { | ||
XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line | ||
XMLHttpRequest = window.XMLHttpRequest // jshint ignore: line | ||
// node | ||
} else { | ||
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line | ||
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest // jshint ignore: line | ||
} | ||
var XHR2 = require('xhr2'); // jshint ignore: line | ||
var XHR2 = require('xhr2') // jshint ignore: line | ||
@@ -45,5 +44,7 @@ /** | ||
*/ | ||
var HttpProvider = function (host, timeout) { | ||
this.host = host || 'http://localhost:8545'; | ||
this.timeout = timeout || 0; | ||
var HttpProvider = function (host, timeout, user, password) { | ||
this.host = host || 'http://localhost:8545'; | ||
this.timeout = timeout || 0; | ||
this.user = user; | ||
this.password = password; | ||
}; | ||
@@ -59,14 +60,14 @@ | ||
HttpProvider.prototype.prepareRequest = function (async) { | ||
var request; | ||
var request; | ||
if (async) { | ||
request = new XHR2(); | ||
request.timeout = this.timeout; | ||
}else { | ||
request = new XMLHttpRequest(); | ||
} | ||
if (async) { | ||
request = new XHR2(); | ||
request.timeout = this.timeout; | ||
} else { | ||
request = new XMLHttpRequest(); | ||
} | ||
request.open('POST', this.host, async); | ||
request.setRequestHeader('Content-Type','application/json'); | ||
return request; | ||
request.open('POST', this.host, async, this.user, this.password); | ||
request.setRequestHeader('Content-Type', 'application/json'); | ||
return request; | ||
}; | ||
@@ -82,19 +83,19 @@ | ||
HttpProvider.prototype.send = function (payload) { | ||
var request = this.prepareRequest(false); | ||
var request = this.prepareRequest(false); | ||
try { | ||
request.send(JSON.stringify(payload)); | ||
} catch(error) { | ||
throw errors.InvalidConnection(this.host); | ||
} | ||
try { | ||
request.send(JSON.stringify(payload)); | ||
} catch (error) { | ||
throw errors.InvalidConnection(this.host); | ||
} | ||
var result = request.responseText; | ||
var result = request.responseText; | ||
try { | ||
result = JSON.parse(result); | ||
} catch(e) { | ||
throw errors.InvalidResponse(request.responseText); | ||
} | ||
try { | ||
result = JSON.parse(result); | ||
} catch (e) { | ||
throw errors.InvalidResponse(request.responseText); | ||
} | ||
return result; | ||
return result; | ||
}; | ||
@@ -110,28 +111,28 @@ | ||
HttpProvider.prototype.sendAsync = function (payload, callback) { | ||
var request = this.prepareRequest(true); | ||
var request = this.prepareRequest(true); | ||
request.onreadystatechange = function() { | ||
if (request.readyState === 4 && request.timeout !== 1) { | ||
var result = request.responseText; | ||
var error = null; | ||
request.onreadystatechange = function () { | ||
if (request.readyState === 4 && request.timeout !== 1) { | ||
var result = request.responseText; | ||
var error = null; | ||
try { | ||
result = JSON.parse(result); | ||
} catch(e) { | ||
error = errors.InvalidResponse(request.responseText); | ||
} | ||
try { | ||
result = JSON.parse(result); | ||
} catch (e) { | ||
error = errors.InvalidResponse(request.responseText); | ||
} | ||
callback(error, result); | ||
} | ||
}; | ||
callback(error, result); | ||
} | ||
}; | ||
request.ontimeout = function() { | ||
callback(errors.ConnectionTimeout(this.timeout)); | ||
}; | ||
request.ontimeout = function () { | ||
callback(errors.ConnectionTimeout(this.timeout)); | ||
}; | ||
try { | ||
request.send(JSON.stringify(payload)); | ||
} catch(error) { | ||
callback(errors.InvalidConnection(this.host)); | ||
} | ||
try { | ||
request.send(JSON.stringify(payload)); | ||
} catch (error) { | ||
callback(errors.InvalidConnection(this.host)); | ||
} | ||
}; | ||
@@ -145,16 +146,16 @@ | ||
*/ | ||
HttpProvider.prototype.isConnected = function() { | ||
try { | ||
this.send({ | ||
id: 9999999999, | ||
jsonrpc: '2.0', | ||
method: 'net_listening', | ||
params: [] | ||
}); | ||
return true; | ||
} catch(e) { | ||
return false; | ||
} | ||
HttpProvider.prototype.isConnected = function () { | ||
try { | ||
this.send({ | ||
id: 9999999999, | ||
jsonrpc: '2.0', | ||
method: 'net_listening', | ||
params: [] | ||
}); | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
}; | ||
module.exports = HttpProvider; |
@@ -338,4 +338,4 @@ /* | ||
Eth.prototype.filter = function (fil, callback, filterCreationErrorCallback) { | ||
return new Filter(this._requestManager, fil, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); | ||
Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { | ||
return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); | ||
}; | ||
@@ -342,0 +342,0 @@ |
@@ -19,8 +19,8 @@ /* | ||
* @authors: | ||
* Marek Kotewicz <marek@ethdev.com> | ||
* @date 2015 | ||
* Fabian Vogelsteller <fabian@ethereum.org> | ||
* Marek Kotewicz <marek@ethcore.io> | ||
* @date 2017 | ||
*/ | ||
var Method = require('../method'); | ||
var formatters = require('../formatters'); | ||
var Filter = require('../filter'); | ||
@@ -34,3 +34,3 @@ var watches = require('./watches'); | ||
methods().forEach(function(method) { | ||
methods().forEach(function(method) { | ||
method.attachToObject(self); | ||
@@ -41,45 +41,103 @@ method.setRequestManager(self._requestManager); | ||
Shh.prototype.filter = function (fil, callback) { | ||
return new Filter(this._requestManager, fil, watches.shh(), formatters.outputPostFormatter, callback); | ||
Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { | ||
return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); | ||
}; | ||
var methods = function () { | ||
var methods = function () { | ||
var post = new Method({ | ||
name: 'post', | ||
call: 'shh_post', | ||
params: 1, | ||
inputFormatter: [formatters.inputPostFormatter] | ||
}); | ||
return [ | ||
new Method({ | ||
name: 'version', | ||
call: 'shh_version', | ||
params: 0 | ||
}), | ||
new Method({ | ||
name: 'info', | ||
call: 'shh_info', | ||
params: 0 | ||
}), | ||
new Method({ | ||
name: 'setMaxMessageSize', | ||
call: 'shh_setMaxMessageSize', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'setMinPoW', | ||
call: 'shh_setMinPoW', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'markTrustedPeer', | ||
call: 'shh_markTrustedPeer', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'newKeyPair', | ||
call: 'shh_newKeyPair', | ||
params: 0 | ||
}), | ||
new Method({ | ||
name: 'addPrivateKey', | ||
call: 'shh_addPrivateKey', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'deleteKeyPair', | ||
call: 'shh_deleteKeyPair', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'hasKeyPair', | ||
call: 'shh_hasKeyPair', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'getPublicKey', | ||
call: 'shh_getPublicKey', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'getPrivateKey', | ||
call: 'shh_getPrivateKey', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'newSymKey', | ||
call: 'shh_newSymKey', | ||
params: 0 | ||
}), | ||
new Method({ | ||
name: 'addSymKey', | ||
call: 'shh_addSymKey', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'generateSymKeyFromPassword', | ||
call: 'shh_generateSymKeyFromPassword', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'hasSymKey', | ||
call: 'shh_hasSymKey', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'getSymKey', | ||
call: 'shh_getSymKey', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'deleteSymKey', | ||
call: 'shh_deleteSymKey', | ||
params: 1 | ||
}), | ||
var newIdentity = new Method({ | ||
name: 'newIdentity', | ||
call: 'shh_newIdentity', | ||
params: 0 | ||
}); | ||
// subscribe and unsubscribe missing | ||
var hasIdentity = new Method({ | ||
name: 'hasIdentity', | ||
call: 'shh_hasIdentity', | ||
params: 1 | ||
}); | ||
var newGroup = new Method({ | ||
name: 'newGroup', | ||
call: 'shh_newGroup', | ||
params: 0 | ||
}); | ||
var addToGroup = new Method({ | ||
name: 'addToGroup', | ||
call: 'shh_addToGroup', | ||
params: 0 | ||
}); | ||
return [ | ||
post, | ||
newIdentity, | ||
hasIdentity, | ||
newGroup, | ||
addToGroup | ||
new Method({ | ||
name: 'post', | ||
call: 'shh_post', | ||
params: 1, | ||
inputFormatter: [null] | ||
}) | ||
]; | ||
@@ -86,0 +144,0 @@ }; |
@@ -78,31 +78,24 @@ /* | ||
var shh = function () { | ||
var newFilter = new Method({ | ||
name: 'newFilter', | ||
call: 'shh_newFilter', | ||
params: 1 | ||
}); | ||
var uninstallFilter = new Method({ | ||
name: 'uninstallFilter', | ||
call: 'shh_uninstallFilter', | ||
params: 1 | ||
}); | ||
var getLogs = new Method({ | ||
name: 'getLogs', | ||
call: 'shh_getMessages', | ||
params: 1 | ||
}); | ||
var poll = new Method({ | ||
name: 'poll', | ||
call: 'shh_getFilterChanges', | ||
params: 1 | ||
}); | ||
return [ | ||
newFilter, | ||
uninstallFilter, | ||
getLogs, | ||
poll | ||
new Method({ | ||
name: 'newFilter', | ||
call: 'shh_newMessageFilter', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'uninstallFilter', | ||
call: 'shh_deleteMessageFilter', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'getLogs', | ||
call: 'shh_getFilterMessages', | ||
params: 1 | ||
}), | ||
new Method({ | ||
name: 'poll', | ||
call: 'shh_getFilterMessages', | ||
params: 1 | ||
}) | ||
]; | ||
@@ -109,0 +102,0 @@ }; |
/* jshint ignore:start */ | ||
Package.describe({ | ||
name: 'ethereum:web3', | ||
version: '0.19.1', | ||
version: '0.20.0', | ||
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC', | ||
@@ -6,0 +6,0 @@ git: 'https://github.com/ethereum/ethereum.js', |
{ | ||
"name": "web3", | ||
"namespace": "ethereum", | ||
"version": "0.19.1", | ||
"version": "0.20.0", | ||
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC", | ||
@@ -11,3 +11,3 @@ "main": "./index.js", | ||
"dependencies": { | ||
"bignumber.js": "^4.0.2", | ||
"bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git", | ||
"crypto-js": "^3.1.4", | ||
@@ -14,0 +14,0 @@ "utf8": "^2.1.1", |
@@ -118,3 +118,3 @@ # Migration 0.13.0 -> 0.14.0 | ||
[waffle-image]: https://badge.waffle.io/ethereum/web3.js.svg?label=ready&title=Ready | ||
[waffle-url]: http://waffle.io/ethereum/web3.js | ||
[waffle-url]: https://waffle.io/ethereum/web3.js | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
20320550
134
235892
17
1
118
74
- Removedbignumber.js@4.1.0(transitive)
Updatedbignumber.js@git+https://github.com/frozeman/bignumber.js-nolookahead.git