Browse Source

Merge commit 'a6feadd192e2b254e1f585d203c2fd325d14bd1f' into ethereumjs

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
5ea6cdb28c
  1. 213
      libjsqrc/ethereumjs/dist/ethereum.js
  2. 12
      libjsqrc/ethereumjs/dist/ethereum.js.map
  3. 2
      libjsqrc/ethereumjs/dist/ethereum.min.js
  4. 57
      libjsqrc/ethereumjs/lib/abi.js
  5. 33
      libjsqrc/ethereumjs/lib/const.js
  6. 15
      libjsqrc/ethereumjs/lib/formatters.js
  7. 44
      libjsqrc/ethereumjs/lib/utils.js
  8. 38
      libjsqrc/ethereumjs/lib/web3.js

213
libjsqrc/ethereumjs/dist/ethereum.js

@ -22,39 +22,12 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof requ
* @date 2014
*/
if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); // jshint ignore:line
*/}
var web3 = require('./web3');
var utils = require('./utils');
var types = require('./types');
var c = require('./const');
var f = require('./formatters');
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var ETH_PADDING = 32;
/// method signature length in bytes
var ETH_METHOD_SIGNATURE_LENGTH = 4;
/// @returns a function that is used as a pattern for 'findIndex'
var findMethodIndex = function (json, methodName) {
return utils.findIndex(json, function (method) {
return method.name === methodName;
});
};
/// @returns method with given method name
var getMethodWithName = function (json, methodName) {
var index = findMethodIndex(json, methodName);
if (index === -1) {
console.error('method ' + methodName + ' not found in the abi');
return undefined;
}
return json[index];
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var filterFunctions = function (json) {
@ -87,15 +60,12 @@ var dynamicTypeBytes = function (type, value) {
var inputTypes = types.inputTypes();
/// Formats input params to bytes
/// @param contract json abi
/// @param name of the method that we want to use
/// @param abi contract method
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
var toAbiInput = function (json, methodName, params) {
var toAbiInput = function (method, params) {
var bytes = "";
var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
/// first we iterate in search for dynamic
method.inputs.forEach(function (input, index) {
@ -128,23 +98,21 @@ var toAbiInput = function (json, methodName, params) {
var dynamicBytesLength = function (type) {
if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2;
return c.ETH_PADDING * 2;
return 0;
};
var outputTypes = types.outputTypes();
/// Formats output bytes back to param list
/// @param contract json abi
/// @param name of the method that we want to use
/// @param contract abi method
/// @param bytes representtion of output
/// @returns array of output params
var fromAbiOutput = function (json, methodName, output) {
var fromAbiOutput = function (method, output) {
output = output.slice(2);
var result = [];
var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
var dynamicPartLength = method.outputs.reduce(function (acc, curr) {
return acc + dynamicBytesLength(curr.type);
@ -195,7 +163,7 @@ var methodDisplayName = function (method) {
/// @returns overloaded part of method's name
var methodTypeName = function (method) {
/// TODO: make it not vulnerable
/// TODO: make it invulnerable
var length = method.indexOf('(');
return length !== -1 ? method.substr(length + 1, method.length - 1 - (length + 1)) : "";
};
@ -211,7 +179,7 @@ var inputParser = function (json) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
return toAbiInput(json, method.name, params);
return toAbiInput(method, params);
};
if (parser[displayName] === undefined) {
@ -234,7 +202,7 @@ var outputParser = function (json) {
var typeName = methodTypeName(method.name);
var impl = function (output) {
return fromAbiOutput(json, method.name, output);
return fromAbiOutput(method, output);
};
if (parser[displayName] === undefined) {
@ -250,7 +218,7 @@ var outputParser = function (json) {
/// @param method name for which we want to get method signature
/// @returns (promise) contract method signature for method with given name
var methodSignature = function (name) {
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + ETH_METHOD_SIGNATURE_LENGTH * 2);
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_METHOD_SIGNATURE_LENGTH * 2);
};
module.exports = {
@ -259,13 +227,47 @@ module.exports = {
methodSignature: methodSignature,
methodDisplayName: methodDisplayName,
methodTypeName: methodTypeName,
getMethodWithName: getMethodWithName,
filterFunctions: filterFunctions,
filterEvents: filterEvents
};
},{"./formatters":5,"./types":9,"./utils":10,"./web3":11}],2:[function(require,module,exports){
},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[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 const.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
/// required to define ETH_BIGNUMBER_ROUNDING_MODE
if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); // jshint ignore:line
*/}
module.exports = {
ETH_PADDING: 32,
ETH_METHOD_SIGNATURE_LENGTH: 4,
ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }
};
},{}],3:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -474,7 +476,7 @@ var contract = function (address, desc) {
module.exports = contract;
},{"./abi":1,"./event":3,"./web3":11}],3:[function(require,module,exports){
},{"./abi":1,"./event":4,"./web3":12}],4:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -549,7 +551,7 @@ var implementationOfEvent = function (address, signature, event) {
module.exports = implementationOfEvent;
},{"./abi":1,"./utils":10}],4:[function(require,module,exports){
},{"./abi":1,"./utils":11}],5:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -646,7 +648,7 @@ Filter.prototype.logs = function () {
module.exports = Filter;
},{"./web3":11}],5:[function(require,module,exports){
},{"./web3":12}],6:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -673,12 +675,8 @@ if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js'); // jshint ignore:line
*/}
// TODO: remove web3 dependency from here!
var web3 = require('./web3');
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var ETH_PADDING = 32;
var utils = require('./utils');
var c = require('./const');
/// @param string string to be padded
/// @param number of characters that result string should have
@ -693,10 +691,11 @@ var padLeft = function (string, chars, sign) {
/// If the value is floating point, round it down
/// @returns right-aligned byte representation of int
var formatInputInt = function (value) {
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number')
value = new BigNumber(value);
BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
value = value.round();
if (value.lessThan(0))
@ -715,7 +714,7 @@ var formatInputInt = function (value) {
/// Formats input value to byte representation of string
/// @returns left-algined byte representation of string
var formatInputString = function (value) {
return web3.fromAscii(value, ETH_PADDING).substr(2);
return utils.fromAscii(value, c.ETH_PADDING).substr(2);
};
/// Formats input value to byte representation of bool
@ -780,7 +779,7 @@ var formatOutputBool = function (value) {
/// @returns left-aligned input bytes formatted to ascii string
var formatOutputString = function (value) {
return web3.toAscii(value);
return utils.toAscii(value);
};
/// @returns right-aligned input bytes formatted to address
@ -805,7 +804,7 @@ module.exports = {
};
},{"./web3":11}],6:[function(require,module,exports){
},{"./const":2,"./utils":11}],7:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -877,7 +876,7 @@ HttpSyncProvider.prototype.send = function (payload) {
module.exports = HttpSyncProvider;
},{}],7:[function(require,module,exports){
},{}],8:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -989,7 +988,7 @@ ProviderManager.prototype.stopPolling = function (pollId) {
module.exports = ProviderManager;
},{"./web3":11}],8:[function(require,module,exports){
},{"./web3":12}],9:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1023,7 +1022,7 @@ QtSyncProvider.prototype.send = function (payload) {
module.exports = QtSyncProvider;
},{}],9:[function(require,module,exports){
},{}],10:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1104,7 +1103,7 @@ module.exports = {
};
},{"./formatters":5}],10:[function(require,module,exports){
},{"./formatters":6}],11:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1140,12 +1139,54 @@ var findIndex = function (array, callback) {
return end ? i - 1 : -1;
};
/// @returns ascii string representation of hex value prefixed with 0x
var toAscii = function(hex) {
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) === '0x') {
i = 2;
}
for (; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if (code === 0) {
break;
}
str += String.fromCharCode(code);
}
return str;
};
var toHex = function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
};
/// @returns hex representation (prefixed by 0x) of ascii string
var fromAscii = function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = toHex(str);
while (hex.length < pad*2)
hex += "00";
return "0x" + hex;
};
module.exports = {
findIndex: findIndex
findIndex: findIndex,
toAscii: toAscii,
fromAscii: fromAscii
};
},{}],11:[function(require,module,exports){
},{}],12:[function(require,module,exports){
/*
This file is part of ethereum.js.
@ -1175,6 +1216,8 @@ if ("build" !== 'build') {/*
var BigNumber = require('bignumber.js');
*/}
var utils = require('./utils');
var ETH_UNITS = [
'wei',
'Kwei',
@ -1340,43 +1383,11 @@ var web3 = {
_events: {},
providers: {},
toHex: function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
},
/// @returns ascii string representation of hex value prefixed with 0x
toAscii: function(hex) {
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) === '0x')
i = 2;
for(; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if(code === 0) {
break;
}
str += String.fromCharCode(code);
}
return str;
},
toAscii: utils.toAscii,
/// @returns hex representation (prefixed by 0x) of ascii string
fromAscii: function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = this.toHex(str);
while(hex.length < pad*2)
hex += "00";
return "0x" + hex;
},
fromAscii: utils.fromAscii,
/// @returns decimal representaton of hex value prefixed by 0x
toDecimal: function (val) {
@ -1482,7 +1493,7 @@ web3.setProvider = function(provider) {
module.exports = web3;
},{}],"web3":[function(require,module,exports){
},{"./utils":11}],"web3":[function(require,module,exports){
var web3 = require('./lib/web3');
var ProviderManager = require('./lib/providermanager');
web3.provider = new ProviderManager();
@ -1495,7 +1506,7 @@ web3.abi = require('./lib/abi');
module.exports = web3;
},{"./lib/abi":1,"./lib/contract":2,"./lib/filter":4,"./lib/httpsync":6,"./lib/providermanager":7,"./lib/qtsync":8,"./lib/web3":11}]},{},["web3"])
},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":8,"./lib/qtsync":9,"./lib/web3":12}]},{},["web3"])
//# sourceMappingURL=ethereum.js.map

