Browse Source

Merge commit '60313959de74d8f4786858ee6e5425b7964478e9' into develop

Conflicts:
	libjsqrc/ethereumjs/dist/web3-light.js
	libjsqrc/ethereumjs/dist/web3-light.js.map
	libjsqrc/ethereumjs/dist/web3-light.min.js
	libjsqrc/ethereumjs/dist/web3.js
	libjsqrc/ethereumjs/dist/web3.js.map
	libjsqrc/ethereumjs/dist/web3.min.js
	libjsqrc/ethereumjs/lib/web3/eth.js
cl-refactor
Marek Kotewicz 10 years ago
parent
commit
8c6cd4a38c
  1. 12
      libjsqrc/ethereumjs/README.md
  2. 12
      libjsqrc/ethereumjs/bower.json
  3. 242
      libjsqrc/ethereumjs/dist/web3-light.js
  4. 18
      libjsqrc/ethereumjs/dist/web3-light.js.map
  5. 2
      libjsqrc/ethereumjs/dist/web3-light.min.js
  6. 4095
      libjsqrc/ethereumjs/dist/web3.js
  7. 24
      libjsqrc/ethereumjs/dist/web3.js.map
  8. 4
      libjsqrc/ethereumjs/dist/web3.min.js
  9. 13
      libjsqrc/ethereumjs/index.js
  10. 23
      libjsqrc/ethereumjs/lib/solidity/abi.js
  11. 68
      libjsqrc/ethereumjs/lib/solidity/utils.js
  12. 46
      libjsqrc/ethereumjs/lib/utils/utils.js
  13. 2
      libjsqrc/ethereumjs/lib/version.json
  14. 2
      libjsqrc/ethereumjs/lib/web3.js
  15. 28
      libjsqrc/ethereumjs/lib/web3/contract.js
  16. 8
      libjsqrc/ethereumjs/lib/web3/eth.js
  17. 2
      libjsqrc/ethereumjs/package.js
  18. 8
      libjsqrc/ethereumjs/package.json
  19. 106
      libjsqrc/ethereumjs/test/abi.formatConstructorParams.js
  20. 11
      libjsqrc/ethereumjs/test/abi.inputParser.js
  21. 2
      libjsqrc/ethereumjs/test/utils.filters.js
  22. 2
      libjsqrc/ethereumjs/test/utils.isAddress.js
  23. 23
      libjsqrc/ethereumjs/test/utils.isStrictAddress.js
  24. 49
      libjsqrc/ethereumjs/test/web3.eth.contract.js
  25. 39
      libjsqrc/ethereumjs/test/web3.eth.gasPrice.js
  26. 6
      libjsqrc/ethereumjs/test/web3.eth.getUncle.js

12
libjsqrc/ethereumjs/README.md

@ -17,7 +17,7 @@ You need to run a local ethrereum node to use this library.
### Node.js
$ npm install ethereum.js
$ npm install web3
### Meteor.js
@ -26,20 +26,24 @@ You need to run a local ethrereum node to use this library.
### As Browser module
Bower
$ bower install ethereum.js
$ bower install web3
Component
$ component install ethereum/ethereum.js
$ 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
Require the library (not required for the meteor package):
You can require the library (not required for the meteor package):
var web3 = require('ethereum.js');
Or use it directly from global namespace:
console.log(web3); // {eth: .., shh: ...} // it's here!
Set a provider (QtSyncProvider, HttpProvider)
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

12
libjsqrc/ethereumjs/bower.json

