constants separated to const.js file

This commit is contained in:
Marek Kotewicz
2015-01-31 14:05:48 +01:00
parent 4bdf52fc1e
commit a8a2e3231c
6 changed files with 104 additions and 58 deletions

View File

@ -21,22 +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;
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var filterFunctions = function (json) {
@ -74,7 +64,7 @@ var inputTypes = types.inputTypes();
/// @returns bytes representation of input params
var toAbiInput = function (method, params) {
var bytes = "";
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
/// first we iterate in search for dynamic
method.inputs.forEach(function (input, index) {
@ -107,7 +97,7 @@ var toAbiInput = function (method, 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;
};
@ -121,7 +111,7 @@ var fromAbiOutput = function (method, output) {
output = output.slice(2);
var result = [];
var padding = ETH_PADDING * 2;
var padding = c.ETH_PADDING * 2;
var dynamicPartLength = method.outputs.reduce(function (acc, curr) {
return acc + dynamicBytesLength(curr.type);
@ -227,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 = {