12
libjsqrc/ethereumjs/dist/ethereum.js.map

File diff suppressed because one or more lines are too long

2
libjsqrc/ethereumjs/dist/ethereum.min.js

File diff suppressed because one or more lines are too long

57
libjsqrc/ethereumjs/lib/abi.js

@ -21,39 +21,12 @@
* @date 2014
*/
if (process.env.NODE_ENV !== 'build') {
var BigNumber = require('bignumber.js'); // jshint ignore:line
}
var web3 = require('./web3');
var utils = require('./utils');
var types = require('./types');
var c = require('./const');
var f = require('./formatters');
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var ETH_PADDING = 32;
/// method signature length in bytes
var ETH_METHOD_SIGNATURE_LENGTH = 4;
/// @returns a function that is used as a pattern for 'findIndex'
var findMethodIndex = function (json, methodName) {
return utils.findIndex(json, function (method) {
return method.name === methodName;
});
};
/// @returns method with given method name
var getMethodWithName = function (json, methodName) {
var index = findMethodIndex(json, methodName);
if (index === -1) {
console.error('method ' + methodName + ' not found in the abi');
return undefined;
}
return json[index];
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var filterFunctions = function (json) {
@ -86,15 +59,12 @@ var dynamicTypeBytes = function (type, value) {
var inputTypes = types.inputTypes();
/// Formats input params to bytes
/// @param contract json abi
/// @param name of the method that we want to use
/// @param abi contract method
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
var toAbiInput = function (json, methodName, params) {
var toAbiInput = function (method, params) {
var bytes = "";
var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
/// first we iterate in search for dynamic
method.inputs.forEach(function (input, index) {
@ -127,23 +97,21 @@ var toAbiInput = function (json, methodName, params) {
var dynamicBytesLength = function (type) {
if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.
return ETH_PADDING * 2;
return c.ETH_PADDING * 2;
return 0;
};
var outputTypes = types.outputTypes();
/// Formats output bytes back to param list
/// @param contract json abi
/// @param name of the method that we want to use
/// @param contract abi method
/// @param bytes representtion of output
/// @returns array of output params
var fromAbiOutput = function (json, methodName, output) {
var fromAbiOutput = function (method, output) {
output = output.slice(2);
var result = [];
var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
var dynamicPartLength = method.outputs.reduce(function (acc, curr) {
return acc + dynamicBytesLength(curr.type);
@ -194,7 +162,7 @@ var methodDisplayName = function (method) {
/// @returns overloaded part of method's name
var methodTypeName = function (method) {
/// TODO: make it not vulnerable
/// TODO: make it invulnerable
var length = method.indexOf('(');
return length !== -1 ? method.substr(length + 1, method.length - 1 - (length + 1)) : "";
};
@ -210,7 +178,7 @@ var inputParser = function (json) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
return toAbiInput(json, method.name, params);
return toAbiInput(method, params);
};
if (parser[displayName] === undefined) {
@ -233,7 +201,7 @@ var outputParser = function (json) {
var typeName = methodTypeName(method.name);
var impl = function (output) {
return fromAbiOutput(json, method.name, output);
return fromAbiOutput(method, output);
};
if (parser[displayName] === undefined) {
@ -249,7 +217,7 @@ var outputParser = function (json) {
/// @param method name for which we want to get method signature
/// @returns (promise) contract method signature for method with given name
var methodSignature = function (name) {
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + ETH_METHOD_SIGNATURE_LENGTH * 2);
return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_METHOD_SIGNATURE_LENGTH * 2);
};
module.exports = {
@ -258,7 +226,6 @@ module.exports = {
methodSignature: methodSignature,
methodDisplayName: methodDisplayName,
methodTypeName: methodTypeName,
getMethodWithName: getMethodWithName,
filterFunctions: filterFunctions,
filterEvents: filterEvents
};

33
libjsqrc/ethereumjs/lib/const.js

@ -0,0 +1,33 @@
/*
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 const.js
* @authors:
* Marek Kotewicz <marek@ethdev.com>
* @date 2015
*/
/// required to define ETH_BIGNUMBER_ROUNDING_MODE
if (process.env.NODE_ENV !== 'build') {
var BigNumber = require('bignumber.js'); // jshint ignore:line
}
module.exports = {
ETH_PADDING: 32,
ETH_METHOD_SIGNATURE_LENGTH: 4,
ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }
};

15
libjsqrc/ethereumjs/lib/formatters.js

@ -24,12 +24,8 @@ if (process.env.NODE_ENV !== 'build') {
var BigNumber = require('bignumber.js'); // jshint ignore:line
}
// TODO: remove web3 dependency from here!
var web3 = require('./web3');
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var ETH_PADDING = 32;
var utils = require('./utils');
var c = require('./const');
/// @param string string to be padded
/// @param number of characters that result string should have
@ -44,10 +40,11 @@ var padLeft = function (string, chars, sign) {
/// If the value is floating point, round it down
/// @returns right-aligned byte representation of int
var formatInputInt = function (value) {
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number')
value = new BigNumber(value);
BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
value = value.round();
if (value.lessThan(0))
@ -66,7 +63,7 @@ var formatInputInt = function (value) {
/// Formats input value to byte representation of string
/// @returns left-algined byte representation of string
var formatInputString = function (value) {
return web3.fromAscii(value, ETH_PADDING).substr(2);
return utils.fromAscii(value, c.ETH_PADDING).substr(2);
};
/// Formats input value to byte representation of bool
@ -131,7 +128,7 @@ var formatOutputBool = function (value) {
/// @returns left-aligned input bytes formatted to ascii string
var formatOutputString = function (value) {
return web3.toAscii(value);
return utils.toAscii(value);
};
/// @returns right-aligned input bytes formatted to address

44
libjsqrc/ethereumjs/lib/utils.js

@ -33,7 +33,49 @@ var findIndex = function (array, callback) {
return end ? i - 1 : -1;
};
/// @returns ascii string representation of hex value prefixed with 0x
var toAscii = function(hex) {
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) === '0x') {
i = 2;
}
for (; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if (code === 0) {
break;
}
str += String.fromCharCode(code);
}
return str;
};
var toHex = function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
};
/// @returns hex representation (prefixed by 0x) of ascii string
var fromAscii = function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = toHex(str);
while (hex.length < pad*2)
hex += "00";
return "0x" + hex;
};
module.exports = {
findIndex: findIndex
findIndex: findIndex,
toAscii: toAscii,
fromAscii: fromAscii
};

38
libjsqrc/ethereumjs/lib/web3.js

@ -27,6 +27,8 @@ if (process.env.NODE_ENV !== 'build') {
var BigNumber = require('bignumber.js');
}
var utils = require('./utils');
var ETH_UNITS = [
'wei',
'Kwei',
@ -192,43 +194,11 @@ var web3 = {
_events: {},
providers: {},
toHex: function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
var n = str.charCodeAt(i).toString(16);
hex += n.length < 2 ? '0' + n : n;
}
return hex;
},
/// @returns ascii string representation of hex value prefixed with 0x
toAscii: function(hex) {
// Find termination
var str = "";
var i = 0, l = hex.length;
if (hex.substring(0, 2) === '0x')
i = 2;
for(; i < l; i+=2) {
var code = parseInt(hex.substr(i, 2), 16);
if(code === 0) {
break;
}
str += String.fromCharCode(code);
}
return str;
},
toAscii: utils.toAscii,
/// @returns hex representation (prefixed by 0x) of ascii string
fromAscii: function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = this.toHex(str);
while(hex.length < pad*2)
hex += "00";
return "0x" + hex;
},
fromAscii: utils.fromAscii,
/// @returns decimal representaton of hex value prefixed by 0x
toDecimal: function (val) {

Loading…
Cancel
Save