Browse Source

updated web3 to version 0.9.0

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
a552208609
  1. 2
      libjsqrc/ethereumjs/.versions
  2. 48
      libjsqrc/ethereumjs/README.md
  3. 2
      libjsqrc/ethereumjs/bower.json
  4. 521
      libjsqrc/ethereumjs/dist/web3-light.js
  5. 5
      libjsqrc/ethereumjs/dist/web3-light.min.js
  6. 521
      libjsqrc/ethereumjs/dist/web3.js
  7. 34
      libjsqrc/ethereumjs/dist/web3.js.map
  8. 6
      libjsqrc/ethereumjs/dist/web3.min.js
  9. 2
      libjsqrc/ethereumjs/example/balance.html
  10. 21
      libjsqrc/ethereumjs/example/contract.html
  11. 22
      libjsqrc/ethereumjs/example/contract_array.html
  12. 28
      libjsqrc/ethereumjs/example/event_inc.html
  13. 4
      libjsqrc/ethereumjs/index.js
  14. 2
      libjsqrc/ethereumjs/lib/version.json
  15. 3
      libjsqrc/ethereumjs/lib/web3.js
  16. 1
      libjsqrc/ethereumjs/lib/web3/allevents.js
  17. 11
      libjsqrc/ethereumjs/lib/web3/batch.js
  18. 117
      libjsqrc/ethereumjs/lib/web3/contract.js
  19. 2
      libjsqrc/ethereumjs/lib/web3/errors.js
  20. 16
      libjsqrc/ethereumjs/lib/web3/eth.js
  21. 2
      libjsqrc/ethereumjs/lib/web3/event.js
  22. 2
      libjsqrc/ethereumjs/lib/web3/filter.js
  23. 33
      libjsqrc/ethereumjs/lib/web3/formatters.js
  24. 26
      libjsqrc/ethereumjs/lib/web3/httpprovider.js
  25. 211
      libjsqrc/ethereumjs/lib/web3/ipcprovider.js
  26. 2
      libjsqrc/ethereumjs/lib/web3/method.js
  27. 36
      libjsqrc/ethereumjs/lib/web3/property.js
  28. 33
      libjsqrc/ethereumjs/lib/web3/qtsync.js
  29. 2
      libjsqrc/ethereumjs/package.js
  30. 22
      libjsqrc/ethereumjs/package.json
  31. 1741
      libjsqrc/ethereumjs/styleguide.md
  32. 98
      libjsqrc/ethereumjs/test/batch.js
  33. 8
      libjsqrc/ethereumjs/test/contract.js
  34. 17
      libjsqrc/ethereumjs/test/errors.js
  35. 2
      libjsqrc/ethereumjs/test/event.encode.js
  36. 18
      libjsqrc/ethereumjs/test/helpers/FakeHttpProvider.js
  37. 41
      libjsqrc/ethereumjs/test/helpers/FakeIpcRequest.js
  38. 8
      libjsqrc/ethereumjs/test/httpprovider.js
  39. 58
      libjsqrc/ethereumjs/test/ipcprovider.js
  40. 2
      libjsqrc/ethereumjs/test/polling.js
  41. 22
      libjsqrc/ethereumjs/test/qtsyncprovider.js
  42. 14
      libjsqrc/ethereumjs/test/web3.eth.contract.js
  43. 2
      libjsqrc/ethereumjs/test/web3.eth.getTransaction.js
  44. 70
      libjsqrc/ethereumjs/test/web3.eth.getTransactionReceipt.js

2
libjsqrc/ethereumjs/.versions

@ -1,3 +1,3 @@
ethereum:web3@0.5.0
ethereum:web3@0.7.0
meteor@1.1.6
underscore@1.0.3

48
libjsqrc/ethereumjs/README.md

