Browse Source

Squashed 'libjsqrc/ethereumjs/' changes from 9926e27..26f268f

26f268f upgraded version to 0.1.1
d2dbc2d fixed gulp errors

git-subtree-dir: libjsqrc/ethereumjs
git-subtree-split: 26f268f50bc621593f985635f3f87520c6b8dba6
cl-refactor
Marek Kotewicz 10 years ago
parent
commit
a8e2d8dff8
  1. 2
      bower.json
  2. 54
      dist/ethereum.js
  3. 10
      dist/ethereum.js.map
  4. 2
      dist/ethereum.min.js
  5. 34
      lib/utils/utils.js
  6. 8
      lib/web3/filter.js
  7. 2
      lib/web3/httpprovider.js
  8. 10
      lib/web3/requestmanager.js
  9. 2
      package.js
  10. 4
      package.json

2
bower.json

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

54
dist/ethereum.js

@ -817,9 +817,7 @@ var fromDecimal = function (value) {
var number = toBigNumber(value); var number = toBigNumber(value);
var result = number.toString(16); var result = number.toString(16);
return (number.lessThan(0)) return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
? '-0x' + result.substr(1)
: '0x' + result;
}; };
/** /**
@ -832,6 +830,7 @@ var fromDecimal = function (value) {
* @return {String} * @return {String}
*/ */
var toHex = function (val) { var toHex = function (val) {
/*jshint maxcomplexity:7 */
if(isBoolean(val)) if(isBoolean(val))
return val; return val;
@ -893,8 +892,7 @@ var getValueOfUnit = function (unit) {
var fromWei = function(number, unit) { var fromWei = function(number, unit) {
var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
return (isBigNumber(number)) return isBigNumber(number) ? returnValue : returnValue.toString(10);
? returnValue : returnValue.toString(10);
}; };
/** /**
@ -920,8 +918,7 @@ var fromWei = function(number, unit) {
var toWei = function(number, unit) { var toWei = function(number, unit) {
var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
return (isBigNumber(number)) return isBigNumber(number) ? returnValue : returnValue.toString(10);
? returnValue : returnValue.toString(10);
}; };
/** /**
@ -932,13 +929,16 @@ var toWei = function(number, unit) {
* @return {BigNumber} BigNumber * @return {BigNumber} BigNumber
*/ */
var toBigNumber = function(number) { var toBigNumber = function(number) {
/*jshint maxcomplexity:5 */
number = number || 0; number = number || 0;
if (isBigNumber(number)) if (isBigNumber(number))
return number; return number;
return (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) {
? new BigNumber(number.replace('0x',''), 16) return new BigNumber(number.replace('0x',''), 16);
: new BigNumber(number.toString(10), 10); }
return new BigNumber(number.toString(10), 10);
}; };
/** /**
@ -1029,6 +1029,17 @@ var isBoolean = function (object) {
return typeof object === 'boolean'; return typeof object === 'boolean';
}; };
/**
* Returns true if object is array, otherwise false
*
* @method isArray
* @param {Object}
* @return {Boolean}
*/
var isArray = function (object) {
return object instanceof Array;
};
module.exports = { module.exports = {
findIndex: findIndex, findIndex: findIndex,
toHex: toHex, toHex: toHex,
@ -1049,7 +1060,8 @@ module.exports = {
isFunction: isFunction, isFunction: isFunction,
isString: isString, isString: isString,
isObject: isObject, isObject: isObject,
isBoolean: isBoolean isBoolean: isBoolean,
isArray: isArray
}; };
@ -1950,7 +1962,7 @@ var implementationIsValid = function (i) {
/// @param should be string or object /// @param should be string or object
/// @returns options string or object /// @returns options string or object
var getOptions = function (options) { var getOptions = function (options) {
/*jshint maxcomplexity:5 */ /*jshint maxcomplexity:9 */
if (typeof options === 'string') { if (typeof options === 'string') {
return options; return options;
@ -2043,11 +2055,9 @@ var filter = function(options, implementation, formatter) {
var get = function () { var get = function () {
var results = implementation.getLogs(filterId); var results = implementation.getLogs(filterId);
return (results instanceof Array) return utils.isArray(results) ? results.map(function(message){
? results.map(function(message){
return formatter ? formatter(message) : message; return formatter ? formatter(message) : message;
}) }) : results;
: results;
}; };
return { return {
@ -2335,7 +2345,7 @@ HttpProvider.prototype.send = function (payload, callback) {
if(request.readyState === 4) { if(request.readyState === 4) {
var result = ''; var result = '';
try { try {
result = JSON.parse(request.responseText) result = JSON.parse(request.responseText);
} catch(error) { } catch(error) {
result = error; result = error;
} }
@ -2547,24 +2557,20 @@ var requestManager = function() {
var provider; var provider;
var send = function (data, callback) { var send = function (data, callback) {
/*jshint maxcomplexity: 7 */ /*jshint maxcomplexity: 8 */
// FORMAT BASED ON ONE FORMATTER function // FORMAT BASED ON ONE FORMATTER function
if(typeof data.inputFormatter === 'function') { if(typeof data.inputFormatter === 'function') {
data.params = Array.prototype.map.call(data.params, function(item, index){ data.params = Array.prototype.map.call(data.params, function(item, index){
// format everything besides the defaultblock, which is already formated // format everything besides the defaultblock, which is already formated
return (!data.addDefaultblock || index+1 < data.addDefaultblock) return (!data.addDefaultblock || index+1 < data.addDefaultblock) ? data.inputFormatter(item) : item;
? data.inputFormatter(item)
: item;
}); });
// FORMAT BASED ON the input FORMATTER ARRAY // FORMAT BASED ON the input FORMATTER ARRAY
} else if(data.inputFormatter instanceof Array) { } else if(data.inputFormatter instanceof Array) {
data.params = Array.prototype.map.call(data.inputFormatter, function(formatter, index){ data.params = Array.prototype.map.call(data.inputFormatter, function(formatter, index){
// format everything besides the defaultblock, which is already formated // format everything besides the defaultblock, which is already formated
return (!data.addDefaultblock || index+1 < data.addDefaultblock) return (!data.addDefaultblock || index+1 < data.addDefaultblock) ? formatter(data.params[index]) : data.params[index];
? formatter(data.params[index])
: data.params[index];
}); });
} }

10
dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
dist/ethereum.min.js

File diff suppressed because one or more lines are too long

34
lib/utils/utils.js

@ -199,9 +199,7 @@ var fromDecimal = function (value) {
var number = toBigNumber(value); var number = toBigNumber(value);
var result = number.toString(16); var result = number.toString(16);
return (number.lessThan(0)) return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
? '-0x' + result.substr(1)
: '0x' + result;
}; };
/** /**
@ -214,6 +212,7 @@ var fromDecimal = function (value) {
* @return {String} * @return {String}
*/ */
var toHex = function (val) { var toHex = function (val) {
/*jshint maxcomplexity:7 */
if(isBoolean(val)) if(isBoolean(val))
return val; return val;
@ -275,8 +274,7 @@ var getValueOfUnit = function (unit) {
var fromWei = function(number, unit) { var fromWei = function(number, unit) {
var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
return (isBigNumber(number)) return isBigNumber(number) ? returnValue : returnValue.toString(10);
? returnValue : returnValue.toString(10);
}; };
/** /**
@ -302,8 +300,7 @@ var fromWei = function(number, unit) {
var toWei = function(number, unit) { var toWei = function(number, unit) {
var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
return (isBigNumber(number)) return isBigNumber(number) ? returnValue : returnValue.toString(10);
? returnValue : returnValue.toString(10);
}; };
/** /**
@ -314,13 +311,16 @@ var toWei = function(number, unit) {
* @return {BigNumber} BigNumber * @return {BigNumber} BigNumber
*/ */
var toBigNumber = function(number) { var toBigNumber = function(number) {
/*jshint maxcomplexity:5 */
number = number || 0; number = number || 0;
if (isBigNumber(number)) if (isBigNumber(number))
return number; return number;
return (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) {
? new BigNumber(number.replace('0x',''), 16) return new BigNumber(number.replace('0x',''), 16);
: new BigNumber(number.toString(10), 10); }
return new BigNumber(number.toString(10), 10);
}; };
/** /**
@ -411,6 +411,17 @@ var isBoolean = function (object) {
return typeof object === 'boolean'; return typeof object === 'boolean';
}; };
/**
* Returns true if object is array, otherwise false
*
* @method isArray
* @param {Object}
* @return {Boolean}
*/
var isArray = function (object) {
return object instanceof Array;
};
module.exports = { module.exports = {
findIndex: findIndex, findIndex: findIndex,
toHex: toHex, toHex: toHex,
@ -431,6 +442,7 @@ module.exports = {
isFunction: isFunction, isFunction: isFunction,
isString: isString, isString: isString,
isObject: isObject, isObject: isObject,
isBoolean: isBoolean isBoolean: isBoolean,
isArray: isArray
}; };

8
lib/web3/filter.js

@ -40,7 +40,7 @@ var implementationIsValid = function (i) {
/// @param should be string or object /// @param should be string or object
/// @returns options string or object /// @returns options string or object
var getOptions = function (options) { var getOptions = function (options) {
/*jshint maxcomplexity:5 */ /*jshint maxcomplexity:9 */
if (typeof options === 'string') { if (typeof options === 'string') {
return options; return options;
@ -133,11 +133,9 @@ var filter = function(options, implementation, formatter) {
var get = function () { var get = function () {
var results = implementation.getLogs(filterId); var results = implementation.getLogs(filterId);
return (results instanceof Array) return utils.isArray(results) ? results.map(function(message){
? results.map(function(message){
return formatter ? formatter(message) : message; return formatter ? formatter(message) : message;
}) }) : results;
: results;
}; };
return { return {

2
lib/web3/httpprovider.js

@ -41,7 +41,7 @@ HttpProvider.prototype.send = function (payload, callback) {
if(request.readyState === 4) { if(request.readyState === 4) {
var result = ''; var result = '';
try { try {
result = JSON.parse(request.responseText) result = JSON.parse(request.responseText);
} catch(error) { } catch(error) {
result = error; result = error;
} }

10
lib/web3/requestmanager.js

@ -37,24 +37,20 @@ var requestManager = function() {
var provider; var provider;
var send = function (data, callback) { var send = function (data, callback) {
/*jshint maxcomplexity: 7 */ /*jshint maxcomplexity: 8 */
// FORMAT BASED ON ONE FORMATTER function // FORMAT BASED ON ONE FORMATTER function
if(typeof data.inputFormatter === 'function') { if(typeof data.inputFormatter === 'function') {
data.params = Array.prototype.map.call(data.params, function(item, index){ data.params = Array.prototype.map.call(data.params, function(item, index){
// format everything besides the defaultblock, which is already formated // format everything besides the defaultblock, which is already formated
return (!data.addDefaultblock || index+1 < data.addDefaultblock) return (!data.addDefaultblock || index+1 < data.addDefaultblock) ? data.inputFormatter(item) : item;
? data.inputFormatter(item)
: item;
}); });
// FORMAT BASED ON the input FORMATTER ARRAY // FORMAT BASED ON the input FORMATTER ARRAY
} else if(data.inputFormatter instanceof Array) { } else if(data.inputFormatter instanceof Array) {
data.params = Array.prototype.map.call(data.inputFormatter, function(formatter, index){ data.params = Array.prototype.map.call(data.inputFormatter, function(formatter, index){
// format everything besides the defaultblock, which is already formated // format everything besides the defaultblock, which is already formated
return (!data.addDefaultblock || index+1 < data.addDefaultblock) return (!data.addDefaultblock || index+1 < data.addDefaultblock) ? formatter(data.params[index]) : data.params[index];
? formatter(data.params[index])
: data.params[index];
}); });
} }

2
package.js

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

4
package.json

@ -1,7 +1,7 @@
{ {
"name": "ethereum.js", "name": "ethereum.js",
"namespace": "ethereum", "namespace": "ethereum",
"version": "0.1.0", "version": "0.1.1",
"description": "Ethereum JavaScript API, middleware to talk to a ethreum node over RPC", "description": "Ethereum JavaScript API, middleware to talk to a ethreum node over RPC",
"main": "./index.js", "main": "./index.js",
"directories": { "directories": {
@ -39,7 +39,7 @@
"scripts": { "scripts": {
"build": "gulp", "build": "gulp",
"watch": "gulp watch", "watch": "gulp watch",
"lint": "gulp lint", "lint": "jshint *.js lib",
"test": "mocha", "test": "mocha",
"test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose", "test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose",
"karma": "./node_modules/karma/bin/karma start --singleRun=true --browsers=\"Firefox\"" "karma": "./node_modules/karma/bin/karma start --singleRun=true --browsers=\"Firefox\""

Loading…
Cancel
Save