@ -1,22 +1,22 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "0.2.5",
"version": "0.2.6",
"description": "Ethereum Compatible JavaScript API",
"main": [
"./dist/ethereum.js",
"./dist/ethereum.min.js"
"./dist/web3.js",
"./dist/web3.min.js"
],
"dependencies": {
"bignumber.js": ">=2.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ethereum/ethereum.js.git"
"url": "https://github.com/ethereum/web3.js.git"
},
"homepage": "https://github.com/ethereum/ethereum.js",
"homepage": "https://github.com/ethereum/web3.js",
"bugs": {
"url": "https://github.com/ethereum/ethereum.js/issues"
"url": "https://github.com/ethereum/web3.js/issues"
},
"keywords": [
"ethereum",

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

@ -15,10 +15,10 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
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 abi.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Gav Wood <g@ethdev.com>
/**
* @file abi.js
* @author Marek Kotewicz <marek@ethdev.com>
* @author Gav Wood <g@ethdev.com>
* @date 2014
*/
@ -26,6 +26,7 @@ var utils = require('../utils/utils');
var c = require('../utils/config');
var types = require('./types');
var f = require('./formatters');
var solUtils = require('./utils');
/**
* throw incorrect type error
@ -238,14 +239,26 @@ var outputParser = function (json) {
return parser;
};
var formatConstructorParams = function (abi, params) {
var constructor = solUtils.getConstructor(abi, params.length);
if (!constructor) {
if (params.length > 0) {
console.warn("didn't found matching constructor, using default one");
}
return '';
}
return formatInput(constructor.inputs, params);
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser,
formatInput: formatInput,
formatOutput: formatOutput
formatOutput: formatOutput,
formatConstructorParams: formatConstructorParams
};
},{"../utils/config":5,"../utils/utils":6,"./formatters":2,"./types":3}],2:[function(require,module,exports){
},{"../utils/config":6,"../utils/utils":7,"./formatters":2,"./types":3,"./utils":4}],2:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -445,7 +458,7 @@ module.exports = {
};
},{"../utils/config":5,"../utils/utils":6,"bignumber.js":"bignumber.js"}],3:[function(require,module,exports){
},{"../utils/config":6,"../utils/utils":7,"bignumber.js":"bignumber.js"}],3:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -525,6 +538,76 @@ module.exports = {
},{"./formatters":2}],4:[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 utils.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
/**
* Returns the contstructor with matching number of arguments
*
* @method getConstructor
* @param {Array} abi
* @param {Number} numberOfArgs
* @returns {Object} constructor function abi
*/
var getConstructor = function (abi, numberOfArgs) {
return abi.filter(function (f) {
return f.type === 'constructor' && f.inputs.length === numberOfArgs;
})[0];
};
/**
* Filters all functions from input abi
*
* @method filterFunctions
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'function'
*/
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/**
* Filters all events from input abi
*
* @method filterEvents
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'event'
*/
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';
});
};
module.exports = {
getConstructor: getConstructor,
filterFunctions: filterFunctions,
filterEvents: filterEvents
};
},{}],5:[function(require,module,exports){
'use strict';
// go env doesn't have and need XMLHttpRequest
@ -535,7 +618,7 @@ if (typeof XMLHttpRequest === 'undefined') {
}
},{}],5:[function(require,module,exports){
},{}],6:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -606,7 +689,7 @@ module.exports = {
};
},{"bignumber.js":"bignumber.js"}],6:[function(require,module,exports){
},{"bignumber.js":"bignumber.js"}],7:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -770,32 +853,6 @@ var extractTypeName = function (name) {
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
};
/**
* Filters all functions from input abi
*
* @method filterFunctions
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'function'
*/
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/**
* Filters all events from input abi
*
* @method filterEvents
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'event'
*/
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';
});
};
/**
* Converts value to it's decimal representation in string
*
@ -958,14 +1015,25 @@ var toTwosComplement = function (number) {
};
/**
* Checks if the given string has proper length
* Checks if the given string is strictly an address
*
* @method isStrictAddress
* @param {String} address the given HEX adress
* @return {Boolean}
*/
var isStrictAddress = function (address) {
return /^0x[0-9a-f]{40}$/.test(address);
};
/**
* Checks if the given string is an address
*
* @method isAddress
* @param {String} address the given HEX adress
* @return {Boolean}
*/
var isAddress = function (address) {
return /^0x[0-9a-f]{40}$/.test(address);
return /^(0x)?[0-9a-f]{40}$/.test(address);
};
/**
@ -976,7 +1044,7 @@ var isAddress = function (address) {
* @return {String} formatted address
*/
var toAddress = function (address) {
if (isAddress(address)) {
if (isStrictAddress(address)) {
return address;
}
@ -1080,14 +1148,13 @@ module.exports = {
fromAscii: fromAscii,
extractDisplayName: extractDisplayName,
extractTypeName: extractTypeName,
filterFunctions: filterFunctions,
filterEvents: filterEvents,
toWei: toWei,
fromWei: fromWei,
toBigNumber: toBigNumber,
toTwosComplement: toTwosComplement,
toAddress: toAddress,
isBigNumber: isBigNumber,
isStrictAddress: isStrictAddress,
isAddress: isAddress,
isFunction: isFunction,
isString: isString,
@ -1098,12 +1165,12 @@ module.exports = {
};
},{"bignumber.js":"bignumber.js"}],7:[function(require,module,exports){
},{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){
module.exports={
"version": "0.2.5"
"version": "0.2.6"
}
},{}],8:[function(require,module,exports){
},{}],9:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1164,7 +1231,7 @@ var web3Properties = [
}),
new Property({
name: 'version.ethereum',
getter: 'eth_version',
getter: 'eth_protocolVersion',
inputFormatter: utils.toDecimal
}),
new Property({
@ -1259,7 +1326,7 @@ setupMethods(web3.shh, shh.methods);
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":18,"./web3/net":19,"./web3/property":20,"./web3/requestmanager":22,"./web3/shh":23,"./web3/watches":25}],9:[function(require,module,exports){
},{"./utils/config":6,"./utils/utils":7,"./version.json":8,"./web3/db":11,"./web3/eth":13,"./web3/filter":15,"./web3/formatters":16,"./web3/method":19,"./web3/net":20,"./web3/property":21,"./web3/requestmanager":23,"./web3/shh":24,"./web3/watches":26}],10:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1283,8 +1350,9 @@ module.exports = web3;
*/
var web3 = require('../web3');
var abi = require('../solidity/abi');
var solAbi = require('../solidity/abi');
var utils = require('../utils/utils');
var solUtils = require('../solidity/utils');
var eventImpl = require('./event');
var signature = require('./signature');
@ -1304,11 +1372,11 @@ var addFunctionRelatedPropertiesToContract = function (contract) {
};
var addFunctionsToContract = function (contract, desc, address) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
var inputParser = solAbi.inputParser(desc);
var outputParser = solAbi.outputParser(desc);
// create contract functions
utils.filterFunctions(desc).forEach(function (method) {
solUtils.filterFunctions(desc).forEach(function (method) {
var displayName = utils.extractDisplayName(method.name);
var typeName = utils.extractTypeName(method.name);
@ -1360,14 +1428,14 @@ var addFunctionsToContract = function (contract, desc, address) {
var addEventRelatedPropertiesToContract = function (contract, desc, address) {
contract.address = address;
contract._onWatchEventResult = function (data) {
var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc));
var matchingEvent = event.getMatchingEvent(solUtils.filterEvents(desc));
var parser = eventImpl.outputParser(matchingEvent);
return parser(data);
};
Object.defineProperty(contract, 'topics', {
get: function() {
return utils.filterEvents(desc).map(function (e) {
return solUtils.filterEvents(desc).map(function (e) {
return signature.eventSignatureFromAscii(e.name);
});
}
@ -1377,7 +1445,7 @@ var addEventRelatedPropertiesToContract = function (contract, desc, address) {
var addEventsToContract = function (contract, desc, address) {
// create contract events
utils.filterEvents(desc).forEach(function (e) {
solUtils.filterEvents(desc).forEach(function (e) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
@ -1435,7 +1503,7 @@ var contract = function (abi) {
return Contract.bind(null, abi);
};
function Contract(abi, address) {
function Contract(abi, options) {
// workaround for invalid assumption that method.name is the full anonymous prototype of the method.
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous
@ -1449,6 +1517,17 @@ function Contract(abi, address) {
}
});
var address = '';
if (utils.isAddress(options)) {
address = options;
} else { // is a source code!
// TODO, parse the rest of the args
var code = options;
var args = Array.prototype.slice.call(arguments, 2);
var bytes = solAbi.formatConstructorParams(abi, args);
address = web3.eth.sendTransaction({data: code + bytes});
}
var result = {};
addFunctionRelatedPropertiesToContract(result);
addFunctionsToContract(result, abi, address);
@ -1461,7 +1540,7 @@ function Contract(abi, address) {
module.exports = contract;
},{"../solidity/abi":1,"../utils/utils":6,"../web3":8,"./event":13,"./signature":24}],10:[function(require,module,exports){
},{"../solidity/abi":1,"../solidity/utils":4,"../utils/utils":7,"../web3":9,"./event":14,"./signature":25}],11:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1519,7 +1598,7 @@ module.exports = {
methods: methods
};
},{"./method":18}],11:[function(require,module,exports){
},{"./method":19}],12:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1559,7 +1638,7 @@ module.exports = {
};
},{"../utils/utils":6}],12:[function(require,module,exports){
},{"../utils/utils":7}],13:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1664,15 +1743,15 @@ var getBlock = new Method({
name: 'getBlock',
call: blockCall,
params: 2,
inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
inputFormatter: [utils.toHex, function (val) { return !!val; }],
outputFormatter: formatters.outputBlockFormatter
});
var getUncle = new Method({
name: 'getUncle',
call: uncleCall,
params: 3,
inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex, function (val) { return !!val; }],
params: 2,
inputFormatter: [utils.toHex, utils.toHex],
outputFormatter: formatters.outputBlockFormatter,
});
@ -1796,7 +1875,7 @@ var properties = [
new Property({
name: 'gasPrice',
getter: 'eth_gasPrice',
outputFormatter: formatters.inputNumberFormatter
outputFormatter: formatters.outputBigNumberFormatter
}),
new Property({
name: 'accounts',
@ -1815,7 +1894,7 @@ module.exports = {
};
},{"../utils/utils":6,"./formatters":15,"./method":18,"./property":20}],13:[function(require,module,exports){
},{"../utils/utils":7,"./formatters":16,"./method":19,"./property":21}],14:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1955,7 +2034,7 @@ module.exports = {
};
},{"../solidity/abi":1,"../utils/utils":6,"./signature":24}],14:[function(require,module,exports){
},{"../solidity/abi":1,"../utils/utils":7,"./signature":25}],15:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2067,7 +2146,7 @@ Filter.prototype.get = function () {
module.exports = Filter;
},{"../utils/utils":6,"./formatters":15,"./requestmanager":22}],15:[function(require,module,exports){
},{"../utils/utils":7,"./formatters":16,"./requestmanager":23}],16:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2280,7 +2359,7 @@ module.exports = {
};
},{"../utils/config":5,"../utils/utils":6}],16:[function(require,module,exports){
},{"../utils/config":6,"../utils/utils":7}],17:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2343,7 +2422,7 @@ HttpProvider.prototype.sendAsync = function (payload, callback) {
module.exports = HttpProvider;
},{"xmlhttprequest":4}],17:[function(require,module,exports){
},{"xmlhttprequest":5}],18:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2436,7 +2515,7 @@ Jsonrpc.prototype.toBatchPayload = function (messages) {
module.exports = Jsonrpc;
},{}],18:[function(require,module,exports){
},{}],19:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2597,7 +2676,7 @@ Method.prototype.send = function () {
module.exports = Method;
},{"../utils/utils":6,"./errors":11,"./requestmanager":22}],19:[function(require,module,exports){
},{"../utils/utils":7,"./errors":12,"./requestmanager":23}],20:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2647,7 +2726,7 @@ module.exports = {
};
},{"../utils/utils":6,"./property":20}],20:[function(require,module,exports){
},{"../utils/utils":7,"./property":21}],21:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2753,7 +2832,7 @@ Property.prototype.set = function (value) {
module.exports = Property;
},{"./requestmanager":22}],21:[function(require,module,exports){
},{"./requestmanager":23}],22:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -2788,7 +2867,7 @@ QtSyncProvider.prototype.send = function (payload) {
module.exports = QtSyncProvider;
},{}],22:[function(require,module,exports){
},{}],23:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3009,7 +3088,7 @@ RequestManager.prototype.poll = function () {
module.exports = RequestManager;
},{"../utils/config":5,"../utils/utils":6,"./errors":11,"./jsonrpc":17}],23:[function(require,module,exports){
},{"../utils/config":6,"../utils/utils":7,"./errors":12,"./jsonrpc":18}],24:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3079,7 +3158,7 @@ module.exports = {
};
},{"./formatters":15,"./method":18}],24:[function(require,module,exports){
},{"./formatters":16,"./method":19}],25:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3123,7 +3202,7 @@ module.exports = {
};
},{"../utils/config":5,"../web3":8}],25:[function(require,module,exports){
},{"../utils/config":6,"../web3":9}],26:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -3226,7 +3305,7 @@ module.exports = {
};
},{"./method":18}],26:[function(require,module,exports){
},{"./method":19}],27:[function(require,module,exports){
},{}],"bignumber.js":[function(require,module,exports){
'use strict';
@ -3235,22 +3314,21 @@ module.exports = BigNumber; // jshint ignore:line
},{}],"web3":[function(require,module,exports){
// dont override global variable
if (typeof web3 !== 'undefined') {
var web3;
}
web3 = require('./lib/web3');
var web3 = require('./lib/web3');
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
web3.eth.contract = require('./lib/web3/contract');
web3.abi = require('./lib/solidity/abi');
// dont override global variable
if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
window.web3 = web3;
}
module.exports = web3;
},{"./lib/solidity/abi":1,"./lib/web3":8,"./lib/web3/contract":9,"./lib/web3/httpprovider":16,"./lib/web3/qtsync":21}]},{},["web3"])
},{"./lib/solidity/abi":1,"./lib/web3":9,"./lib/web3/contract":10,"./lib/web3/httpprovider":17,"./lib/web3/qtsync":22}]},{},["web3"])
//# sourceMappingURL=web3-light.js.map