@ -17,42 +17,52 @@ You need to run a local ethrereum node to use this library.
### Node.js
$ npm install web3
```bash
npm install web3
```
### Meteor.js
$ meteor add ethereum:web3
```bash
meteor add ethereum:web3
```
### As Browser module
Bower
$ bower install web3
```bash
bower install web3
```
Component
$ component install ethereum/web3.js
```bash
component install ethereum/web3.js
```
* Include `ethereum.min.js` in your html file. (not required for the meteor package)
* Include [bignumber.js](https://github.com/MikeMcl/bignumber.js/) (not required for the meteor package)
## Usage
Use the `web3` object directly from global namespace:
```js
console.log(web3); // {eth: .., shh: ...} // it's here!
```
Set a provider (QtSyncProvider, HttpProvider)
Set a provider (HttpProvider)
```js
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
```
There you go, now you can use it:
```
```js
var coinbase = web3.eth.coinbase;
var balance = web3.eth.getBalance(coinbase);
```
For another example see `example/index.html`.
You can find more examples in [`example`](https://github.com/ethereum/web3.js/tree/master/example) directory.
## Contribute!
@ -82,26 +92,6 @@ npm run-script build
npm test
```
### Testing (karma)
Karma allows testing within one or several browsers.
```bash
npm run-script karma # default browsers are Chrome and Firefox
npm run-script karma -- --browsers="Chrome,Safari" # custom browsers
```
**Please note this repo is in it's early stage.**
If you'd like to run a Http ethereum node check out
[cpp-ethereum](https://github.com/ethereum/cpp-ethereum).
Install ethereum and spawn a node:
```
eth -j
```
[npm-image]: https://badge.fury.io/js/web3.png
[npm-url]: https://npmjs.org/package/web3
[travis-image]: https://travis-ci.org/ethereum/web3.js.svg

2
libjsqrc/ethereumjs/bower.json

@ -1,7 +1,7 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "0.7.1",
"version": "0.9.0",
"description": "Ethereum Compatible JavaScript API",
"main": [
"./dist/web3.js",

521
libjsqrc/ethereumjs/dist/web3-light.js

@ -1398,7 +1398,7 @@ module.exports = {
},{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){
module.exports={
"version": "0.7.1"
"version": "0.9.0"
}
},{}],9:[function(require,module,exports){
@ -1505,6 +1505,9 @@ web3.setProvider = function (provider) {
this.currentProvider = provider;
RequestManager.getInstance().setProvider(provider);
};
web3.isConnected = function(){
return (this.currentProvider && this.currentProvider.isConnected());
};
web3.reset = function () {
RequestManager.getInstance().reset();
c.defaultBlock = 'latest';
@ -1575,7 +1578,7 @@ setupMethods(web3.shh, shh.methods);
module.exports = web3;
},{"./utils/config":5,"./utils/sha3":6,"./utils/utils":7,"./version.json":8,"./web3/batch":11,"./web3/db":13,"./web3/eth":15,"./web3/filter":17,"./web3/formatters":18,"./web3/method":23,"./web3/net":25,"./web3/property":26,"./web3/requestmanager":28,"./web3/shh":29,"./web3/watches":31}],10:[function(require,module,exports){
},{"./utils/config":5,"./utils/sha3":6,"./utils/utils":7,"./version.json":8,"./web3/batch":11,"./web3/db":13,"./web3/eth":15,"./web3/filter":17,"./web3/formatters":18,"./web3/method":24,"./web3/net":26,"./web3/property":27,"./web3/requestmanager":28,"./web3/shh":29,"./web3/watches":31}],10:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1620,7 +1623,6 @@ AllSolidityEvents.prototype.encode = function (options) {
result[f] = formatters.inputBlockNumberFormatter(options[f]);
});
result.topics = [null, null, null, null, null]; // match all topics
result.address = this._address;
return result;
@ -1682,6 +1684,8 @@ module.exports = AllSolidityEvents;
*/
var RequestManager = require('./requestmanager');
var Jsonrpc = require('./jsonrpc');
var errors = require('./errors');
var Batch = function () {
this.requests = [];
@ -1708,11 +1712,14 @@ Batch.prototype.execute = function () {
results = results || [];
requests.map(function (request, index) {
return results[index] || {};
}).map(function (result, index) {
return requests[index].format ? requests[index].format(result.result) : result.result;
}).forEach(function (result, index) {
if (requests[index].callback) {
requests[index].callback(err, result);
if (!Jsonrpc.getInstance().isValidResponse(result)) {
return requests[index].callback(errors.InvalidResponse(result));
}
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
}
});
});
@ -1721,7 +1728,7 @@ Batch.prototype.execute = function () {
module.exports = Batch;
},{"./requestmanager":28}],12:[function(require,module,exports){
},{"./errors":14,"./jsonrpc":23,"./requestmanager":28}],12:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1820,6 +1827,79 @@ var contract = function (abi) {
return new ContractFactory(abi);
};
/**
* Should be called to check if the contract gets properly deployed on the blockchain.
*
* @method checkForContractAddress
* @param {Object} contract
* @param {Function} callback
* @returns {Undefined}
*/
var checkForContractAddress = function(contract, abi, callback){
var count = 0,
callbackFired = false;
// wait for receipt
var filter = web3.eth.filter('latest', function(e){
if(!e && !callbackFired) {
count++;
// console.log('Checking for contract address', count);
// stop watching after 50 blocks (timeout)
if(count > 50) {
filter.stopWatching();
callbackFired = true;
if(callback)
callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
else
throw new Error('Contract transaction couldn\'t be found after 50 blocks');
} else {
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
if(receipt && !callbackFired) {
web3.eth.getCode(receipt.contractAddress, function(e, code){
/*jshint maxcomplexity: 5 */
if(callbackFired)
return;
filter.stopWatching();
callbackFired = true;
if(code.length > 2) {
// console.log('Contract code deployed!');
contract.address = receipt.contractAddress;
// attach events and methods
addFunctionsToContract(contract, abi);
addEventsToContract(contract, abi);
// call callback for the second time
if(callback)
callback(null, contract);
} else {
if(callback)
callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
else
throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
}
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -1838,10 +1918,12 @@ var ContractFactory = function (abi) {
* @param {Any} contract constructor param2 (optional)
* @param {Object} contract transaction object (required)
* @param {Function} callback
* @returns {Contract} returns contract if no callback was passed,
* otherwise calls callback function (err, contract)
* @returns {Contract} returns contract instance
*/
ContractFactory.prototype.new = function () {
var _this = this;
var contract = new Contract(this.abi);
// parse arguments
var options = {}; // required!
var callback;
@ -1861,18 +1943,31 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
if (!callback) {
var address = web3.eth.sendTransaction(options);
return this.at(address);
}
var self = this;
web3.eth.sendTransaction(options, function (err, address) {
if(callback) {
// wait for the contract address adn check if the code was deployed
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
// call callback for the first time
callback(null, contract);
checkForContractAddress(contract, _this.abi, callback);
}
self.at(address, callback);
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract, _this.abi);
}
return contract;
};
/**
@ -1885,12 +1980,17 @@ ContractFactory.prototype.new = function () {
* otherwise calls callback function (err, contract)
*/
ContractFactory.prototype.at = function (address, callback) {
var contract = new Contract(this.abi, address);
// TODO: address is required
// attach functions
addFunctionsToContract(contract, this.abi);
addEventsToContract(contract, this.abi);
if (callback) {
callback(null, new Contract(this.abi, address));
callback(null, contract);
}
return new Contract(this.abi, address);
return contract;
};
/**
@ -1902,8 +2002,6 @@ ContractFactory.prototype.at = function (address, callback) {
*/
var Contract = function (abi, address) {
this.address = address;
addFunctionsToContract(this, abi);
addEventsToContract(this, abi);
};
module.exports = contract;
@ -1967,7 +2065,7 @@ module.exports = {
methods: methods
};
},{"./method":23}],14:[function(require,module,exports){
},{"./method":24}],14:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2001,7 +2099,7 @@ module.exports = {
return new Error('Providor not set or invalid');
},
InvalidResponse: function (result){
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response';
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: '+ result;
return new Error(message);
}
};
@ -2162,6 +2260,13 @@ var getTransactionFromBlock = new Method({
outputFormatter: formatters.outputTransactionFormatter
});
var getTransactionReceipt = new Method({
name: 'getTransactionReceipt',
call: 'eth_getTransactionReceipt',
params: 1,
outputFormatter: formatters.outputTransactionReceiptFormatter
});
var getTransactionCount = new Method({
name: 'getTransactionCount',
call: 'eth_getTransactionCount',
@ -2174,7 +2279,7 @@ var sendRawTransaction = new Method({
name: 'sendRawTransaction',
call: 'eth_sendRawTransaction',
params: 1,
inputFormatter: []
inputFormatter: [null]
});
var sendTransaction = new Method({
@ -2240,6 +2345,7 @@ var methods = [
getBlockUncleCount,
getTransaction,
getTransactionFromBlock,
getTransactionReceipt,
getTransactionCount,
call,
estimateGas,
@ -2292,7 +2398,7 @@ module.exports = {
};
},{"../utils/utils":7,"./formatters":18,"./method":23,"./property":26}],16:[function(require,module,exports){
},{"../utils/utils":7,"./formatters":18,"./method":24,"./property":27}],16:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2398,8 +2504,8 @@ SolidityEvent.prototype.encode = function (indexed, options) {
result.topics = [];
if (!this._anonymous) {
result.address = this._address;
if (!this._anonymous) {
result.topics.push('0x' + this.signature());
}
@ -2594,9 +2700,11 @@ var getLogsAtStart = function(self, callback){
callback(err);
}
if(utils.isArray(messages)) {
messages.forEach(function (message) {
callback(null, message);
});
}
});
}
};
@ -2798,8 +2906,8 @@ var inputTransactionFormatter = function (options){
* Formats the output of a transaction to its proper values
*
* @method outputTransactionFormatter
* @param {Object} transaction
* @returns {Object} transaction
* @param {Object} tx
* @returns {Object}
*/
var outputTransactionFormatter = function (tx){
if(tx.blockNumber !== null)
@ -2813,12 +2921,36 @@ var outputTransactionFormatter = function (tx){
return tx;
};
/**
* Formats the output of a transaction receipt to its proper values
*
* @method outputTransactionReceiptFormatter
* @param {Object} receipt
* @returns {Object}
*/
var outputTransactionReceiptFormatter = function (receipt){
if(receipt.blockNumber !== null)
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
if(receipt.transactionIndex !== null)
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
if(utils.isArray(receipt.logs)) {
receipt.logs = receipt.logs.map(function(log){
return outputLogFormatter(log);
});
}
return receipt;
};
/**
* Formats the output of a block to its proper values
*
* @method outputBlockFormatter
* @param {Object} block object
* @returns {Object} block object
* @param {Object} block
* @returns {Object}
*/
var outputBlockFormatter = function(block) {
@ -2926,6 +3058,7 @@ module.exports = {
inputPostFormatter: inputPostFormatter,
outputBigNumberFormatter: outputBigNumberFormatter,
outputTransactionFormatter: outputTransactionFormatter,
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
outputBlockFormatter: outputBlockFormatter,
outputLogFormatter: outputLogFormatter,
outputPostFormatter: outputPostFormatter
@ -3191,12 +3324,11 @@ module.exports = SolidityFunction;
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2014
* @date 2015
*/
"use strict";
// resolves the problem for electron/atom shell environments, which use node integration, but have no process variable available
var XMLHttpRequest = (typeof window !== 'undefined' && window.XMLHttpRequest) ? window.XMLHttpRequest : require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
var errors = require('./errors');
@ -3204,6 +3336,25 @@ var HttpProvider = function (host) {
this.host = host || 'http://localhost:8545';
};
HttpProvider.prototype.isConnected = function() {
var request = new XMLHttpRequest();
request.open('POST', this.host, false);
request.setRequestHeader('Content-type','application/json');
try {
request.send(JSON.stringify({
id: 9999999999,
jsonrpc: '2.0',
method: 'net_listening',
params: []
}));
return true;
} catch(e) {
return false;
}
};
HttpProvider.prototype.send = function (payload) {
var request = new XMLHttpRequest();
@ -3228,7 +3379,7 @@ HttpProvider.prototype.send = function (payload) {
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
throw errors.InvalidResponse(request.responseText);
}
return result;
@ -3244,7 +3395,7 @@ HttpProvider.prototype.sendAsync = function (payload, callback) {
try {
result = JSON.parse(result);
} catch(e) {
error = errors.InvalidResponse(result);
error = errors.InvalidResponse(request.responseText);
}
callback(error, result);
@ -3391,6 +3542,219 @@ module.exports = ICAP;
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 ipcprovider.js
* @authors:
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
"use strict";
var utils = require('../utils/utils');
var errors = require('./errors');
var errorTimeout = '{"jsonrpc": "2.0", "error": {"code": -32603, "message": "IPC Request timed out for method \'__method__\'"}, "id": "__id__"}';
var IpcProvider = function (path, net) {
var _this = this;
this.responseCallbacks = {};
this.path = path;
net = net || require('net');
this.connection = net.connect({path: this.path});
this.connection.on('error', function(e){
console.error('IPC Connection Error', e);
_this._timeout();
});
this.connection.on('end', function(){
_this._timeout();
});
// LISTEN FOR CONNECTION RESPONSES
this.connection.on('data', function(data) {
/*jshint maxcomplexity: 6 */
_this._parseResponse(data.toString()).forEach(function(result){
var id = null;
// get the id which matches the returned id
if(utils.isArray(result)) {
result.forEach(function(load){
if(_this.responseCallbacks[load.id])
id = load.id;
});
} else {
id = result.id;
}
// fire the callback
if(_this.responseCallbacks[id]) {
_this.responseCallbacks[id](null, result);
delete _this.responseCallbacks[id];
}
});
});
};
/**
Will parse the response and make an array out of it.
@method _parseResponse
@param {String} data
*/
IpcProvider.prototype._parseResponse = function(data) {
var _this = this,
returnValues = [];
// DE-CHUNKER
var dechunkedData = data
.replace(/\}\{/g,'}|--|{') // }{
.replace(/\}\]\[\{/g,'}]|--|[{') // }][{
.replace(/\}\[\{/g,'}|--|[{') // }[{
.replace(/\}\]\{/g,'}]|--|{') // }]{
.split('|--|');
dechunkedData.forEach(function(data){
// prepend the last chunk
if(_this.lastChunk)
data = _this.lastChunk + data;
var result = null;
try {
result = JSON.parse(data);
} catch(e) {
_this.lastChunk = data;
// start timeout to cancel all requests
clearTimeout(_this.lastChunkTimeout);
_this.lastChunkTimeout = setTimeout(function(){
_this.timeout();
throw errors.InvalidResponse(data);
}, 1000 * 15);
return;
}
// cancel timeout and set chunk to null
clearTimeout(_this.lastChunkTimeout);
_this.lastChunk = null;
if(result)
returnValues.push(result);
});
return returnValues;
};
/**
Get the adds a callback to the responseCallbacks object,
which will be called if a response matching the response Id will arrive.
@method _addResponseCallback
*/
IpcProvider.prototype._addResponseCallback = function(payload, callback) {
var id = payload.id || payload[0].id;
var method = payload.method || payload[0].method;
this.responseCallbacks[id] = callback;
this.responseCallbacks[id].method = method;
};
/**
Timeout all requests when the end/error event is fired
@method _timeout
*/
IpcProvider.prototype._timeout = function() {
for(var key in this.responseCallbacks) {
if(this.responseCallbacks.hasOwnProperty(key)){
this.responseCallbacks[key](errorTimeout.replace('__id__', key).replace('__method__', this.responseCallbacks[key].method));
delete this.responseCallbacks[key];
}
}
};
/**
Check if the current connection is still valid.
@method isConnected
*/
IpcProvider.prototype.isConnected = function() {
var _this = this;
// try reconnect, when connection is gone
if(!_this.connection.writable)
_this.connection.connect({path: _this.path});
return !!this.connection.writable;
};
IpcProvider.prototype.send = function (payload) {
if(this.connection.writeSync) {
var result;
// try reconnect, when connection is gone
if(!this.connection.writable)
this.connection.connect({path: this.path});
var data = this.connection.writeSync(JSON.stringify(payload));
try {
result = JSON.parse(data);
} catch(e) {
throw errors.InvalidResponse(data);
}
return result;
} else {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
}
};
IpcProvider.prototype.sendAsync = function (payload, callback) {
// try reconnect, when connection is gone
if(!this.connection.writable)
this.connection.connect({path: this.path});
this.connection.write(JSON.stringify(payload));
this._addResponseCallback(payload, callback);
};
module.exports = IpcProvider;
},{"../utils/utils":7,"./errors":14,"net":32}],23:[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 jsonrpc.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
@ -3467,7 +3831,7 @@ Jsonrpc.prototype.toBatchPayload = function (messages) {
module.exports = Jsonrpc;
},{}],23:[function(require,module,exports){
},{}],24:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3564,7 +3928,7 @@ Method.prototype.formatInput = function (args) {
* @return {Object}
*/
Method.prototype.formatOutput = function (result) {
return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
return this.outputFormatter && result ? this.outputFormatter(result) : result;
};
/**
@ -3641,7 +4005,7 @@ Method.prototype.send = function () {
module.exports = Method;
},{"../utils/utils":7,"./errors":14,"./requestmanager":28}],24:[function(require,module,exports){
},{"../utils/utils":7,"./errors":14,"./requestmanager":28}],25:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3689,7 +4053,7 @@ var abi = [
module.exports = contract(abi).at(address);
},{"./contract":12}],25:[function(require,module,exports){
},{"./contract":12}],26:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3739,7 +4103,7 @@ module.exports = {
};
},{"../utils/utils":7,"./property":26}],26:[function(require,module,exports){
},{"../utils/utils":7,"./property":27}],27:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3764,6 +4128,7 @@ module.exports = {
*/
var RequestManager = require('./requestmanager');
var utils = require('../utils/utils');
var Property = function (options) {
this.name = options.name;
@ -3795,6 +4160,19 @@ Property.prototype.formatOutput = function (result) {
return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
};
/**
* Should be used to extract callback from array of arguments. Modifies input param
*
* @method extractCallback
* @param {Array} arguments
* @return {Function|Null} callback, if exists
*/
Property.prototype.extractCallback = function (args) {
if (utils.isFunction(args[args.length - 1])) {
return args.pop(); // modify the args array!
}
};
/**
* Should attach function to method
*
@ -3821,7 +4199,10 @@ Property.prototype.attachToObject = function (obj) {
return prefix + name.charAt(0).toUpperCase() + name.slice(1);
};
obj[toAsyncName('get', name)] = this.getAsync.bind(this);
var func = this.getAsync.bind(this);
func.request = this.request.bind(this);
obj[toAsyncName('get', name)] = func;
};
/**
@ -3854,45 +4235,27 @@ Property.prototype.getAsync = function (callback) {
});
};
module.exports = Property;
},{"./requestmanager":28}],27:[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 qtsync.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* @date 2014
/**
* Should be called to create pure JSONRPC request which can be used in batch request
*
* @method request
* @param {...} params
* @return {Object} jsonrpc request
*/
var QtSyncProvider = function () {
Property.prototype.request = function () {
var payload = {
method: this.getter,
params: [],
callback: this.extractCallback(Array.prototype.slice.call(arguments))
};
QtSyncProvider.prototype.send = function (payload) {
var result = navigator.qt.callMethod(JSON.stringify(payload));
return JSON.parse(result);
payload.format = this.formatOutput.bind(this);
return payload;
};
module.exports = QtSyncProvider;
module.exports = Property;
},{}],28:[function(require,module,exports){
},{"../utils/utils":7,"./requestmanager":28}],28:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4157,7 +4520,7 @@ RequestManager.prototype.poll = function () {
module.exports = RequestManager;
},{"../utils/config":5,"../utils/utils":7,"./errors":14,"./jsonrpc":22}],29:[function(require,module,exports){
},{"../utils/config":5,"../utils/utils":7,"./errors":14,"./jsonrpc":23}],29:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4227,7 +4590,7 @@ module.exports = {
};
},{"./formatters":18,"./method":23}],30:[function(require,module,exports){
},{"./formatters":18,"./method":24}],30:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4323,7 +4686,7 @@ var deposit = function (from, address, value, client, callback) {
module.exports = transfer;
},{"../web3":9,"./contract":12,"./icap":21,"./namereg":24}],31:[function(require,module,exports){
},{"../web3":9,"./contract":12,"./icap":21,"./namereg":25}],31:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4439,7 +4802,7 @@ module.exports = {
};
},{"./method":23}],32:[function(require,module,exports){
},{"./method":24}],32:[function(require,module,exports){
},{}],33:[function(require,module,exports){
;(function (root, factory) {
@ -5821,8 +6184,10 @@ module.exports = BigNumber; // jshint ignore:line
},{}],"web3":[function(require,module,exports){
var web3 = require('./lib/web3');
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
web3.providers.IpcProvider = require('./lib/web3/ipcprovider');
web3.eth.contract = require('./lib/web3/contract');
web3.eth.namereg = require('./lib/web3/namereg');
web3.eth.sendIBANTransaction = require('./lib/web3/transfer');
@ -5835,5 +6200,5 @@ if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
module.exports = web3;
},{"./lib/web3":9,"./lib/web3/contract":12,"./lib/web3/httpprovider":20,"./lib/web3/namereg":24,"./lib/web3/qtsync":27,"./lib/web3/transfer":30}]},{},["web3"])
},{"./lib/web3":9,"./lib/web3/contract":12,"./lib/web3/httpprovider":20,"./lib/web3/ipcprovider":22,"./lib/web3/namereg":25,"./lib/web3/transfer":30}]},{},["web3"])
//# sourceMappingURL=web3-light.js.map

5
libjsqrc/ethereumjs/dist/web3-light.min.js

File diff suppressed because one or more lines are too long

521
libjsqrc/ethereumjs/dist/web3.js

@ -1398,7 +1398,7 @@ module.exports = {
},{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){
module.exports={
"version": "0.7.1"
"version": "0.9.0"
}
},{}],9:[function(require,module,exports){
@ -1505,6 +1505,9 @@ web3.setProvider = function (provider) {
this.currentProvider = provider;
RequestManager.getInstance().setProvider(provider);
};
web3.isConnected = function(){
return (this.currentProvider && this.currentProvider.isConnected());
};
web3.reset = function () {
RequestManager.getInstance().reset();
c.defaultBlock = 'latest';
@ -1575,7 +1578,7 @@ setupMethods(web3.shh, shh.methods);
module.exports = web3;
},{"./utils/config":5,"./utils/sha3":6,"./utils/utils":7,"./version.json":8,"./web3/batch":11,"./web3/db":13,"./web3/eth":15,"./web3/filter":17,"./web3/formatters":18,"./web3/method":23,"./web3/net":25,"./web3/property":26,"./web3/requestmanager":28,"./web3/shh":29,"./web3/watches":31}],10:[function(require,module,exports){
},{"./utils/config":5,"./utils/sha3":6,"./utils/utils":7,"./version.json":8,"./web3/batch":11,"./web3/db":13,"./web3/eth":15,"./web3/filter":17,"./web3/formatters":18,"./web3/method":24,"./web3/net":26,"./web3/property":27,"./web3/requestmanager":28,"./web3/shh":29,"./web3/watches":31}],10:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1620,7 +1623,6 @@ AllSolidityEvents.prototype.encode = function (options) {
result[f] = formatters.inputBlockNumberFormatter(options[f]);
});
result.topics = [null, null, null, null, null]; // match all topics
result.address = this._address;
return result;
@ -1682,6 +1684,8 @@ module.exports = AllSolidityEvents;
*/
var RequestManager = require('./requestmanager');
var Jsonrpc = require('./jsonrpc');
var errors = require('./errors');
var Batch = function () {
this.requests = [];
@ -1708,11 +1712,14 @@ Batch.prototype.execute = function () {
results = results || [];
requests.map(function (request, index) {
return results[index] || {};
}).map(function (result, index) {
return requests[index].format ? requests[index].format(result.result) : result.result;
}).forEach(function (result, index) {
if (requests[index].callback) {
requests[index].callback(err, result);
if (!Jsonrpc.getInstance().isValidResponse(result)) {
return requests[index].callback(errors.InvalidResponse(result));
}
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
}
});
});
@ -1721,7 +1728,7 @@ Batch.prototype.execute = function () {
module.exports = Batch;
},{"./requestmanager":28}],12:[function(require,module,exports){
},{"./errors":14,"./jsonrpc":23,"./requestmanager":28}],12:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1820,6 +1827,79 @@ var contract = function (abi) {
return new ContractFactory(abi);
};
/**
* Should be called to check if the contract gets properly deployed on the blockchain.
*
* @method checkForContractAddress
* @param {Object} contract
* @param {Function} callback
* @returns {Undefined}
*/
var checkForContractAddress = function(contract, abi, callback){
var count = 0,
callbackFired = false;
// wait for receipt
var filter = web3.eth.filter('latest', function(e){
if(!e && !callbackFired) {
count++;
// console.log('Checking for contract address', count);
// stop watching after 50 blocks (timeout)
if(count > 50) {
filter.stopWatching();
callbackFired = true;
if(callback)
callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
else
throw new Error('Contract transaction couldn\'t be found after 50 blocks');
} else {
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
if(receipt && !callbackFired) {
web3.eth.getCode(receipt.contractAddress, function(e, code){
/*jshint maxcomplexity: 5 */
if(callbackFired)
return;
filter.stopWatching();
callbackFired = true;
if(code.length > 2) {
// console.log('Contract code deployed!');
contract.address = receipt.contractAddress;
// attach events and methods
addFunctionsToContract(contract, abi);
addEventsToContract(contract, abi);
// call callback for the second time
if(callback)
callback(null, contract);
} else {
if(callback)
callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
else
throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
}
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -1838,10 +1918,12 @@ var ContractFactory = function (abi) {
* @param {Any} contract constructor param2 (optional)
* @param {Object} contract transaction object (required)
* @param {Function} callback
* @returns {Contract} returns contract if no callback was passed,
* otherwise calls callback function (err, contract)
* @returns {Contract} returns contract instance
*/
ContractFactory.prototype.new = function () {
var _this = this;
var contract = new Contract(this.abi);
// parse arguments
var options = {}; // required!
var callback;
@ -1861,18 +1943,31 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
if (!callback) {
var address = web3.eth.sendTransaction(options);
return this.at(address);
}
var self = this;
web3.eth.sendTransaction(options, function (err, address) {
if(callback) {
// wait for the contract address adn check if the code was deployed
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
// call callback for the first time
callback(null, contract);
checkForContractAddress(contract, _this.abi, callback);
}
self.at(address, callback);
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract, _this.abi);
}
return contract;
};
/**
@ -1885,12 +1980,17 @@ ContractFactory.prototype.new = function () {
* otherwise calls callback function (err, contract)
*/
ContractFactory.prototype.at = function (address, callback) {
var contract = new Contract(this.abi, address);
// TODO: address is required
// attach functions
addFunctionsToContract(contract, this.abi);
addEventsToContract(contract, this.abi);
if (callback) {
callback(null, new Contract(this.abi, address));
callback(null, contract);
}
return new Contract(this.abi, address);
return contract;
};
/**
@ -1902,8 +2002,6 @@ ContractFactory.prototype.at = function (address, callback) {
*/
var Contract = function (abi, address) {
this.address = address;
addFunctionsToContract(this, abi);
addEventsToContract(this, abi);
};
module.exports = contract;
@ -1967,7 +2065,7 @@ module.exports = {
methods: methods
};
},{"./method":23}],14:[function(require,module,exports){
},{"./method":24}],14:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2001,7 +2099,7 @@ module.exports = {
return new Error('Providor not set or invalid');
},
InvalidResponse: function (result){
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response';
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: '+ result;
return new Error(message);
}
};
@ -2162,6 +2260,13 @@ var getTransactionFromBlock = new Method({
outputFormatter: formatters.outputTransactionFormatter
});
var getTransactionReceipt = new Method({
name: 'getTransactionReceipt',
call: 'eth_getTransactionReceipt',
params: 1,
outputFormatter: formatters.outputTransactionReceiptFormatter
});
var getTransactionCount = new Method({
name: 'getTransactionCount',
call: 'eth_getTransactionCount',
@ -2174,7 +2279,7 @@ var sendRawTransaction = new Method({
name: 'sendRawTransaction',
call: 'eth_sendRawTransaction',
params: 1,
inputFormatter: []
inputFormatter: [null]
});
var sendTransaction = new Method({
@ -2240,6 +2345,7 @@ var methods = [
getBlockUncleCount,
getTransaction,
getTransactionFromBlock,
getTransactionReceipt,
getTransactionCount,
call,
estimateGas,
@ -2292,7 +2398,7 @@ module.exports = {
};
},{"../utils/utils":7,"./formatters":18,"./method":23,"./property":26}],16:[function(require,module,exports){
},{"../utils/utils":7,"./formatters":18,"./method":24,"./property":27}],16:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2398,8 +2504,8 @@ SolidityEvent.prototype.encode = function (indexed, options) {
result.topics = [];
if (!this._anonymous) {
result.address = this._address;
if (!this._anonymous) {
result.topics.push('0x' + this.signature());
}
@ -2594,9 +2700,11 @@ var getLogsAtStart = function(self, callback){
callback(err);
}
if(utils.isArray(messages)) {
messages.forEach(function (message) {
callback(null, message);
});
}
});
}
};
@ -2798,8 +2906,8 @@ var inputTransactionFormatter = function (options){
* Formats the output of a transaction to its proper values
*
* @method outputTransactionFormatter
* @param {Object} transaction
* @returns {Object} transaction
* @param {Object} tx
* @returns {Object}
*/
var outputTransactionFormatter = function (tx){
if(tx.blockNumber !== null)
@ -2813,12 +2921,36 @@ var outputTransactionFormatter = function (tx){
return tx;
};
/**
* Formats the output of a transaction receipt to its proper values
*
* @method outputTransactionReceiptFormatter
* @param {Object} receipt
* @returns {Object}
*/
var outputTransactionReceiptFormatter = function (receipt){
if(receipt.blockNumber !== null)
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
if(receipt.transactionIndex !== null)
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
if(utils.isArray(receipt.logs)) {
receipt.logs = receipt.logs.map(function(log){
return outputLogFormatter(log);
});
}
return receipt;
};
/**
* Formats the output of a block to its proper values
*
* @method outputBlockFormatter
* @param {Object} block object
* @returns {Object} block object
* @param {Object} block
* @returns {Object}
*/
var outputBlockFormatter = function(block) {
@ -2926,6 +3058,7 @@ module.exports = {
inputPostFormatter: inputPostFormatter,
outputBigNumberFormatter: outputBigNumberFormatter,
outputTransactionFormatter: outputTransactionFormatter,
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
outputBlockFormatter: outputBlockFormatter,
outputLogFormatter: outputLogFormatter,
outputPostFormatter: outputPostFormatter
@ -3191,12 +3324,11 @@ module.exports = SolidityFunction;
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2014
* @date 2015
*/
"use strict";
// resolves the problem for electron/atom shell environments, which use node integration, but have no process variable available
var XMLHttpRequest = (typeof window !== 'undefined' && window.XMLHttpRequest) ? window.XMLHttpRequest : require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
var errors = require('./errors');
@ -3204,6 +3336,25 @@ var HttpProvider = function (host) {
this.host = host || 'http://localhost:8545';
};
HttpProvider.prototype.isConnected = function() {
var request = new XMLHttpRequest();
request.open('POST', this.host, false);
request.setRequestHeader('Content-type','application/json');
try {
request.send(JSON.stringify({
id: 9999999999,
jsonrpc: '2.0',
method: 'net_listening',
params: []
}));
return true;
} catch(e) {
return false;
}
};
HttpProvider.prototype.send = function (payload) {
var request = new XMLHttpRequest();
@ -3228,7 +3379,7 @@ HttpProvider.prototype.send = function (payload) {
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
throw errors.InvalidResponse(request.responseText);
}
return result;
@ -3244,7 +3395,7 @@ HttpProvider.prototype.sendAsync = function (payload, callback) {
try {
result = JSON.parse(result);
} catch(e) {
error = errors.InvalidResponse(result);
error = errors.InvalidResponse(request.responseText);
}
callback(error, result);
@ -3391,6 +3542,219 @@ module.exports = ICAP;
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 ipcprovider.js
* @authors:
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
"use strict";
var utils = require('../utils/utils');
var errors = require('./errors');
var errorTimeout = '{"jsonrpc": "2.0", "error": {"code": -32603, "message": "IPC Request timed out for method \'__method__\'"}, "id": "__id__"}';
var IpcProvider = function (path, net) {
var _this = this;
this.responseCallbacks = {};
this.path = path;
net = net || require('net');
this.connection = net.connect({path: this.path});
this.connection.on('error', function(e){
console.error('IPC Connection Error', e);
_this._timeout();
});
this.connection.on('end', function(){
_this._timeout();
});
// LISTEN FOR CONNECTION RESPONSES
this.connection.on('data', function(data) {
/*jshint maxcomplexity: 6 */
_this._parseResponse(data.toString()).forEach(function(result){
var id = null;
// get the id which matches the returned id
if(utils.isArray(result)) {
result.forEach(function(load){
if(_this.responseCallbacks[load.id])
id = load.id;
});
} else {
id = result.id;
}
// fire the callback
if(_this.responseCallbacks[id]) {
_this.responseCallbacks[id](null, result);
delete _this.responseCallbacks[id];
}
});
});
};
/**
Will parse the response and make an array out of it.
@method _parseResponse
@param {String} data
*/
IpcProvider.prototype._parseResponse = function(data) {
var _this = this,
returnValues = [];
// DE-CHUNKER
var dechunkedData = data
.replace(/\}\{/g,'}|--|{') // }{
.replace(/\}\]\[\{/g,'}]|--|[{') // }][{
.replace(/\}\[\{/g,'}|--|[{') // }[{
.replace(/\}\]\{/g,'}]|--|{') // }]{
.split('|--|');
dechunkedData.forEach(function(data){
// prepend the last chunk
if(_this.lastChunk)
data = _this.lastChunk + data;
var result = null;
try {
result = JSON.parse(data);
} catch(e) {
_this.lastChunk = data;
// start timeout to cancel all requests
clearTimeout(_this.lastChunkTimeout);
_this.lastChunkTimeout = setTimeout(function(){
_this.timeout();
throw errors.InvalidResponse(data);
}, 1000 * 15);
return;
}
// cancel timeout and set chunk to null
clearTimeout(_this.lastChunkTimeout);
_this.lastChunk = null;
if(result)
returnValues.push(result);
});
return returnValues;
};
/**
Get the adds a callback to the responseCallbacks object,
which will be called if a response matching the response Id will arrive.
@method _addResponseCallback
*/
IpcProvider.prototype._addResponseCallback = function(payload, callback) {
var id = payload.id || payload[0].id;
var method = payload.method || payload[0].method;
this.responseCallbacks[id] = callback;
this.responseCallbacks[id].method = method;
};
/**
Timeout all requests when the end/error event is fired
@method _timeout
*/
IpcProvider.prototype._timeout = function() {
for(var key in this.responseCallbacks) {
if(this.responseCallbacks.hasOwnProperty(key)){
this.responseCallbacks[key](errorTimeout.replace('__id__', key).replace('__method__', this.responseCallbacks[key].method));
delete this.responseCallbacks[key];
}
}
};
/**
Check if the current connection is still valid.
@method isConnected
*/
IpcProvider.prototype.isConnected = function() {
var _this = this;
// try reconnect, when connection is gone
if(!_this.connection.writable)
_this.connection.connect({path: _this.path});
return !!this.connection.writable;
};
IpcProvider.prototype.send = function (payload) {
if(this.connection.writeSync) {
var result;
// try reconnect, when connection is gone
if(!this.connection.writable)
this.connection.connect({path: this.path});
var data = this.connection.writeSync(JSON.stringify(payload));
try {
result = JSON.parse(data);
} catch(e) {
throw errors.InvalidResponse(data);
}
return result;
} else {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
}
};
IpcProvider.prototype.sendAsync = function (payload, callback) {
// try reconnect, when connection is gone
if(!this.connection.writable)
this.connection.connect({path: this.path});
this.connection.write(JSON.stringify(payload));
this._addResponseCallback(payload, callback);
};
module.exports = IpcProvider;
},{"../utils/utils":7,"./errors":14,"net":32}],23:[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 jsonrpc.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
@ -3467,7 +3831,7 @@ Jsonrpc.prototype.toBatchPayload = function (messages) {
module.exports = Jsonrpc;
},{}],23:[function(require,module,exports){
},{}],24:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3564,7 +3928,7 @@ Method.prototype.formatInput = function (args) {
* @return {Object}
*/
Method.prototype.formatOutput = function (result) {
return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
return this.outputFormatter && result ? this.outputFormatter(result) : result;
};
/**
@ -3641,7 +4005,7 @@ Method.prototype.send = function () {
module.exports = Method;
},{"../utils/utils":7,"./errors":14,"./requestmanager":28}],24:[function(require,module,exports){
},{"../utils/utils":7,"./errors":14,"./requestmanager":28}],25:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3689,7 +4053,7 @@ var abi = [
module.exports = contract(abi).at(address);
},{"./contract":12}],25:[function(require,module,exports){
},{"./contract":12}],26:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3739,7 +4103,7 @@ module.exports = {
};
},{"../utils/utils":7,"./property":26}],26:[function(require,module,exports){
},{"../utils/utils":7,"./property":27}],27:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3764,6 +4128,7 @@ module.exports = {
*/
var RequestManager = require('./requestmanager');
var utils = require('../utils/utils');
var Property = function (options) {
this.name = options.name;
@ -3795,6 +4160,19 @@ Property.prototype.formatOutput = function (result) {
return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
};
/**
* Should be used to extract callback from array of arguments. Modifies input param
*
* @method extractCallback
* @param {Array} arguments
* @return {Function|Null} callback, if exists
*/
Property.prototype.extractCallback = function (args) {
if (utils.isFunction(args[args.length - 1])) {
return args.pop(); // modify the args array!
}
};
/**
* Should attach function to method
*
@ -3821,7 +4199,10 @@ Property.prototype.attachToObject = function (obj) {
return prefix + name.charAt(0).toUpperCase() + name.slice(1);
};
obj[toAsyncName('get', name)] = this.getAsync.bind(this);
var func = this.getAsync.bind(this);
func.request = this.request.bind(this);
obj[toAsyncName('get', name)] = func;
};
/**
@ -3854,45 +4235,27 @@ Property.prototype.getAsync = function (callback) {
});
};
module.exports = Property;
},{"./requestmanager":28}],27:[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 qtsync.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* @date 2014
/**
* Should be called to create pure JSONRPC request which can be used in batch request
*
* @method request
* @param {...} params
* @return {Object} jsonrpc request
*/
var QtSyncProvider = function () {
Property.prototype.request = function () {
var payload = {
method: this.getter,
params: [],
callback: this.extractCallback(Array.prototype.slice.call(arguments))
};
QtSyncProvider.prototype.send = function (payload) {
var result = navigator.qt.callMethod(JSON.stringify(payload));
return JSON.parse(result);
payload.format = this.formatOutput.bind(this);
return payload;
};
module.exports = QtSyncProvider;
module.exports = Property;
},{}],28:[function(require,module,exports){
},{"../utils/utils":7,"./requestmanager":28}],28:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4157,7 +4520,7 @@ RequestManager.prototype.poll = function () {
module.exports = RequestManager;
},{"../utils/config":5,"../utils/utils":7,"./errors":14,"./jsonrpc":22}],29:[function(require,module,exports){
},{"../utils/config":5,"../utils/utils":7,"./errors":14,"./jsonrpc":23}],29:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4227,7 +4590,7 @@ module.exports = {
};
},{"./formatters":18,"./method":23}],30:[function(require,module,exports){
},{"./formatters":18,"./method":24}],30:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4323,7 +4686,7 @@ var deposit = function (from, address, value, client, callback) {
module.exports = transfer;
},{"../web3":9,"./contract":12,"./icap":21,"./namereg":24}],31:[function(require,module,exports){
},{"../web3":9,"./contract":12,"./icap":21,"./namereg":25}],31:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -4439,7 +4802,7 @@ module.exports = {
};
},{"./method":23}],32:[function(require,module,exports){
},{"./method":24}],32:[function(require,module,exports){
},{}],33:[function(require,module,exports){
;(function (root, factory) {
@ -8500,8 +8863,10 @@ module.exports = {
},{"crypto":32}],"web3":[function(require,module,exports){
var web3 = require('./lib/web3');
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
web3.providers.IpcProvider = require('./lib/web3/ipcprovider');
web3.eth.contract = require('./lib/web3/contract');
web3.eth.namereg = require('./lib/web3/namereg');
web3.eth.sendIBANTransaction = require('./lib/web3/transfer');
@ -8514,5 +8879,5 @@ if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
module.exports = web3;
},{"./lib/web3":9,"./lib/web3/contract":12,"./lib/web3/httpprovider":20,"./lib/web3/namereg":24,"./lib/web3/qtsync":27,"./lib/web3/transfer":30}]},{},["web3"])
},{"./lib/web3":9,"./lib/web3/contract":12,"./lib/web3/httpprovider":20,"./lib/web3/ipcprovider":22,"./lib/web3/namereg":25,"./lib/web3/transfer":30}]},{},["web3"])
//# sourceMappingURL=web3.js.map

34
libjsqrc/ethereumjs/dist/web3.js.map

File diff suppressed because one or more lines are too long

6
libjsqrc/ethereumjs/dist/web3.min.js

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/example/balance.html

@ -16,7 +16,7 @@
document.getElementById('coinbase').innerText = 'coinbase: ' + coinbase;
document.getElementById('original').innerText = ' original balance: ' + originalBalance + ' watching...';
web3.eth.filter('pending').watch(function() {
web3.eth.filter('latest').watch(function() {
var currentBalance = web3.eth.getBalance(coinbase).toNumber();
document.getElementById("current").innerText = 'current: ' + currentBalance;
document.getElementById("diff").innerText = 'diff: ' + (currentBalance - originalBalance);

21
libjsqrc/ethereumjs/example/contract.html

@ -31,25 +31,22 @@
// let's assume that coinbase is our account
web3.eth.defaultAccount = web3.eth.coinbase;
var watch = web3.eth.filter('latest');
// create contract
myContract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if(err) {
console.error(err);
return;
// callback fires twice, we only want the second call when the contract is deployed
} else if(contract.address){
if (contractMined) {
myContract = contract;
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
}
});
}
function callExampleContract() {

22
libjsqrc/ethereumjs/example/contract_array.html

@ -31,25 +31,23 @@
// let's assume that coinbase is our account
web3.eth.defaultAccount = web3.eth.coinbase;
var watch = web3.eth.filter('latest');
// create contract
myContract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + myContract.address);
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);
web3.eth.contract(abi).new({data: code}, function (err, contract) {
if (err) {
console.error(err);
return;
// callback fires twice, we only want the second call when the contract is deployed
} else if(contract.address){
myContract = contract;
console.log('address: ' + myContract.address);
if (contractMined) {
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
}
});
}
function callExampleContract() {

28
libjsqrc/ethereumjs/example/event_inc.html

@ -35,29 +35,25 @@
// let's assume that we have a private key to coinbase ;)
web3.eth.defaultAccount = web3.eth.coinbase;
var watch = web3.eth.filter('latest');
contract = web3.eth.contract(abi).new({data: code});
console.log('address: ' + contract.address);
document.getElementById('create').style.visibility = 'hidden';
document.getElementById('status').innerText = "transaction sent, waiting for confirmation";
watch.watch(function (err, hash) {
var block = web3.eth.getBlock(hash, true);
var contractMined = block.transactions.reduce(function (mined, th) {
// TODO: compiled code do not have 0x prefix
return mined || (th.from === web3.eth.defaultAccount && th.input.indexOf(code) !== -1);
}, false);
if (contractMined) {
web3.eth.contract(abi).new({data: code}, function (err, c) {
if (err) {
console.error(err);
return;
// callback fires twice, we only want the second call when the contract is deployed
} else if(contract.address){
contract = c;
console.log('address: ' + contract.address);
document.getElementById('status').innerText = 'Mined!';
document.getElementById('call').style.visibility = 'visible';
inc = contract.Incremented({odd: true}, update);
}
});
inc = contract.Incremented({odd: true});
inc.watch(update);
};
var counter = 0;

4
libjsqrc/ethereumjs/index.js

@ -1,6 +1,8 @@
var web3 = require('./lib/web3');
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
web3.providers.IpcProvider = require('./lib/web3/ipcprovider');
web3.eth.contract = require('./lib/web3/contract');
web3.eth.namereg = require('./lib/web3/namereg');
web3.eth.sendIBANTransaction = require('./lib/web3/transfer');

2
libjsqrc/ethereumjs/lib/version.json

@ -1,3 +1,3 @@
{
"version": "0.7.1"
"version": "0.9.0"
}

3
libjsqrc/ethereumjs/lib/web3.js

@ -101,6 +101,9 @@ web3.setProvider = function (provider) {
this.currentProvider = provider;
RequestManager.getInstance().setProvider(provider);
};
web3.isConnected = function(){
return (this.currentProvider && this.currentProvider.isConnected());
};
web3.reset = function () {
RequestManager.getInstance().reset();
c.defaultBlock = 'latest';

1
libjsqrc/ethereumjs/lib/web3/allevents.js

@ -42,7 +42,6 @@ AllSolidityEvents.prototype.encode = function (options) {
result[f] = formatters.inputBlockNumberFormatter(options[f]);
});
result.topics = [null, null, null, null, null]; // match all topics
result.address = this._address;
return result;

11
libjsqrc/ethereumjs/lib/web3/batch.js

@ -21,6 +21,8 @@
*/
var RequestManager = require('./requestmanager');
var Jsonrpc = require('./jsonrpc');
var errors = require('./errors');
var Batch = function () {
this.requests = [];
@ -47,11 +49,14 @@ Batch.prototype.execute = function () {
results = results || [];
requests.map(function (request, index) {
return results[index] || {};
}).map(function (result, index) {
return requests[index].format ? requests[index].format(result.result) : result.result;
}).forEach(function (result, index) {
if (requests[index].callback) {
requests[index].callback(err, result);
if (!Jsonrpc.getInstance().isValidResponse(result)) {
return requests[index].callback(errors.InvalidResponse(result));
}
requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
}
});
});

117
libjsqrc/ethereumjs/lib/web3/contract.js

@ -96,6 +96,79 @@ var contract = function (abi) {
return new ContractFactory(abi);
};
/**
* Should be called to check if the contract gets properly deployed on the blockchain.
*
* @method checkForContractAddress
* @param {Object} contract
* @param {Function} callback
* @returns {Undefined}
*/
var checkForContractAddress = function(contract, abi, callback){
var count = 0,
callbackFired = false;
// wait for receipt
var filter = web3.eth.filter('latest', function(e){
if(!e && !callbackFired) {
count++;
// console.log('Checking for contract address', count);
// stop watching after 50 blocks (timeout)
if(count > 50) {
filter.stopWatching();
callbackFired = true;
if(callback)
callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
else
throw new Error('Contract transaction couldn\'t be found after 50 blocks');
} else {
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
if(receipt && !callbackFired) {
web3.eth.getCode(receipt.contractAddress, function(e, code){
/*jshint maxcomplexity: 5 */
if(callbackFired)
return;
filter.stopWatching();
callbackFired = true;
if(code.length > 2) {
// console.log('Contract code deployed!');
contract.address = receipt.contractAddress;
// attach events and methods
addFunctionsToContract(contract, abi);
addEventsToContract(contract, abi);
// call callback for the second time
if(callback)
callback(null, contract);
} else {
if(callback)
callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
else
throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
}
});
}
});
}
}
});
};
/**
* Should be called to create new ContractFactory instance
*
@ -114,10 +187,12 @@ var ContractFactory = function (abi) {
* @param {Any} contract constructor param2 (optional)
* @param {Object} contract transaction object (required)
* @param {Function} callback
* @returns {Contract} returns contract if no callback was passed,
* otherwise calls callback function (err, contract)
* @returns {Contract} returns contract instance
*/
ContractFactory.prototype.new = function () {
var _this = this;
var contract = new Contract(this.abi);
// parse arguments
var options = {}; // required!
var callback;
@ -137,18 +212,31 @@ ContractFactory.prototype.new = function () {
var bytes = encodeConstructorParams(this.abi, args);
options.data += bytes;
if (!callback) {
var address = web3.eth.sendTransaction(options);
return this.at(address);
}
var self = this;
web3.eth.sendTransaction(options, function (err, address) {
if(callback) {
// wait for the contract address adn check if the code was deployed
web3.eth.sendTransaction(options, function (err, hash) {
if (err) {
callback(err);
} else {
// add the transaction hash
contract.transactionHash = hash;
// call callback for the first time
callback(null, contract);
checkForContractAddress(contract, _this.abi, callback);
}
self.at(address, callback);
});
} else {
var hash = web3.eth.sendTransaction(options);
// add the transaction hash
contract.transactionHash = hash;
checkForContractAddress(contract, _this.abi);
}
return contract;
};
/**
@ -161,12 +249,17 @@ ContractFactory.prototype.new = function () {
* otherwise calls callback function (err, contract)
*/
ContractFactory.prototype.at = function (address, callback) {
var contract = new Contract(this.abi, address);
// TODO: address is required
// attach functions
addFunctionsToContract(contract, this.abi);
addEventsToContract(contract, this.abi);
if (callback) {
callback(null, new Contract(this.abi, address));
callback(null, contract);
}
return new Contract(this.abi, address);
return contract;
};
/**
@ -178,8 +271,6 @@ ContractFactory.prototype.at = function (address, callback) {
*/
var Contract = function (abi, address) {
this.address = address;
addFunctionsToContract(this, abi);
addEventsToContract(this, abi);
};
module.exports = contract;

2
libjsqrc/ethereumjs/lib/web3/errors.js

@ -31,7 +31,7 @@ module.exports = {
return new Error('Providor not set or invalid');
},
InvalidResponse: function (result){
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response';
var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: '+ result;
return new Error(message);
}
};

16
libjsqrc/ethereumjs/lib/web3/eth.js

@ -152,6 +152,13 @@ var getTransactionFromBlock = new Method({
outputFormatter: formatters.outputTransactionFormatter
});
var getTransactionReceipt = new Method({
name: 'getTransactionReceipt',
call: 'eth_getTransactionReceipt',
params: 1,
outputFormatter: formatters.outputTransactionReceiptFormatter
});
var getTransactionCount = new Method({
name: 'getTransactionCount',
call: 'eth_getTransactionCount',
@ -160,6 +167,13 @@ var getTransactionCount = new Method({
outputFormatter: utils.toDecimal
});
var sendRawTransaction = new Method({
name: 'sendRawTransaction',
call: 'eth_sendRawTransaction',
params: 1,
inputFormatter: [null]
});
var sendTransaction = new Method({
name: 'sendTransaction',
call: 'eth_sendTransaction',
@ -223,9 +237,11 @@ var methods = [
getBlockUncleCount,
getTransaction,
getTransactionFromBlock,
getTransactionReceipt,
getTransactionCount,
call,
estimateGas,
sendRawTransaction,
sendTransaction,
compileSolidity,
compileLLL,

2
libjsqrc/ethereumjs/lib/web3/event.js

@ -103,8 +103,8 @@ SolidityEvent.prototype.encode = function (indexed, options) {
result.topics = [];
if (!this._anonymous) {
result.address = this._address;
if (!this._anonymous) {
result.topics.push('0x' + this.signature());
}

2
libjsqrc/ethereumjs/lib/web3/filter.js

@ -90,9 +90,11 @@ var getLogsAtStart = function(self, callback){
callback(err);
}
if(utils.isArray(messages)) {
messages.forEach(function (message) {
callback(null, message);
});
}
});
}
};

33
libjsqrc/ethereumjs/lib/web3/formatters.js

@ -85,8 +85,8 @@ var inputTransactionFormatter = function (options){
* Formats the output of a transaction to its proper values
*
* @method outputTransactionFormatter
* @param {Object} transaction
* @returns {Object} transaction
* @param {Object} tx
* @returns {Object}
*/
var outputTransactionFormatter = function (tx){
if(tx.blockNumber !== null)
@ -100,12 +100,36 @@ var outputTransactionFormatter = function (tx){
return tx;
};
/**
* Formats the output of a transaction receipt to its proper values
*
* @method outputTransactionReceiptFormatter
* @param {Object} receipt
* @returns {Object}
*/
var outputTransactionReceiptFormatter = function (receipt){
if(receipt.blockNumber !== null)
receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
if(receipt.transactionIndex !== null)
receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
if(utils.isArray(receipt.logs)) {
receipt.logs = receipt.logs.map(function(log){
return outputLogFormatter(log);
});
}
return receipt;
};
/**
* Formats the output of a block to its proper values
*
* @method outputBlockFormatter
* @param {Object} block object
* @returns {Object} block object
* @param {Object} block
* @returns {Object}
*/
var outputBlockFormatter = function(block) {
@ -213,6 +237,7 @@ module.exports = {
inputPostFormatter: inputPostFormatter,
outputBigNumberFormatter: outputBigNumberFormatter,
outputTransactionFormatter: outputTransactionFormatter,
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
outputBlockFormatter: outputBlockFormatter,
outputLogFormatter: outputLogFormatter,
outputPostFormatter: outputPostFormatter

26
libjsqrc/ethereumjs/lib/web3/httpprovider.js

@ -19,12 +19,11 @@
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2014
* @date 2015
*/
"use strict";
// resolves the problem for electron/atom shell environments, which use node integration, but have no process variable available
var XMLHttpRequest = (typeof window !== 'undefined' && window.XMLHttpRequest) ? window.XMLHttpRequest : require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
var errors = require('./errors');
@ -32,6 +31,25 @@ var HttpProvider = function (host) {
this.host = host || 'http://localhost:8545';
};
HttpProvider.prototype.isConnected = function() {
var request = new XMLHttpRequest();
request.open('POST', this.host, false);
request.setRequestHeader('Content-type','application/json');
try {
request.send(JSON.stringify({
id: 9999999999,
jsonrpc: '2.0',
method: 'net_listening',
params: []
}));
return true;
} catch(e) {
return false;
}
};
HttpProvider.prototype.send = function (payload) {
var request = new XMLHttpRequest();
@ -56,7 +74,7 @@ HttpProvider.prototype.send = function (payload) {
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
throw errors.InvalidResponse(request.responseText);
}
return result;
@ -72,7 +90,7 @@ HttpProvider.prototype.sendAsync = function (payload, callback) {
try {
result = JSON.parse(result);
} catch(e) {
error = errors.InvalidResponse(result);
error = errors.InvalidResponse(request.responseText);
}
callback(error, result);

211
libjsqrc/ethereumjs/lib/web3/ipcprovider.js

@ -0,0 +1,211 @@
/*
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 ipcprovider.js
* @authors:
* Fabian Vogelsteller <fabian@ethdev.com>
* @date 2015
*/
"use strict";
var utils = require('../utils/utils');
var errors = require('./errors');
var errorTimeout = '{"jsonrpc": "2.0", "error": {"code": -32603, "message": "IPC Request timed out for method \'__method__\'"}, "id": "__id__"}';
var IpcProvider = function (path, net) {
var _this = this;
this.responseCallbacks = {};
this.path = path;
net = net || require('net');
this.connection = net.connect({path: this.path});
this.connection.on('error', function(e){
console.error('IPC Connection Error', e);
_this._timeout();
});
this.connection.on('end', function(){
_this._timeout();
});
// LISTEN FOR CONNECTION RESPONSES
this.connection.on('data', function(data) {
/*jshint maxcomplexity: 6 */
_this._parseResponse(data.toString()).forEach(function(result){
var id = null;
// get the id which matches the returned id
if(utils.isArray(result)) {
result.forEach(function(load){
if(_this.responseCallbacks[load.id])
id = load.id;
});
} else {
id = result.id;
}
// fire the callback
if(_this.responseCallbacks[id]) {
_this.responseCallbacks[id](null, result);
delete _this.responseCallbacks[id];
}
});
});
};
/**
Will parse the response and make an array out of it.
@method _parseResponse
@param {String} data
*/
IpcProvider.prototype._parseResponse = function(data) {
var _this = this,
returnValues = [];
// DE-CHUNKER
var dechunkedData = data
.replace(/\}\{/g,'}|--|{') // }{
.replace(/\}\]\[\{/g,'}]|--|[{') // }][{
.replace(/\}\[\{/g,'}|--|[{') // }[{
.replace(/\}\]\{/g,'}]|--|{') // }]{
.split('|--|');
dechunkedData.forEach(function(data){
// prepend the last chunk
if(_this.lastChunk)
data = _this.lastChunk + data;
var result = null;
try {
result = JSON.parse(data);
} catch(e) {
_this.lastChunk = data;
// start timeout to cancel all requests
clearTimeout(_this.lastChunkTimeout);
_this.lastChunkTimeout = setTimeout(function(){
_this.timeout();
throw errors.InvalidResponse(data);
}, 1000 * 15);
return;
}
// cancel timeout and set chunk to null
clearTimeout(_this.lastChunkTimeout);
_this.lastChunk = null;
if(result)
returnValues.push(result);
});
return returnValues;
};
/**
Get the adds a callback to the responseCallbacks object,
which will be called if a response matching the response Id will arrive.
@method _addResponseCallback
*/
IpcProvider.prototype._addResponseCallback = function(payload, callback) {
var id = payload.id || payload[0].id;
var method = payload.method || payload[0].method;
this.responseCallbacks[id] = callback;
this.responseCallbacks[id].method = method;
};
/**
Timeout all requests when the end/error event is fired
@method _timeout
*/
IpcProvider.prototype._timeout = function() {
for(var key in this.responseCallbacks) {
if(this.responseCallbacks.hasOwnProperty(key)){
this.responseCallbacks[key](errorTimeout.replace('__id__', key).replace('__method__', this.responseCallbacks[key].method));
delete this.responseCallbacks[key];
}
}
};
/**
Check if the current connection is still valid.
@method isConnected
*/
IpcProvider.prototype.isConnected = function() {
var _this = this;
// try reconnect, when connection is gone
if(!_this.connection.writable)
_this.connection.connect({path: _this.path});
return !!this.connection.writable;
};
IpcProvider.prototype.send = function (payload) {
if(this.connection.writeSync) {
var result;
// try reconnect, when connection is gone
if(!this.connection.writable)
this.connection.connect({path: this.path});
var data = this.connection.writeSync(JSON.stringify(payload));
try {
result = JSON.parse(data);
} catch(e) {
throw errors.InvalidResponse(data);
}
return result;
} else {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
}
};
IpcProvider.prototype.sendAsync = function (payload, callback) {
// try reconnect, when connection is gone
if(!this.connection.writable)
this.connection.connect({path: this.path});
this.connection.write(JSON.stringify(payload));
this._addResponseCallback(payload, callback);
};
module.exports = IpcProvider;

2
libjsqrc/ethereumjs/lib/web3/method.js

@ -94,7 +94,7 @@ Method.prototype.formatInput = function (args) {
* @return {Object}
*/
Method.prototype.formatOutput = function (result) {
return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
return this.outputFormatter && result ? this.outputFormatter(result) : result;
};
/**

36
libjsqrc/ethereumjs/lib/web3/property.js

@ -22,6 +22,7 @@
*/
var RequestManager = require('./requestmanager');
var utils = require('../utils/utils');
var Property = function (options) {
this.name = options.name;
@ -53,6 +54,19 @@ Property.prototype.formatOutput = function (result) {
return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
};
/**
* Should be used to extract callback from array of arguments. Modifies input param
*
* @method extractCallback
* @param {Array} arguments
* @return {Function|Null} callback, if exists
*/
Property.prototype.extractCallback = function (args) {
if (utils.isFunction(args[args.length - 1])) {
return args.pop(); // modify the args array!
}
};
/**
* Should attach function to method
*
@ -79,7 +93,10 @@ Property.prototype.attachToObject = function (obj) {
return prefix + name.charAt(0).toUpperCase() + name.slice(1);
};
obj[toAsyncName('get', name)] = this.getAsync.bind(this);
var func = this.getAsync.bind(this);
func.request = this.request.bind(this);
obj[toAsyncName('get', name)] = func;
};
/**
@ -112,5 +129,22 @@ Property.prototype.getAsync = function (callback) {
});
};
/**
* Should be called to create pure JSONRPC request which can be used in batch request
*
* @method request
* @param {...} params
* @return {Object} jsonrpc request
*/
Property.prototype.request = function () {
var payload = {
method: this.getter,
params: [],
callback: this.extractCallback(Array.prototype.slice.call(arguments))
};
payload.format = this.formatOutput.bind(this);
return payload;
};
module.exports = Property;

33
libjsqrc/ethereumjs/lib/web3/qtsync.js

@ -1,33 +0,0 @@
/*
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 qtsync.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Marian Oancea <marian@ethdev.com>
* @date 2014
*/
var QtSyncProvider = function () {
};
QtSyncProvider.prototype.send = function (payload) {
var result = navigator.qt.callMethod(JSON.stringify(payload));
return JSON.parse(result);
};
module.exports = QtSyncProvider;

2
libjsqrc/ethereumjs/package.js

@ -1,7 +1,7 @@
/* jshint ignore:start */
Package.describe({
name: 'ethereum:web3',
version: '0.7.1',
version: '0.9.0',
summary: 'Ethereum JavaScript API, middleware to talk to a ethreum node over RPC',
git: 'https://github.com/ethereum/ethereum.js',
// By default, Meteor will default to using README.md for documentation.

22
libjsqrc/ethereumjs/package.json

@ -1,7 +1,7 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "0.7.1",
"version": "0.9.0",
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
"main": "./index.js",
"directories": {
@ -56,30 +56,30 @@
],
"author": "ethdev.com",
"authors": [
{
"name": "Jeffery Wilcke",
"email": "jeff@ethdev.com",
"url": "https://github.com/obscuren"
},
{
"name": "Marek Kotewicz",
"email": "marek@ethdev.com",
"url": "https://github.com/debris"
},
{
"name": "Fabian Vogelsteller",
"email": "fabian@ethdev.com",
"homepage": "http://frozeman.de"
},
{
"name": "Marian Oancea",
"email": "marian@ethdev.com",
"url": "https://github.com/cubedro"
},
{
"name": "Fabian Vogelsteller",
"email": "fabian@frozeman.de",
"homepage": "http://frozeman.de"
},
{
"name": "Gav Wood",
"email": "g@ethdev.com",
"homepage": "http://gavwood.com"
},
{
"name": "Jeffery Wilcke",
"email": "jeff@ethdev.com",
"url": "https://github.com/obscuren"
}
],
"license": "LGPL-3.0"

1741
libjsqrc/ethereumjs/styleguide.md

File diff suppressed because it is too large

98
libjsqrc/ethereumjs/test/batch.js

@ -44,7 +44,45 @@ describe('lib/web3/batch', function () {
batch.execute();
});
it('should execute batch request', function (done) {
it('should execute batch request for async properties', function (done) {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset();
var result = [];
var result2 = '0xb';
provider.injectBatchResults([result, result2]);
var counter = 0;
var callback = function (err, r) {
counter++;
assert.isArray(result, r);
};
var callback2 = function (err, r) {
assert.equal(counter, 1);
assert.equal(r, 11);
done();
};
provider.injectValidation(function (payload) {
var first = payload[0];
var second = payload[1];
assert.equal(first.method, 'eth_accounts');
assert.deepEqual(first.params, []);
assert.equal(second.method, 'net_peerCount');
assert.deepEqual(second.params, []);
});
var batch = web3.createBatch();
batch.add(web3.eth.getAccounts.request(callback));
batch.add(web3.net.getPeerCount.request(callback2));
batch.execute();
});
it('should execute batch request with contract', function (done) {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
@ -100,6 +138,64 @@ describe('lib/web3/batch', function () {
provider.injectBatchResults([result, result2]);
batch.execute();
});
it('should execute batch requests and receive errors', function (done) {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset();
var abi = [{
"name": "balance(address)",
"type": "function",
"inputs": [{
"name": "who",
"type": "address"
}],
"constant": true,
"outputs": [{
"name": "value",
"type": "uint256"
}]
}];
var address = '0x1000000000000000000000000000000000000001';
var result = 'Something went wrong';
var result2 = 'Something went wrong 2';
var counter = 0;
var callback = function (err, r) {
counter++;
assert.isNotNull(err);
};
var callback2 = function (err, r) {
assert.equal(counter, 1);
assert.isNotNull(err);
done();
};
provider.injectValidation(function (payload) {
var first = payload[0];
var second = payload[1];
assert.equal(first.method, 'eth_getBalance');
assert.deepEqual(first.params, ['0x0000000000000000000000000000000000000000', 'latest']);
assert.equal(second.method, 'eth_call');
assert.deepEqual(second.params, [{
'to': '0x1000000000000000000000000000000000000001',
'data': '0xe3d670d70000000000000000000000001000000000000000000000000000000000000001'
}]);
});
var batch = web3.createBatch();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', callback));
batch.add(web3.eth.contract(abi).at(address).balance.request(address, callback2));
provider.injectBatchResults([result, result2], true); // injects error
batch.execute();
});
});
});

8
libjsqrc/ethereumjs/test/contract.js

@ -209,13 +209,7 @@ describe('web3.eth.contract', function () {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_newFilter');
assert.deepEqual(payload.params[0], {
topics: [
null,
null,
null,
null,
null
],
topics: [],
address: '0x1234567890123456789012345678901234567890'
});
} else if (step === 1) {

17
libjsqrc/ethereumjs/test/errors.js

@ -0,0 +1,17 @@
var chai = require('chai');
var assert = chai.assert;
var errors = require('../lib/web3/errors');
describe('lib/web3/method', function () {
describe('getCall', function () {
for(var key in errors) {
it('should return and error', function () {
assert.instanceOf(errors[key](), Error);
});
}
});
});

2
libjsqrc/ethereumjs/test/event.encode.js

@ -184,6 +184,7 @@ var tests = [{
},
options: {},
expected: {
address: address,
topics: [
'0x0000000000000000000000000000000000000000000000000000000000000001'
]
@ -207,6 +208,7 @@ var tests = [{
},
options: {},
expected: {
address: address,
topics: [
null,
'0x0000000000000000000000000000000000000000000000000000000000000001'

18
libjsqrc/ethereumjs/test/helpers/FakeHttpProvider.js

@ -10,6 +10,17 @@ var getResponseStub = function () {
};
};
var getErrorStub = function () {
return {
jsonrpc: '2.0',
id: 1,
error: {
code: 1234,
message: ''
}
};
};
var FakeHttpProvider = function () {
this.response = getResponseStub();
this.error = null;
@ -48,10 +59,15 @@ FakeHttpProvider.prototype.injectResult = function (result) {
this.response.result = result;
};
FakeHttpProvider.prototype.injectBatchResults = function (results) {
FakeHttpProvider.prototype.injectBatchResults = function (results, error) {
this.response = results.map(function (r) {
if(error) {
var response = getErrorStub();
response.error.message = r;
} else {
var response = getResponseStub();
response.result = r;
}
return response;
});
};

41
libjsqrc/ethereumjs/test/helpers/FakeIpcRequest.js

@ -0,0 +1,41 @@
var chai = require('chai');
var assert = chai.assert;
var FakeIpcRequest = function () {
this._handle = {fd: {}};
this.callbacks = [];
return this
};
FakeIpcRequest.prototype.connect = function (path) {
assert.notEqual(path, undefined);
return this;
};
FakeIpcRequest.prototype.on = function(name, callback) {
if(name === 'data'){
this.callbacks.push(callback);
}
};
FakeIpcRequest.prototype.writeSync = function (payload) {
assert.equal(typeof payload, 'string');
return payload;
};
FakeIpcRequest.prototype.write = function (payload) {
assert.equal(typeof payload, 'string');
this.callbacks.forEach(function(cb){
setTimeout(function(){
cb(payload);
}, 100);
});
};
module.exports = new FakeIpcRequest();

8
libjsqrc/ethereumjs/test/httpprovider.js

@ -29,5 +29,13 @@ describe('lib/web3/httpprovider', function () {
});
});
});
describe('isConnected', function () {
it('should return a boolean', function () {
var provider = new HttpProvider();
assert.isBoolean(provider.isConnected());
});
});
});

58
libjsqrc/ethereumjs/test/ipcprovider.js

@ -0,0 +1,58 @@
var chai = require('chai');
var assert = chai.assert;
var SandboxedModule = require('sandboxed-module');
SandboxedModule.registerBuiltInSourceTransformer('istanbul');
var IpcProvider = SandboxedModule.require('../lib/web3/ipcprovider', {
requires: {
'bignumber.js': require('bignumber.js'),
'net': require('./helpers/FakeIpcRequest')
}
});
describe('lib/web3/ipcprovider', function () {
describe('send', function () {
it('should send basic request', function () {
var provider = new IpcProvider();
var result = provider.send({id: 1, method: 'eth_test'});
assert.isObject(result);
});
});
describe('sendAsync', function () {
it('should send basic async request', function (done) {
var provider = new IpcProvider();
provider.sendAsync({id: 1, method: 'eth_test'}, function (err, result) {
assert.isObject(result);
done();
});
});
});
describe('isConnected', function () {
it('should return a boolean', function () {
var provider = new IpcProvider();
assert.isBoolean(provider.isConnected());
});
it('should return false', function () {
var provider = new IpcProvider();
provider.connection.writable = false;
assert.isFalse(provider.isConnected());
});
it('should return true, when a net handle is set', function () {
var provider = new IpcProvider();
provider.connection.writable = true;
assert.isTrue(provider.isConnected());
});
});
});

2
libjsqrc/ethereumjs/test/polling.js

@ -63,8 +63,6 @@ var testPolling = function (tests) {
var filter = web3[test.protocol].filter.apply(null, test.args);
provider.injectBatchResults([test.secondResult]);
filter.watch(function (err, result) {
console.log(err, result);
if (test.err) {
// todo
} else {

22
libjsqrc/ethereumjs/test/qtsyncprovider.js

@ -1,22 +0,0 @@
var chai = require('chai');
var assert = chai.assert;
var SandboxedModule = require('sandboxed-module');
SandboxedModule.registerBuiltInSourceTransformer('istanbul');
var QtSyncProvider = SandboxedModule.require('../lib/web3/qtsync', {
globals: {
navigator: require('./helpers/FakeQtNavigator')
}
});
describe('/lib/web3/qtsyncprovider', function () {
describe('send', function () {
it('should send basic request', function () {
var provider = new QtSyncProvider();
var result = provider.send({});
assert.equal(typeof result, 'object');
});
});
});

14
libjsqrc/ethereumjs/test/web3.eth.contract.js

@ -219,15 +219,27 @@ describe('web3.eth.contract', function() {
]
}];
var steps = 1;
provider.injectResult(address);
provider.injectValidation(function (payload) {
if(steps === 1) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_sendTransaction');
assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
steps++;
} else if(steps === 2) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_newBlockFilter');
done();
}
});
var myCon = contract(description).new(2, {data: code});
contract(description).new(2, {data: code}, function(e, myCon){
});
});
});

2
libjsqrc/ethereumjs/test/web3.eth.getTransaction.js

@ -6,7 +6,6 @@ var testMethod = require('./helpers/test.method.js');
var method = 'getTransaction';
var txResult = {
"status": "mined",
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":"0x5",
"blockHash": "0x6fd9e2a26ab",
@ -20,7 +19,6 @@ var txResult = {
"input":"0x603880600c6000396000f30060"
};
var formattedTxResult = {
"status": "mined",
"hash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"nonce":5,
"blockHash": "0x6fd9e2a26ab",

70
libjsqrc/ethereumjs/test/web3.eth.getTransactionReceipt.js

@ -0,0 +1,70 @@
var chai = require('chai');
var web3 = require('../index');
var BigNumber = require('bignumber.js');
var testMethod = require('./helpers/test.method.js');
var method = 'getTransactionReceipt';
var txResult = {
"blockHash": "0x6fd9e2a26ab",
"blockNumber": "0x15df",
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": "0x1",
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed":"0x7f110",
"gasUsed": "0x7f110",
"logs": [{
transactionIndex: '0x3e8',
logIndex: '0x3e8',
blockNumber: '0x3e8',
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
},{
transactionIndex: null,
logIndex: null,
blockNumber: null,
transactionHash: null,
blockHash: null,
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
}]
};
var formattedTxResult = {
"blockHash": "0x6fd9e2a26ab",
"blockNumber": 5599,
"transactionHash":"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b",
"transactionIndex": 1,
"contractAddress":"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"cumulativeGasUsed": 520464,
"gasUsed": 520464,
"logs": [{
transactionIndex: 1000,
logIndex: 1000,
blockNumber: 1000,
transactionHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
blockHash: '0xd6960376d6c6dea93647383ffb245cfced97ccc5c7525397a543a72fdaea5265',
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
},{
transactionIndex: null,
logIndex: null,
blockNumber: null,
transactionHash: null,
blockHash: null,
data: '0x7b2274657374223a2274657374227',
topics: ['0x68656c6c6f','0x6d79746f70696373']
}]
};
var tests = [{
args: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
formattedArgs: ['0x2dbab4c0612bf9caf4c195085547dc0612bf9caf4c1950855'],
result: txResult,
formattedResult: formattedTxResult,
call: 'eth_'+ method
}];
testMethod.runTests('eth', method, tests);
Loading…
Cancel
Save