mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
initial support for batch requests
This commit is contained in:
parent
a0b9cfb1e7
commit
863607750f
141
dist/web3-light.js
vendored
141
dist/web3-light.js
vendored
@ -1318,6 +1318,7 @@ var RequestManager = require('./web3/requestmanager');
|
|||||||
var c = require('./utils/config');
|
var c = require('./utils/config');
|
||||||
var Method = require('./web3/method');
|
var Method = require('./web3/method');
|
||||||
var Property = require('./web3/property');
|
var Property = require('./web3/property');
|
||||||
|
var Batch = require('./web3/batch');
|
||||||
|
|
||||||
var web3Methods = [
|
var web3Methods = [
|
||||||
new Method({
|
new Method({
|
||||||
@ -1410,6 +1411,9 @@ web3.toBigNumber = utils.toBigNumber;
|
|||||||
web3.toWei = utils.toWei;
|
web3.toWei = utils.toWei;
|
||||||
web3.fromWei = utils.fromWei;
|
web3.fromWei = utils.fromWei;
|
||||||
web3.isAddress = utils.isAddress;
|
web3.isAddress = utils.isAddress;
|
||||||
|
web3.createBatch = function () {
|
||||||
|
return new Batch();
|
||||||
|
};
|
||||||
|
|
||||||
// ADD defaultblock
|
// ADD defaultblock
|
||||||
Object.defineProperty(web3.eth, 'defaultBlock', {
|
Object.defineProperty(web3.eth, 'defaultBlock', {
|
||||||
@ -1445,7 +1449,66 @@ setupMethods(web3.shh, shh.methods);
|
|||||||
module.exports = web3;
|
module.exports = web3;
|
||||||
|
|
||||||
|
|
||||||
},{"./utils/config":5,"./utils/utils":6,"./version.json":7,"./web3/db":10,"./web3/eth":12,"./web3/filter":14,"./web3/formatters":15,"./web3/method":19,"./web3/net":20,"./web3/property":21,"./web3/requestmanager":23,"./web3/shh":24,"./web3/watches":25}],9:[function(require,module,exports){
|
},{"./utils/config":5,"./utils/utils":6,"./version.json":7,"./web3/batch":9,"./web3/db":11,"./web3/eth":13,"./web3/filter":15,"./web3/formatters":16,"./web3/method":20,"./web3/net":21,"./web3/property":22,"./web3/requestmanager":24,"./web3/shh":25,"./web3/watches":26}],9:[function(require,module,exports){
|
||||||
|
/*
|
||||||
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
|
ethereum.js is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
ethereum.js is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file batch.js
|
||||||
|
* @author Marek Kotewicz <marek@ethdev.com>
|
||||||
|
* @date 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
var RequestManager = require('./requestmanager');
|
||||||
|
|
||||||
|
var Batch = function () {
|
||||||
|
this.requests = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to add create new request to batch request
|
||||||
|
*
|
||||||
|
* @method add
|
||||||
|
* @param {Object} jsonrpc requet object
|
||||||
|
*/
|
||||||
|
Batch.prototype.add = function (request) {
|
||||||
|
this.requests.push(request);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to execute batch request
|
||||||
|
*
|
||||||
|
* @method execute
|
||||||
|
*/
|
||||||
|
Batch.prototype.execute = function () {
|
||||||
|
var requests = this.requests;
|
||||||
|
RequestManager.getInstance().sendBatch(requests, function (err, results) {
|
||||||
|
results = results || [];
|
||||||
|
requests.map(function (request, index) {
|
||||||
|
return results[index] || {};
|
||||||
|
}).forEach(function (result, index) {
|
||||||
|
requests[index].callback(err, result.result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Batch;
|
||||||
|
|
||||||
|
|
||||||
|
},{"./requestmanager":24}],10:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1627,7 +1690,7 @@ var Contract = function (abi, address) {
|
|||||||
module.exports = contract;
|
module.exports = contract;
|
||||||
|
|
||||||
|
|
||||||
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./event":13,"./function":16}],10:[function(require,module,exports){
|
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./event":14,"./function":17}],11:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1685,7 +1748,7 @@ module.exports = {
|
|||||||
methods: methods
|
methods: methods
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./method":19}],11:[function(require,module,exports){
|
},{"./method":20}],12:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1725,7 +1788,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{}],12:[function(require,module,exports){
|
},{}],13:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1979,7 +2042,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./formatters":15,"./method":19,"./property":21}],13:[function(require,module,exports){
|
},{"../utils/utils":6,"./formatters":16,"./method":20,"./property":22}],14:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2175,7 +2238,7 @@ SolidityEvent.prototype.attachToContract = function (contract) {
|
|||||||
module.exports = SolidityEvent;
|
module.exports = SolidityEvent;
|
||||||
|
|
||||||
|
|
||||||
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./formatters":15}],14:[function(require,module,exports){
|
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./formatters":16}],15:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2332,7 +2395,7 @@ Filter.prototype.get = function (callback) {
|
|||||||
module.exports = Filter;
|
module.exports = Filter;
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./formatters":15,"./requestmanager":23}],15:[function(require,module,exports){
|
},{"../utils/utils":6,"./formatters":16,"./requestmanager":24}],16:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2552,7 +2615,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/config":5,"../utils/utils":6}],16:[function(require,module,exports){
|
},{"../utils/config":5,"../utils/utils":6}],17:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2740,7 +2803,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
|
|||||||
module.exports = SolidityFunction;
|
module.exports = SolidityFunction;
|
||||||
|
|
||||||
|
|
||||||
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8}],17:[function(require,module,exports){
|
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8}],18:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2832,7 +2895,7 @@ HttpProvider.prototype.sendAsync = function (payload, callback) {
|
|||||||
module.exports = HttpProvider;
|
module.exports = HttpProvider;
|
||||||
|
|
||||||
|
|
||||||
},{"./errors":11,"xmlhttprequest":4}],18:[function(require,module,exports){
|
},{"./errors":12,"xmlhttprequest":4}],19:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2925,7 +2988,7 @@ Jsonrpc.prototype.toBatchPayload = function (messages) {
|
|||||||
module.exports = Jsonrpc;
|
module.exports = Jsonrpc;
|
||||||
|
|
||||||
|
|
||||||
},{}],19:[function(require,module,exports){
|
},{}],20:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3034,6 +3097,7 @@ Method.prototype.formatOutput = function (result) {
|
|||||||
*/
|
*/
|
||||||
Method.prototype.attachToObject = function (obj) {
|
Method.prototype.attachToObject = function (obj) {
|
||||||
var func = this.send.bind(this);
|
var func = this.send.bind(this);
|
||||||
|
func.request = this.request.bind(this);
|
||||||
func.call = this.call; // that's ugly. filter.js uses it
|
func.call = this.call; // that's ugly. filter.js uses it
|
||||||
var name = this.name.split('.');
|
var name = this.name.split('.');
|
||||||
if (name.length > 1) {
|
if (name.length > 1) {
|
||||||
@ -3064,6 +3128,18 @@ Method.prototype.toPayload = function (args) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to create pure JSONRPC request which can be used in batch request
|
||||||
|
*
|
||||||
|
* @method request
|
||||||
|
* @param {...} params
|
||||||
|
* @return {Object} jsonrpc request
|
||||||
|
*/
|
||||||
|
Method.prototype.request = function () {
|
||||||
|
var payload = this.toPayload(Array.prototype.slice.call(arguments));
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should send request to the API
|
* Should send request to the API
|
||||||
*
|
*
|
||||||
@ -3085,7 +3161,7 @@ Method.prototype.send = function () {
|
|||||||
module.exports = Method;
|
module.exports = Method;
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./errors":11,"./requestmanager":23}],20:[function(require,module,exports){
|
},{"../utils/utils":6,"./errors":12,"./requestmanager":24}],21:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3135,7 +3211,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./property":21}],21:[function(require,module,exports){
|
},{"../utils/utils":6,"./property":22}],22:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3241,7 +3317,7 @@ Property.prototype.set = function (value) {
|
|||||||
module.exports = Property;
|
module.exports = Property;
|
||||||
|
|
||||||
|
|
||||||
},{"./requestmanager":23}],22:[function(require,module,exports){
|
},{"./requestmanager":24}],23:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3276,7 +3352,7 @@ QtSyncProvider.prototype.send = function (payload) {
|
|||||||
module.exports = QtSyncProvider;
|
module.exports = QtSyncProvider;
|
||||||
|
|
||||||
|
|
||||||
},{}],23:[function(require,module,exports){
|
},{}],24:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3384,6 +3460,33 @@ RequestManager.prototype.sendAsync = function (data, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to asynchronously send batch request
|
||||||
|
*
|
||||||
|
* @method sendBatch
|
||||||
|
* @param {Array} batch data
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
RequestManager.prototype.sendBatch = function (data, callback) {
|
||||||
|
if (!this.provider) {
|
||||||
|
return callback(errors.InvalidProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = Jsonrpc.getInstance().toBatchPayload(data);
|
||||||
|
|
||||||
|
this.provider.sendAsync(payload, function (err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!utils.isArray(results)) {
|
||||||
|
return callback(errors.InvalidResponse(results));
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(err, results);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to set provider of request manager
|
* Should be used to set provider of request manager
|
||||||
*
|
*
|
||||||
@ -3497,7 +3600,7 @@ RequestManager.prototype.poll = function () {
|
|||||||
module.exports = RequestManager;
|
module.exports = RequestManager;
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/config":5,"../utils/utils":6,"./errors":11,"./jsonrpc":18}],24:[function(require,module,exports){
|
},{"../utils/config":5,"../utils/utils":6,"./errors":12,"./jsonrpc":19}],25:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3567,7 +3670,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"./formatters":15,"./method":19}],25:[function(require,module,exports){
|
},{"./formatters":16,"./method":20}],26:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3683,7 +3786,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"./method":19}],26:[function(require,module,exports){
|
},{"./method":20}],27:[function(require,module,exports){
|
||||||
|
|
||||||
},{}],"bignumber.js":[function(require,module,exports){
|
},{}],"bignumber.js":[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -3705,7 +3808,7 @@ if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
|
|||||||
module.exports = web3;
|
module.exports = web3;
|
||||||
|
|
||||||
|
|
||||||
},{"./lib/web3":8,"./lib/web3/contract":9,"./lib/web3/httpprovider":17,"./lib/web3/qtsync":22}]},{},["web3"])
|
},{"./lib/web3":8,"./lib/web3/contract":10,"./lib/web3/httpprovider":18,"./lib/web3/qtsync":23}]},{},["web3"])
|
||||||
|
|
||||||
|
|
||||||
//# sourceMappingURL=web3-light.js.map
|
//# sourceMappingURL=web3-light.js.map
|
10
dist/web3-light.js.map
vendored
10
dist/web3-light.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/web3-light.min.js
vendored
4
dist/web3-light.min.js
vendored
File diff suppressed because one or more lines are too long
143
dist/web3.js
vendored
143
dist/web3.js
vendored
@ -1318,6 +1318,7 @@ var RequestManager = require('./web3/requestmanager');
|
|||||||
var c = require('./utils/config');
|
var c = require('./utils/config');
|
||||||
var Method = require('./web3/method');
|
var Method = require('./web3/method');
|
||||||
var Property = require('./web3/property');
|
var Property = require('./web3/property');
|
||||||
|
var Batch = require('./web3/batch');
|
||||||
|
|
||||||
var web3Methods = [
|
var web3Methods = [
|
||||||
new Method({
|
new Method({
|
||||||
@ -1410,6 +1411,9 @@ web3.toBigNumber = utils.toBigNumber;
|
|||||||
web3.toWei = utils.toWei;
|
web3.toWei = utils.toWei;
|
||||||
web3.fromWei = utils.fromWei;
|
web3.fromWei = utils.fromWei;
|
||||||
web3.isAddress = utils.isAddress;
|
web3.isAddress = utils.isAddress;
|
||||||
|
web3.createBatch = function () {
|
||||||
|
return new Batch();
|
||||||
|
};
|
||||||
|
|
||||||
// ADD defaultblock
|
// ADD defaultblock
|
||||||
Object.defineProperty(web3.eth, 'defaultBlock', {
|
Object.defineProperty(web3.eth, 'defaultBlock', {
|
||||||
@ -1445,7 +1449,66 @@ setupMethods(web3.shh, shh.methods);
|
|||||||
module.exports = web3;
|
module.exports = web3;
|
||||||
|
|
||||||
|
|
||||||
},{"./utils/config":5,"./utils/utils":6,"./version.json":7,"./web3/db":10,"./web3/eth":12,"./web3/filter":14,"./web3/formatters":15,"./web3/method":19,"./web3/net":20,"./web3/property":21,"./web3/requestmanager":23,"./web3/shh":24,"./web3/watches":25}],9:[function(require,module,exports){
|
},{"./utils/config":5,"./utils/utils":6,"./version.json":7,"./web3/batch":9,"./web3/db":11,"./web3/eth":13,"./web3/filter":15,"./web3/formatters":16,"./web3/method":20,"./web3/net":21,"./web3/property":22,"./web3/requestmanager":24,"./web3/shh":25,"./web3/watches":26}],9:[function(require,module,exports){
|
||||||
|
/*
|
||||||
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
|
ethereum.js is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
ethereum.js is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file batch.js
|
||||||
|
* @author Marek Kotewicz <marek@ethdev.com>
|
||||||
|
* @date 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
var RequestManager = require('./requestmanager');
|
||||||
|
|
||||||
|
var Batch = function () {
|
||||||
|
this.requests = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to add create new request to batch request
|
||||||
|
*
|
||||||
|
* @method add
|
||||||
|
* @param {Object} jsonrpc requet object
|
||||||
|
*/
|
||||||
|
Batch.prototype.add = function (request) {
|
||||||
|
this.requests.push(request);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to execute batch request
|
||||||
|
*
|
||||||
|
* @method execute
|
||||||
|
*/
|
||||||
|
Batch.prototype.execute = function () {
|
||||||
|
var requests = this.requests;
|
||||||
|
RequestManager.getInstance().sendBatch(requests, function (err, results) {
|
||||||
|
results = results || [];
|
||||||
|
requests.map(function (request, index) {
|
||||||
|
return results[index] || {};
|
||||||
|
}).forEach(function (result, index) {
|
||||||
|
requests[index].callback(err, result.result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Batch;
|
||||||
|
|
||||||
|
|
||||||
|
},{"./requestmanager":24}],10:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1627,7 +1690,7 @@ var Contract = function (abi, address) {
|
|||||||
module.exports = contract;
|
module.exports = contract;
|
||||||
|
|
||||||
|
|
||||||
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./event":13,"./function":16}],10:[function(require,module,exports){
|
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./event":14,"./function":17}],11:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1685,7 +1748,7 @@ module.exports = {
|
|||||||
methods: methods
|
methods: methods
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./method":19}],11:[function(require,module,exports){
|
},{"./method":20}],12:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1725,7 +1788,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{}],12:[function(require,module,exports){
|
},{}],13:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -1979,7 +2042,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./formatters":15,"./method":19,"./property":21}],13:[function(require,module,exports){
|
},{"../utils/utils":6,"./formatters":16,"./method":20,"./property":22}],14:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2175,7 +2238,7 @@ SolidityEvent.prototype.attachToContract = function (contract) {
|
|||||||
module.exports = SolidityEvent;
|
module.exports = SolidityEvent;
|
||||||
|
|
||||||
|
|
||||||
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./formatters":15}],14:[function(require,module,exports){
|
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8,"./formatters":16}],15:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2332,7 +2395,7 @@ Filter.prototype.get = function (callback) {
|
|||||||
module.exports = Filter;
|
module.exports = Filter;
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./formatters":15,"./requestmanager":23}],15:[function(require,module,exports){
|
},{"../utils/utils":6,"./formatters":16,"./requestmanager":24}],16:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2552,7 +2615,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/config":5,"../utils/utils":6}],16:[function(require,module,exports){
|
},{"../utils/config":5,"../utils/utils":6}],17:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2740,7 +2803,7 @@ SolidityFunction.prototype.attachToContract = function (contract) {
|
|||||||
module.exports = SolidityFunction;
|
module.exports = SolidityFunction;
|
||||||
|
|
||||||
|
|
||||||
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8}],17:[function(require,module,exports){
|
},{"../solidity/coder":1,"../utils/utils":6,"../web3":8}],18:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2832,7 +2895,7 @@ HttpProvider.prototype.sendAsync = function (payload, callback) {
|
|||||||
module.exports = HttpProvider;
|
module.exports = HttpProvider;
|
||||||
|
|
||||||
|
|
||||||
},{"./errors":11,"xmlhttprequest":4}],18:[function(require,module,exports){
|
},{"./errors":12,"xmlhttprequest":4}],19:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -2925,7 +2988,7 @@ Jsonrpc.prototype.toBatchPayload = function (messages) {
|
|||||||
module.exports = Jsonrpc;
|
module.exports = Jsonrpc;
|
||||||
|
|
||||||
|
|
||||||
},{}],19:[function(require,module,exports){
|
},{}],20:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3034,6 +3097,7 @@ Method.prototype.formatOutput = function (result) {
|
|||||||
*/
|
*/
|
||||||
Method.prototype.attachToObject = function (obj) {
|
Method.prototype.attachToObject = function (obj) {
|
||||||
var func = this.send.bind(this);
|
var func = this.send.bind(this);
|
||||||
|
func.request = this.request.bind(this);
|
||||||
func.call = this.call; // that's ugly. filter.js uses it
|
func.call = this.call; // that's ugly. filter.js uses it
|
||||||
var name = this.name.split('.');
|
var name = this.name.split('.');
|
||||||
if (name.length > 1) {
|
if (name.length > 1) {
|
||||||
@ -3064,6 +3128,18 @@ Method.prototype.toPayload = function (args) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to create pure JSONRPC request which can be used in batch request
|
||||||
|
*
|
||||||
|
* @method request
|
||||||
|
* @param {...} params
|
||||||
|
* @return {Object} jsonrpc request
|
||||||
|
*/
|
||||||
|
Method.prototype.request = function () {
|
||||||
|
var payload = this.toPayload(Array.prototype.slice.call(arguments));
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should send request to the API
|
* Should send request to the API
|
||||||
*
|
*
|
||||||
@ -3085,7 +3161,7 @@ Method.prototype.send = function () {
|
|||||||
module.exports = Method;
|
module.exports = Method;
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./errors":11,"./requestmanager":23}],20:[function(require,module,exports){
|
},{"../utils/utils":6,"./errors":12,"./requestmanager":24}],21:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3135,7 +3211,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/utils":6,"./property":21}],21:[function(require,module,exports){
|
},{"../utils/utils":6,"./property":22}],22:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3241,7 +3317,7 @@ Property.prototype.set = function (value) {
|
|||||||
module.exports = Property;
|
module.exports = Property;
|
||||||
|
|
||||||
|
|
||||||
},{"./requestmanager":23}],22:[function(require,module,exports){
|
},{"./requestmanager":24}],23:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3276,7 +3352,7 @@ QtSyncProvider.prototype.send = function (payload) {
|
|||||||
module.exports = QtSyncProvider;
|
module.exports = QtSyncProvider;
|
||||||
|
|
||||||
|
|
||||||
},{}],23:[function(require,module,exports){
|
},{}],24:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3384,6 +3460,33 @@ RequestManager.prototype.sendAsync = function (data, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to asynchronously send batch request
|
||||||
|
*
|
||||||
|
* @method sendBatch
|
||||||
|
* @param {Array} batch data
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
RequestManager.prototype.sendBatch = function (data, callback) {
|
||||||
|
if (!this.provider) {
|
||||||
|
return callback(errors.InvalidProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = Jsonrpc.getInstance().toBatchPayload(data);
|
||||||
|
|
||||||
|
this.provider.sendAsync(payload, function (err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!utils.isArray(results)) {
|
||||||
|
return callback(errors.InvalidResponse(results));
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(err, results);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to set provider of request manager
|
* Should be used to set provider of request manager
|
||||||
*
|
*
|
||||||
@ -3497,7 +3600,7 @@ RequestManager.prototype.poll = function () {
|
|||||||
module.exports = RequestManager;
|
module.exports = RequestManager;
|
||||||
|
|
||||||
|
|
||||||
},{"../utils/config":5,"../utils/utils":6,"./errors":11,"./jsonrpc":18}],24:[function(require,module,exports){
|
},{"../utils/config":5,"../utils/utils":6,"./errors":12,"./jsonrpc":19}],25:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3567,7 +3670,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"./formatters":15,"./method":19}],25:[function(require,module,exports){
|
},{"./formatters":16,"./method":20}],26:[function(require,module,exports){
|
||||||
/*
|
/*
|
||||||
This file is part of ethereum.js.
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
@ -3683,7 +3786,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
},{"./method":19}],26:[function(require,module,exports){
|
},{"./method":20}],27:[function(require,module,exports){
|
||||||
|
|
||||||
},{}],"bignumber.js":[function(require,module,exports){
|
},{}],"bignumber.js":[function(require,module,exports){
|
||||||
/*! bignumber.js v2.0.7 https://github.com/MikeMcl/bignumber.js/LICENCE */
|
/*! bignumber.js v2.0.7 https://github.com/MikeMcl/bignumber.js/LICENCE */
|
||||||
@ -6370,7 +6473,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
})(this);
|
})(this);
|
||||||
|
|
||||||
},{"crypto":26}],"web3":[function(require,module,exports){
|
},{"crypto":27}],"web3":[function(require,module,exports){
|
||||||
var web3 = require('./lib/web3');
|
var web3 = require('./lib/web3');
|
||||||
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
|
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
|
||||||
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
|
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
|
||||||
@ -6384,7 +6487,7 @@ if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
|
|||||||
module.exports = web3;
|
module.exports = web3;
|
||||||
|
|
||||||
|
|
||||||
},{"./lib/web3":8,"./lib/web3/contract":9,"./lib/web3/httpprovider":17,"./lib/web3/qtsync":22}]},{},["web3"])
|
},{"./lib/web3":8,"./lib/web3/contract":10,"./lib/web3/httpprovider":18,"./lib/web3/qtsync":23}]},{},["web3"])
|
||||||
|
|
||||||
|
|
||||||
//# sourceMappingURL=web3.js.map
|
//# sourceMappingURL=web3.js.map
|
10
dist/web3.js.map
vendored
10
dist/web3.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/web3.min.js
vendored
4
dist/web3.min.js
vendored
File diff suppressed because one or more lines are too long
@ -37,6 +37,7 @@ var RequestManager = require('./web3/requestmanager');
|
|||||||
var c = require('./utils/config');
|
var c = require('./utils/config');
|
||||||
var Method = require('./web3/method');
|
var Method = require('./web3/method');
|
||||||
var Property = require('./web3/property');
|
var Property = require('./web3/property');
|
||||||
|
var Batch = require('./web3/batch');
|
||||||
|
|
||||||
var web3Methods = [
|
var web3Methods = [
|
||||||
new Method({
|
new Method({
|
||||||
@ -129,6 +130,9 @@ web3.toBigNumber = utils.toBigNumber;
|
|||||||
web3.toWei = utils.toWei;
|
web3.toWei = utils.toWei;
|
||||||
web3.fromWei = utils.fromWei;
|
web3.fromWei = utils.fromWei;
|
||||||
web3.isAddress = utils.isAddress;
|
web3.isAddress = utils.isAddress;
|
||||||
|
web3.createBatch = function () {
|
||||||
|
return new Batch();
|
||||||
|
};
|
||||||
|
|
||||||
// ADD defaultblock
|
// ADD defaultblock
|
||||||
Object.defineProperty(web3.eth, 'defaultBlock', {
|
Object.defineProperty(web3.eth, 'defaultBlock', {
|
||||||
|
57
lib/web3/batch.js
Normal file
57
lib/web3/batch.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
This file is part of ethereum.js.
|
||||||
|
|
||||||
|
ethereum.js is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
ethereum.js is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file batch.js
|
||||||
|
* @author Marek Kotewicz <marek@ethdev.com>
|
||||||
|
* @date 2015
|
||||||
|
*/
|
||||||
|
|
||||||
|
var RequestManager = require('./requestmanager');
|
||||||
|
|
||||||
|
var Batch = function () {
|
||||||
|
this.requests = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to add create new request to batch request
|
||||||
|
*
|
||||||
|
* @method add
|
||||||
|
* @param {Object} jsonrpc requet object
|
||||||
|
*/
|
||||||
|
Batch.prototype.add = function (request) {
|
||||||
|
this.requests.push(request);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to execute batch request
|
||||||
|
*
|
||||||
|
* @method execute
|
||||||
|
*/
|
||||||
|
Batch.prototype.execute = function () {
|
||||||
|
var requests = this.requests;
|
||||||
|
RequestManager.getInstance().sendBatch(requests, function (err, results) {
|
||||||
|
results = results || [];
|
||||||
|
requests.map(function (request, index) {
|
||||||
|
return results[index] || {};
|
||||||
|
}).forEach(function (result, index) {
|
||||||
|
requests[index].callback(err, result.result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = Batch;
|
||||||
|
|
@ -106,6 +106,7 @@ Method.prototype.formatOutput = function (result) {
|
|||||||
*/
|
*/
|
||||||
Method.prototype.attachToObject = function (obj) {
|
Method.prototype.attachToObject = function (obj) {
|
||||||
var func = this.send.bind(this);
|
var func = this.send.bind(this);
|
||||||
|
func.request = this.request.bind(this);
|
||||||
func.call = this.call; // that's ugly. filter.js uses it
|
func.call = this.call; // that's ugly. filter.js uses it
|
||||||
var name = this.name.split('.');
|
var name = this.name.split('.');
|
||||||
if (name.length > 1) {
|
if (name.length > 1) {
|
||||||
@ -136,6 +137,18 @@ Method.prototype.toPayload = function (args) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to create pure JSONRPC request which can be used in batch request
|
||||||
|
*
|
||||||
|
* @method request
|
||||||
|
* @param {...} params
|
||||||
|
* @return {Object} jsonrpc request
|
||||||
|
*/
|
||||||
|
Method.prototype.request = function () {
|
||||||
|
var payload = this.toPayload(Array.prototype.slice.call(arguments));
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should send request to the API
|
* Should send request to the API
|
||||||
*
|
*
|
||||||
|
@ -105,6 +105,33 @@ RequestManager.prototype.sendAsync = function (data, callback) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should be called to asynchronously send batch request
|
||||||
|
*
|
||||||
|
* @method sendBatch
|
||||||
|
* @param {Array} batch data
|
||||||
|
* @param {Function} callback
|
||||||
|
*/
|
||||||
|
RequestManager.prototype.sendBatch = function (data, callback) {
|
||||||
|
if (!this.provider) {
|
||||||
|
return callback(errors.InvalidProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload = Jsonrpc.getInstance().toBatchPayload(data);
|
||||||
|
|
||||||
|
this.provider.sendAsync(payload, function (err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!utils.isArray(results)) {
|
||||||
|
return callback(errors.InvalidResponse(results));
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(err, results);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to set provider of request manager
|
* Should be used to set provider of request manager
|
||||||
*
|
*
|
||||||
|
37
test/batch.js
Normal file
37
test/batch.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
var chai = require('chai');
|
||||||
|
var assert = chai.assert;
|
||||||
|
var web3 = require('../index');
|
||||||
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
||||||
|
|
||||||
|
describe('lib/web3/batch', function () {
|
||||||
|
describe('execute', function () {
|
||||||
|
it('should execute batch request', function (done) {
|
||||||
|
|
||||||
|
var provider = new FakeHttpProvider();
|
||||||
|
web3.setProvider(provider);
|
||||||
|
web3.reset();
|
||||||
|
|
||||||
|
var result = '0x126';
|
||||||
|
var result2 = '0x127';
|
||||||
|
provider.injectBatchResults([result, result2]);
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
var callback = function (err, r) {
|
||||||
|
counter++;
|
||||||
|
assert.equal(result, r);
|
||||||
|
};
|
||||||
|
|
||||||
|
var callback2 = function (err, r) {
|
||||||
|
assert.equal(counter, 1);
|
||||||
|
assert.equal(result2, r);
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
var batch = web3.createBatch();
|
||||||
|
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
|
||||||
|
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000005', 'latest', callback2));
|
||||||
|
batch.execute();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -430,3 +430,4 @@ describe('web3.eth.contract', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
21
test/method.request.js
Normal file
21
test/method.request.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
var chai = require('chai');
|
||||||
|
var assert = chai.assert;
|
||||||
|
var web3 = require('../index');
|
||||||
|
|
||||||
|
describe('lib/web3/method', function () {
|
||||||
|
describe('request', function () {
|
||||||
|
it('should create proper request', function () {
|
||||||
|
|
||||||
|
var callback = function (err, result) {};
|
||||||
|
var expected = {
|
||||||
|
method: 'eth_getBalance',
|
||||||
|
callback: callback,
|
||||||
|
params: ['0x0000000000000000000000000000000000000000', 'latest']
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback);
|
||||||
|
assert.deepEqual(request, expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user