18
libjsqrc/ethereumjs/dist/web3-light.js.map

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

4095
libjsqrc/ethereumjs/dist/web3.js

File diff suppressed because it is too large

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

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

13
libjsqrc/ethereumjs/index.js

@ -1,14 +1,13 @@
// dont override global variable
if (typeof web3 !== 'undefined') {
var web3;
}
web3 = require('./lib/web3');
var web3 = require('./lib/web3');
web3.providers.HttpProvider = require('./lib/web3/httpprovider');
web3.providers.QtSyncProvider = require('./lib/web3/qtsync');
web3.eth.contract = require('./lib/web3/contract');
web3.abi = require('./lib/solidity/abi');
// dont override global variable
if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
window.web3 = web3;
}
module.exports = web3;

23
libjsqrc/ethereumjs/lib/solidity/abi.js

@ -14,10 +14,10 @@
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 abi.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* Gav Wood <g@ethdev.com>
/**
* @file abi.js
* @author Marek Kotewicz <marek@ethdev.com>
* @author Gav Wood <g@ethdev.com>
* @date 2014
*/
@ -25,6 +25,7 @@ var utils = require('../utils/utils');
var c = require('../utils/config');
var types = require('./types');
var f = require('./formatters');
var solUtils = require('./utils');
/**
* throw incorrect type error
@ -237,9 +238,21 @@ var outputParser = function (json) {
return parser;
};
var formatConstructorParams = function (abi, params) {
var constructor = solUtils.getConstructor(abi, params.length);
if (!constructor) {
if (params.length > 0) {
console.warn("didn't found matching constructor, using default one");
}
return '';
}
return formatInput(constructor.inputs, params);
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser,
formatInput: formatInput,
formatOutput: formatOutput
formatOutput: formatOutput,
formatConstructorParams: formatConstructorParams
};

68
libjsqrc/ethereumjs/lib/solidity/utils.js

@ -0,0 +1,68 @@
/*
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 utils.js
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
/**
* Returns the contstructor with matching number of arguments
*
* @method getConstructor
* @param {Array} abi
* @param {Number} numberOfArgs
* @returns {Object} constructor function abi
*/
var getConstructor = function (abi, numberOfArgs) {
return abi.filter(function (f) {
return f.type === 'constructor' && f.inputs.length === numberOfArgs;
})[0];
};
/**
* Filters all functions from input abi
*
* @method filterFunctions
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'function'
*/
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/**
* Filters all events from input abi
*
* @method filterEvents
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'event'
*/
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';
});
};
module.exports = {
getConstructor: getConstructor,
filterFunctions: filterFunctions,
filterEvents: filterEvents
};

