aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-31 21:05:48 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-31 21:05:48 +0800
commita8a2e3231c2ced50989dc5d23659f7482a667f69 (patch)
tree8529faaa567708c9e4955f613317911e6e8aad0f /lib
parent4bdf52fc1e5030d53a8b7337051e12ebd0509009 (diff)
downloadgo-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.tar
go-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.tar.gz
go-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.tar.bz2
go-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.tar.lz
go-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.tar.xz
go-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.tar.zst
go-tangerine-a8a2e3231c2ced50989dc5d23659f7482a667f69.zip
constants separated to const.js file
Diffstat (limited to 'lib')
-rw-r--r--lib/abi.js20
-rw-r--r--lib/const.js33
-rw-r--r--lib/formatters.js10
3 files changed, 42 insertions, 21 deletions
diff --git a/lib/abi.js b/lib/abi.js
index 1fd3a58fc..01d2debb7 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -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 = {
diff --git a/lib/const.js b/lib/const.js
new file mode 100644
index 000000000..69ed5a09b
--- /dev/null
+++ b/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 }
+};
+
diff --git a/lib/formatters.js b/lib/formatters.js
index d8781e21e..857a01a40 100644
--- a/lib/formatters.js
+++ b/lib/formatters.js
@@ -25,10 +25,7 @@ if (process.env.NODE_ENV !== 'build') {
}
var utils = require('./utils');
-
-BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
-
-var ETH_PADDING = 32;
+var c = require('./const');
/// @param string string to be padded
/// @param number of characters that result string should have
@@ -43,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))
@@ -65,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 utils.fromAscii(value, ETH_PADDING).substr(2);
+ return utils.fromAscii(value, c.ETH_PADDING).substr(2);
};
/// Formats input value to byte representation of bool