Skip to content

Commit

Permalink
Merge branch '1.0' into fix/repeat-confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
frozeman authored Mar 13, 2018
2 parents 092e646 + 54daf21 commit b5e5099
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 30 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/web3-eth-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

-------
Expand Down
6 changes: 3 additions & 3 deletions docs/web3-shh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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,
Expand Down Expand Up @@ -848,7 +848,7 @@ Example
web3.shh.subscribe('messages', {
symKeyID: 'bf31b9ffc2387e18636e0a3d0c56b023264c16e78a2adcba1303cefc685e610f',
sig: '0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6'
sig: '0x04d1574d4eab8f3dde4d2dc7ed2c4d699d77cbbdd09167b8fffa099652ce4df00c4c6e0263eafe05007a46fdf0c8d32b11aeabcd3abbc7b2bc2bb967368a68e9c6',
ttl: 20,
topics: ['0xffddaa11'],
minPow: 0.8,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 17 additions & 6 deletions packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
});

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

Expand Down
35 changes: 20 additions & 15 deletions packages/web3-core-subscriptions/src/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-eth-contract/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/web3/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/abi.decodeParameter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ describe('typical usage', function() {
// done();
// });

}).timeout(4000);
}).timeout(6000);
// TODO add error check
});

Expand Down
136 changes: 136 additions & 0 deletions test/eth.subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b5e5099

Please sign in to comment.