46
libjsqrc/ethereumjs/lib/utils/utils.js

@ -161,32 +161,6 @@ var extractTypeName = function (name) {
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
};
/**
* Filters all functions from input abi
*
* @method filterFunctions
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'function'
*/
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/**
* Filters all events from input abi
*
* @method filterEvents
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'event'
*/
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';
});
};
/**
* Converts value to it's decimal representation in string
*
@ -349,14 +323,25 @@ var toTwosComplement = function (number) {
};
/**
* Checks if the given string has proper length
* Checks if the given string is strictly an address
*
* @method isStrictAddress
* @param {String} address the given HEX adress
* @return {Boolean}
*/
var isStrictAddress = function (address) {
return /^0x[0-9a-f]{40}$/.test(address);
};
/**
* Checks if the given string is an address
*
* @method isAddress
* @param {String} address the given HEX adress
* @return {Boolean}
*/
var isAddress = function (address) {
return /^0x[0-9a-f]{40}$/.test(address);
return /^(0x)?[0-9a-f]{40}$/.test(address);
};
/**
@ -367,7 +352,7 @@ var isAddress = function (address) {
* @return {String} formatted address
*/
var toAddress = function (address) {
if (isAddress(address)) {
if (isStrictAddress(address)) {
return address;
}
@ -471,14 +456,13 @@ module.exports = {
fromAscii: fromAscii,
extractDisplayName: extractDisplayName,
extractTypeName: extractTypeName,
filterFunctions: filterFunctions,
filterEvents: filterEvents,
toWei: toWei,
fromWei: fromWei,
toBigNumber: toBigNumber,
toTwosComplement: toTwosComplement,
toAddress: toAddress,
isBigNumber: isBigNumber,
isStrictAddress: isStrictAddress,
isAddress: isAddress,
isFunction: isFunction,
isString: isString,

2
libjsqrc/ethereumjs/lib/version.json

@ -1,3 +1,3 @@
{
"version": "0.2.5"
"version": "0.2.6"
}

2
libjsqrc/ethereumjs/lib/web3.js

@ -58,7 +58,7 @@ var web3Properties = [
}),
new Property({
name: 'version.ethereum',
getter: 'eth_version',
getter: 'eth_protocolVersion',
inputFormatter: utils.toDecimal
}),
new Property({

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

@ -21,8 +21,9 @@
*/
var web3 = require('../web3');
var abi = require('../solidity/abi');
var solAbi = require('../solidity/abi');
var utils = require('../utils/utils');
var solUtils = require('../solidity/utils');
var eventImpl = require('./event');
var signature = require('./signature');
@ -42,11 +43,11 @@ var addFunctionRelatedPropertiesToContract = function (contract) {
};
var addFunctionsToContract = function (contract, desc, address) {
var inputParser = abi.inputParser(desc);
var outputParser = abi.outputParser(desc);
var inputParser = solAbi.inputParser(desc);
var outputParser = solAbi.outputParser(desc);
// create contract functions
utils.filterFunctions(desc).forEach(function (method) {
solUtils.filterFunctions(desc).forEach(function (method) {
var displayName = utils.extractDisplayName(method.name);
var typeName = utils.extractTypeName(method.name);
@ -98,14 +99,14 @@ var addFunctionsToContract = function (contract, desc, address) {
var addEventRelatedPropertiesToContract = function (contract, desc, address) {
contract.address = address;
contract._onWatchEventResult = function (data) {
var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc));
var matchingEvent = event.getMatchingEvent(solUtils.filterEvents(desc));
var parser = eventImpl.outputParser(matchingEvent);
return parser(data);
};
Object.defineProperty(contract, 'topics', {
get: function() {
return utils.filterEvents(desc).map(function (e) {
return solUtils.filterEvents(desc).map(function (e) {
return signature.eventSignatureFromAscii(e.name);
});
}
@ -115,7 +116,7 @@ var addEventRelatedPropertiesToContract = function (contract, desc, address) {
var addEventsToContract = function (contract, desc, address) {
// create contract events
utils.filterEvents(desc).forEach(function (e) {
solUtils.filterEvents(desc).forEach(function (e) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
@ -173,7 +174,7 @@ var contract = function (abi) {
return Contract.bind(null, abi);
};
function Contract(abi, address) {
function Contract(abi, options) {
// workaround for invalid assumption that method.name is the full anonymous prototype of the method.
// it's not. it's just the name. the rest of the code assumes it's actually the anonymous
@ -187,6 +188,17 @@ function Contract(abi, address) {
}
});
var address = '';
if (utils.isAddress(options)) {
address = options;
} else { // is a source code!
// TODO, parse the rest of the args
var code = options;
var args = Array.prototype.slice.call(arguments, 2);
var bytes = solAbi.formatConstructorParams(abi, args);
address = web3.eth.sendTransaction({data: code + bytes});
}
var result = {};
addFunctionRelatedPropertiesToContract(result);
addFunctionsToContract(result, abi, address);

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

@ -102,15 +102,15 @@ var getBlock = new Method({
name: 'getBlock',
call: blockCall,
params: 2,
inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
inputFormatter: [utils.toHex, function (val) { return !!val; }],
outputFormatter: formatters.outputBlockFormatter
});
var getUncle = new Method({
name: 'getUncle',
call: uncleCall,
params: 3,
inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex, function (val) { return !!val; }],
params: 2,
inputFormatter: [utils.toHex, utils.toHex],
outputFormatter: formatters.outputBlockFormatter,
});
@ -234,7 +234,7 @@ var properties = [
new Property({
name: 'gasPrice',
getter: 'eth_gasPrice',
outputFormatter: formatters.inputNumberFormatter
outputFormatter: formatters.outputBigNumberFormatter
}),
new Property({
name: 'accounts',

2
libjsqrc/ethereumjs/package.js

@ -1,7 +1,7 @@
/* jshint ignore:start */
Package.describe({
name: 'ethereum:js',
version: '0.2.5',
version: '0.2.6',
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.

8
libjsqrc/ethereumjs/package.json

@ -1,7 +1,7 @@
{
"name": "web3",
"namespace": "ethereum",
"version": "0.2.5",
"version": "0.2.6",
"description": "Ethereum JavaScript API, middleware to talk to a ethereum node over RPC",
"main": "./index.js",
"directories": {
@ -49,11 +49,11 @@
},
"repository": {
"type": "git",
"url": "https://github.com/ethereum/ethereum.js.git"
"url": "https://github.com/ethereum/web3.js.git"
},
"homepage": "https://github.com/ethereum/ethereum.js",
"homepage": "https://github.com/ethereum/web3.js",
"bugs": {
"url": "https://github.com/ethereum/ethereum.js/issues"
"url": "https://github.com/ethereum/web3.js/issues"
},
"keywords": [
"ethereum",

106
libjsqrc/ethereumjs/test/abi.formatConstructorParams.js

@ -0,0 +1,106 @@
var chai = require('chai');
var assert = require('assert');
var abi = require('../lib/solidity/abi');
describe('lib/solidity/abi', function () {
describe('formatConstructorParams', function () {
it('should format uint256 properly', function () {
// given
var description = [{
"name": "test",
"type": "constructor",
"inputs": [{
"name": "a",
"type": "uint256"
}
]
}];
// when
var bytes = abi.formatConstructorParams(description, [2]);
// then
assert.equal(bytes, '0000000000000000000000000000000000000000000000000000000000000002');
});
it('should not find matching constructor', function () {
// given
var description = [{
"name": "test",
"type": "constructor",
"inputs": [{
"name": "a",
"type": "uint256"
}
]
}];
// when
var bytes = abi.formatConstructorParams(description, []);
// then
assert.equal(bytes, '');
});
it('should not find matching constructor2', function () {
// given
var description = [{
"name": "test",
"type": "constructor",
"inputs": [{
"name": "a",
"type": "uint256"
}
]
}];
// when
var bytes = abi.formatConstructorParams(description, [1,2]);
// then
assert.equal(bytes, '');
});
it('should not find matching constructor3', function () {
// given
var description = [{
"name": "test",
"type": "function",
"inputs": [{
"name": "a",
"type": "uint256"
}
]
}];
// when
var bytes = abi.formatConstructorParams(description, [2]);
// then
assert.equal(bytes, '');
});
it('should find matching constructor with multiple args', function () {
// given
var description = [{
"name": "test",
"type": "constructor",
"inputs": [{
"name": "a",
"type": "uint256"
}, {
"name": "b",
"type": "uint256"
}]
}];
// when
var bytes = abi.formatConstructorParams(description, ['1', '5']);
// then
assert.equal(bytes, '00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000005');
});
});
});

11
libjsqrc/ethereumjs/test/abi.inputParser.js

@ -1,6 +1,7 @@
var assert = require('assert');
var chai = require('chai');
var assert = chai.assert;
var BigNumber = require('bignumber.js');
var abi = require('../lib/solidity/abi.js');
var abi = require('../lib/solidity/abi');
var clone = function (object) { return JSON.parse(JSON.stringify(object)); };
var description = [{
@ -19,9 +20,9 @@ var description = [{
]
}];
describe('lib/solidity/abi', function() {
describe('inputParser', function() {
it('should parse input uint', function() {
describe('lib/solidity/abi', function () {
describe('inputParser', function () {
it('should parse input uint', function () {
// given
var d = clone(description);

2
libjsqrc/ethereumjs/test/utils.filters.js

@ -1,5 +1,5 @@
var assert = require('assert');
var utils = require('../lib/utils/utils.js');
var utils = require('../lib/solidity/utils');
describe('lib/utils/utils', function() {
it('should filter functions and events from input array properly', function () {

2
libjsqrc/ethereumjs/test/utils.isAddress.js

@ -8,7 +8,7 @@ var tests = [
{ value: 'function', is: false},
{ value: {}, is: false},
{ value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true },
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: false }
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: true }
];
describe('lib/utils/utils', function () {

23
libjsqrc/ethereumjs/test/utils.isStrictAddress.js

@ -0,0 +1,23 @@
var chai = require('chai');
var utils = require('../lib/utils/utils.js');
var assert = chai.assert;
var tests = [
{ value: function () {}, is: false},
{ value: new Function(), is: false},
{ value: 'function', is: false},
{ value: {}, is: false},
{ value: '0xc6d9d2cd449a754c494264e1809c50e34d64562b', is: true },
{ value: 'c6d9d2cd449a754c494264e1809c50e34d64562b', is: false }
];
describe('lib/utils/utils', function () {
describe('isStrictAddress', function () {
tests.forEach(function (test) {
it('shoud test if value ' + test.value + ' is address: ' + test.is, function () {
assert.equal(utils.isStrictAddress(test.value), test.is);
});
});
});
});

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

@ -1,5 +1,7 @@
var assert = require('assert');
var contract = require('../lib/web3/contract.js');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var web3 = require('../index');
describe('web3.eth.contract', function() {
it('should create simple contract with one method from abi with explicit type name', function () {
@ -20,10 +22,11 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var Con = contract(description);
var myCon = new Con(null);
var myCon = new Con(address);
// then
assert.equal('function', typeof myCon.test);
@ -48,10 +51,11 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var Con = contract(description);
var myCon = new Con(null);
var myCon = new Con(address);
// then
assert.equal('function', typeof myCon.test);
@ -90,10 +94,11 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var Con = contract(description);
var myCon = new Con(null);
var myCon = new Con(address);
// then
assert.equal('function', typeof myCon.test);
@ -134,10 +139,11 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var Con = contract(description);
var myCon = new Con(null);
var myCon = new Con(address);
// then
assert.equal('function', typeof myCon.test);
@ -162,11 +168,11 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var Con = contract(description);
var myCon = new Con(null);
var myCon = new Con(address);
// then
assert.equal('undefined', typeof myCon.test);
@ -191,11 +197,11 @@ describe('web3.eth.contract', function() {
}
]
}];
var address = '0x1234567890123456789012345678901234567890';
// when
var Con = contract(description);
var myCon = new Con(null);
var myCon = new Con(address);
// then
assert.equal('function', typeof myCon.test);
@ -203,5 +209,32 @@ describe('web3.eth.contract', function() {
});
it('should create contract with nondefault constructor', function (done) {
var provider = new FakeHttpProvider();
web3.setProvider(provider);
web3.reset(); // reset different polls
var address = '0x1234567890123456789012345678901234567890';
var code = '0x31241231231123123123123121cf121212i123123123123123512312412512111111';
var description = [{
"name": "test",
"type": "constructor",
"inputs": [{
"name": "a",
"type": "uint256"
}
]
}];
provider.injectResult(address);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, 'eth_sendTransaction');
assert.equal(payload.params[0].data, code + '0000000000000000000000000000000000000000000000000000000000000002');
done();
});
var Con = contract(description);
var myCon = new Con(code, 2);
});
});

39
libjsqrc/ethereumjs/test/web3.eth.gasPrice.js

@ -0,0 +1,39 @@
var chai = require('chai');
var assert = chai.assert;
var web3 = require('../index');
var BigNumber = require('bignumber.js');
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
var method = 'gasPrice';
var tests = [{
result: '0x15f90',
formattedResult: new BigNumber(90000),
call: 'eth_'+ method
}];
describe('web3.eth', function () {
describe(method, function () {
tests.forEach(function (test, index) {
it('property test: ' + index, function () {
// given
var provider = new FakeHttpProvider();
web3.setProvider(provider);
provider.injectResult(test.result);
provider.injectValidation(function (payload) {
assert.equal(payload.jsonrpc, '2.0');
assert.equal(payload.method, test.call);
assert.deepEqual(payload.params, []);
});
// when
var result = web3.eth[method];
// then
assert.deepEqual(test.formattedResult, result);
});
});
});
});

6
libjsqrc/ethereumjs/test/web3.eth.getUncle.js

@ -118,19 +118,19 @@ var formattedBlockResultWithTx = {
var tests = [{
args: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', 2],
formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2', false],
formattedArgs: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x2'],
result: blockResult,
formattedResult: formattedBlockResult,
call: 'eth_getUncleByBlockHashAndIndex'
},{
args: [436, 1],
formattedArgs: ['0x1b4', '0x1', false],
formattedArgs: ['0x1b4', '0x1'],
result: blockResult,
formattedResult: formattedBlockResult,
call: 'eth_getUncleByBlockNumberAndIndex'
},{
args: [436, 1, true],
formattedArgs: ['0x1b4', '0x1', true],
formattedArgs: ['0x1b4', '0x1'],
result: blockResultWithTx,
formattedResult: formattedBlockResultWithTx,
call: 'eth_getUncleByBlockNumberAndIndex'

Loading…
Cancel
Save