diff --git a/README.md b/README.md index 7026ef34151..9130566c389 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ npm test - Haskell [hs-web3](https://github.com/airalab/hs-web3) - Haskell [hs-web3](https://github.com/airalab/hs-web3) - Java [web3j](https://github.com/web3j/web3j) - Java [web3j](https://github.com/web3j/web3j) - Scala [web3j-scala](https://github.com/mslinn/web3j-scala) + - Purescript [purescript-web3](https://github.com/f-o-a-m/purescript-web3) + - PHP [web3.php](https://github.com/sc0Vu/web3.php) [repo]: https://github.com/ethereum/web3.js diff --git a/docs/web3-eth-contract.rst b/docs/web3-eth-contract.rst index 30cafedc233..bee19405a80 100644 --- a/docs/web3-eth-contract.rst +++ b/docs/web3-eth-contract.rst @@ -637,6 +637,7 @@ Parameters 1. ``options`` - ``Object`` (optional): The options used for calling. * ``from`` - ``String`` (optional): The address the call "transaction" should be made from. * ``gas`` - ``Number`` (optional): The maximum gas provided for this call "transaction" (gas limit). Setting a specific value helps to detect out of gas errors. If all gas is used it will return the same number. + * ``value`` - ``Number|String|BN|BigNumber``(optional): The value transferred for the call "transaction" in wei. 2. ``callback`` - ``Function`` (optional): This callback will be fired with the result of the gas estimation as the second argument, or with an error object as the first argument. ------- diff --git a/docs/web3-shh.rst b/docs/web3-shh.rst index 4b80b7fc493..6c6cef00c54 100644 --- a/docs/web3-shh.rst +++ b/docs/web3-shh.rst @@ -769,7 +769,7 @@ Example web3.shh.newSymKey().then((id) => {identities.push(id);}), web3.shh.newKeyPair().then((id) => {identities.push(id);}) - }).then(() => { + ]).then(() => { // will receive also its own message send, below subscription = shh.subscribe("messages", { @@ -778,7 +778,7 @@ Example }).on('data', console.log); }).then(() => { - shh.post({ + web3.shh.post({ symKeyID: identities[0], // encrypts using the sym key ID sig: identities[1], // signs the message using the keyPair ID ttl: 10, @@ -848,7 +848,7 @@ Example web3.shh.subscribe('messages', { symKeyID: 'bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f', - sig: '0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6' + sig: '0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6', ttl: 20, topics: ['0xffddaa11'], minPow: 0.8, diff --git a/package.json b/package.json index c9a57fd6753..e6e602934e9 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "version": "1.0.0-beta.30", "description": "Ethereum JavaScript API wrapper repository", "license": "LGPL-3.0", + "main": "./packages/web3/src/index.js", "directories": { "doc": "./doc", "test": "./test" diff --git a/packages/web3-core-method/src/index.js b/packages/web3-core-method/src/index.js index d2c88c39f8b..353ec31c839 100644 --- a/packages/web3-core-method/src/index.js +++ b/packages/web3-core-method/src/index.js @@ -31,6 +31,7 @@ var promiEvent = require('web3-core-promievent'); var Subscriptions = require('web3-core-subscriptions').subscriptions; var TIMEOUTBLOCK = 50; +var POLLINGTIMEOUT = 15 * TIMEOUTBLOCK; // ~average block time (seconds) * TIMEOUTBLOCK var CONFIRMATIONBLOCKS = 24; var Method = function Method(options) { @@ -240,7 +241,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { // fire "receipt" and confirmation events and resolve after - var checkConfirmation = function (existingReceipt, err, blockHeader, sub) { + var checkConfirmation = function (existingReceipt, err, blockHeader, sub, isPolling) { if (!err) { // create fake unsubscribe if (!sub) { @@ -373,10 +374,20 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { .catch(function () { timeoutCount++; - if (timeoutCount - 1 >= TIMEOUTBLOCK) { - sub.unsubscribe(); - promiseResolved = true; - return utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject); + // check to see if we are http polling + if(!!isPolling) { + // polling timeout is different than TIMEOUTBLOCK blocks since we are triggering every second + if (timeoutCount - 1 >= POLLINGTIMEOUT) { + sub.unsubscribe(); + promiseResolved = true; + return utils._fireError(new Error('Transaction was not mined within' + POLLINGTIMEOUT + ' seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject); + } + } else { + if (timeoutCount - 1 >= TIMEOUTBLOCK) { + sub.unsubscribe(); + promiseResolved = true; + return utils._fireError(new Error('Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!'), defer.eventEmitter, defer.reject); + } } }); @@ -394,7 +405,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) { if (_.isFunction(this.requestManager.provider.on)) { _ethereumCall.subscribe('newBlockHeaders', checkConfirmation.bind(null, existingReceipt)); } else { - intervalId = setInterval(checkConfirmation.bind(null, existingReceipt), 1000); + intervalId = setInterval(checkConfirmation.bind(null, existingReceipt, null, null, null, true), 1000); } }.bind(this); diff --git a/packages/web3-core-subscriptions/src/subscription.js b/packages/web3-core-subscriptions/src/subscription.js index 8f51fe260b4..ae2db930728 100644 --- a/packages/web3-core-subscriptions/src/subscription.js +++ b/packages/web3-core-subscriptions/src/subscription.js @@ -254,20 +254,25 @@ Subscription.prototype.subscribe = function() { // call callback on notifications _this.options.requestManager.addSubscription(_this.id, payload.params[0] , _this.options.type, function(err, result) { - // TODO remove once its fixed in geth - if(_.isArray(result)) - result = result[0]; - - var output = _this._formatOutput(result); - if (!err) { - - if(_.isFunction(_this.options.subscription.subscriptionHandler)) { - return _this.options.subscription.subscriptionHandler.call(_this, output); - } else { - _this.emit('data', output); + if (!_.isArray(result)) { + result = [result]; } + result.forEach(function(resultItem) { + var output = _this._formatOutput(resultItem); + + if (_.isFunction(_this.options.subscription.subscriptionHandler)) { + return _this.options.subscription.subscriptionHandler.call(_this, output); + } else { + _this.emit('data', output); + } + + // call the callback, last so that unsubscribe there won't affect the emit above + if (_.isFunction(_this.callback)) { + _this.callback(null, output, _this); + } + }); } else { // unsubscribe, but keep listeners _this.options.requestManager.removeSubscription(_this.id); @@ -287,11 +292,11 @@ Subscription.prototype.subscribe = function() { }); } _this.emit('error', err); - } - // call the callback, last so that unsubscribe there won't affect the emit above - if (_.isFunction(_this.callback)) { - _this.callback(err, output, _this); + // call the callback, last so that unsubscribe there won't affect the emit above + if (_.isFunction(_this.callback)) { + _this.callback(err, null, _this); + } } }); } else if (_.isFunction(_this.callback)) { diff --git a/packages/web3-eth-contract/src/index.js b/packages/web3-eth-contract/src/index.js index 12c86b85f63..952755246b6 100644 --- a/packages/web3-eth-contract/src/index.js +++ b/packages/web3-eth-contract/src/index.js @@ -765,11 +765,12 @@ Contract.prototype._executeMethod = function _executeMethod(){ if(args.generateRequest) { var payload = { - params: [formatters.inputCallFormatter.call(this._parent, args.options), formatters.inputDefaultBlockNumberFormatter.call(this._parent, args.defaultBlock)], + params: [formatters.inputCallFormatter.call(this._parent, args.options)], callback: args.callback }; if(args.type === 'call') { + payload.params.push(formatters.inputDefaultBlockNumberFormatter.call(this._parent, args.defaultBlock)); payload.method = 'eth_call'; payload.format = this._parent._decodeMethodReturn.bind(null, this._method.outputs); } else { diff --git a/packages/web3/README.md b/packages/web3/README.md index 1a1be9c7ed1..885d2679367 100644 --- a/packages/web3/README.md +++ b/packages/web3/README.md @@ -1,8 +1,8 @@ # web3 -This is a main package of [web3.js][repo] +This is a main package of [web3.js](https://github.com/ethereum/web3.js) -Please read the [documentation][docs] for more. +Please read the main [readme](https://github.com/ethereum/web3.js/blob/1.0/README.md) and [documentation](https://web3js.readthedocs.io/en/1.0/) for more. ## Installation diff --git a/test/abi.decodeParameter.js b/test/abi.decodeParameter.js index c25dc0b0f27..e01209d9f6c 100644 --- a/test/abi.decodeParameter.js +++ b/test/abi.decodeParameter.js @@ -170,7 +170,7 @@ describe('lib/solidity/coder', function () { '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'}); test({ type: 'bytes[][2]', expected: [['0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134a'], ['0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' + - '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134c', + '731b3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134c', '0x731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134d']], value: '0000000000000000000000000000000000000000000000000000000000000040' + '0000000000000000000000000000000000000000000000000000000000000080' + @@ -187,7 +187,7 @@ describe('lib/solidity/coder', function () { '0000000000000000000000000000000000000000000000000000000000000040' + // 120 // '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b' + - '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134c' + + '731b3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134c' + '0000000000000000000000000000000000000000000000000000000000000020' + // 180 // '731a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134d'}); diff --git a/test/contract.js b/test/contract.js index d0fee896d6d..4f6c9c37764 100644 --- a/test/contract.js +++ b/test/contract.js @@ -3004,7 +3004,7 @@ describe('typical usage', function() { // done(); // }); - }).timeout(4000); + }).timeout(6000); // TODO add error check }); diff --git a/test/eth.subscribe.js b/test/eth.subscribe.js index d2d5edf7408..4f2db3b1308 100644 --- a/test/eth.subscribe.js +++ b/test/eth.subscribe.js @@ -162,6 +162,142 @@ var tests = [{ data: '0x0000000000000000000000000000000000000000000000000000000000000001' + '0000000000000000000000000000000000000000000000000000000000000008' }] +}, + { + protocol: 'eth', + args: ['logs',{address: ['0xDdf4d0A3c12e86b4B5f39B213f7E19d048276dAE','0xAaf4D0a3C12e86B4B5f39b213f7E19d048276daE']}], + firstResult: '0x4444', + firstPayload: { + method: "eth_subscribe", + params: ['logs',{address: ['0xddf4d0a3c12e86b4b5f39b213f7e19d048276dae','0xaaf4d0a3c12e86b4b5f39b213f7e19d048276dae'], topics: []}] + }, + secondResult: true, + secondPayload: { + method: "eth_unsubscribe" + }, + subscriptions: [{ + subscription: '0x4444', + result: [{ + logIndex: '0x23', + transactionHash: '0x2345fdfdf', + blockHash: '0x43534ffddd', + transactionIndex: '0x1', + blockNumber: '0x3222', + address: '0xddf4d0a3c12e86b4b5f39b213f7e19d048276dae', + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + },{ + logIndex: '0x23', + transactionHash: '0x2345fdfdd', + blockHash: '0x43534ffddd', + transactionIndex: '0x1', + blockNumber: '0x3222', + address: '0xddf4d0a3c12e86b4b5f39b213f7e19d048276dae', + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + }] + }], + subscriptionResults: [{ + id: "log_d43624aa", + blockHash: "0x43534ffddd", + blockNumber: 12834, + logIndex: 35, + transactionHash: '0x2345fdfdf', + transactionIndex: 1, + address: '0xDdf4d0A3c12e86b4B5f39B213f7E19d048276dAE', // checksum address + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + },{ + id: "log_b20551f9", + blockHash: "0x43534ffddd", + blockNumber: 12834, + logIndex: 35, + transactionHash: '0x2345fdfdd', + transactionIndex: 1, + address: '0xDdf4d0A3c12e86b4B5f39B213f7E19d048276dAE', // checksum address + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + }] + }, +{ + protocol: 'eth', + args: ['logs',{address: ['0xDdf4d0A3c12e86b4B5f39B213f7E19d048276dAE','0xAaf4D0a3C12e86B4B5f39b213f7E19d048276daE']}], + firstResult: '0x4444', + firstPayload: { + method: "eth_subscribe", + params: ['logs',{address: ['0xddf4d0a3c12e86b4b5f39b213f7e19d048276dae','0xaaf4d0a3c12e86b4b5f39b213f7e19d048276dae'], topics: []}] + }, + secondResult: true, + secondPayload: { + method: "eth_unsubscribe" + }, + subscriptions: [{ + subscription: '0x4444', + result: [{ + logIndex: '0x23', + transactionHash: '0x2345fdfdf', + blockHash: '0x43534ffddd', + transactionIndex: '0x1', + blockNumber: '0x3222', + address: '0xddf4d0a3c12e86b4b5f39b213f7e19d048276dae', + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + },{ + logIndex: '0x23', + transactionHash: '0x2345fdfdd', + blockHash: '0x43534ffddd', + transactionIndex: '0x1', + blockNumber: '0x3222', + address: '0xddf4d0a3c12e86b4b5f39b213f7e19d048276dae', + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + }] + }], + subscriptionResults: [{ + id: "log_d43624aa", + blockHash: "0x43534ffddd", + blockNumber: 12834, + logIndex: 35, + transactionHash: '0x2345fdfdf', + transactionIndex: 1, + address: '0xDdf4d0A3c12e86b4B5f39B213f7E19d048276dAE', // checksum address + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + },{ + id: "log_b20551f9", + blockHash: "0x43534ffddd", + blockNumber: 12834, + logIndex: 35, + transactionHash: '0x2345fdfdd', + transactionIndex: 1, + address: '0xDdf4d0A3c12e86b4B5f39B213f7E19d048276dAE', // checksum address + topics: [ + '0x0000000000000000000000000000000000000000000000000000000005656565' + ], + data: '0x0000000000000000000000000000000000000000000000000000000000000001' + + '0000000000000000000000000000000000000000000000000000000000000008' + }] }, { protocol: 'eth',