Commit e94da808 authored by Marek Kotewicz's avatar Marek Kotewicz

default padding set to 32, separated to one variable

parent a1c0bb68
...@@ -31,6 +31,8 @@ var web3 = require('./web3'); // jshint ignore:line ...@@ -31,6 +31,8 @@ var web3 = require('./web3'); // jshint ignore:line
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN }); BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var ETH_PADDING = 32;
// TODO: make these be actually accurate instead of falling back onto JS's doubles. // TODO: make these be actually accurate instead of falling back onto JS's doubles.
var hexToDec = function (hex) { var hexToDec = function (hex) {
return parseInt(hex, 16).toString(); return parseInt(hex, 16).toString();
...@@ -93,7 +95,7 @@ var setupInputTypes = function () { ...@@ -93,7 +95,7 @@ var setupInputTypes = function () {
/// If the value is floating point, round it down /// If the value is floating point, round it down
/// @returns right-aligned byte representation of int /// @returns right-aligned byte representation of int
var formatInt = function (value) { var formatInt = function (value) {
var padding = 32 * 2; var padding = ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') { if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number') if (typeof value === 'number')
value = new BigNumber(value); value = new BigNumber(value);
...@@ -115,7 +117,7 @@ var setupInputTypes = function () { ...@@ -115,7 +117,7 @@ var setupInputTypes = function () {
/// Formats input value to byte representation of string /// Formats input value to byte representation of string
/// @returns left-algined byte representation of string /// @returns left-algined byte representation of string
var formatString = function (value) { var formatString = function (value) {
return web3.fromAscii(value, 32).substr(2); return web3.fromAscii(value, ETH_PADDING).substr(2);
}; };
/// Formats input value to byte representation of bool /// Formats input value to byte representation of bool
...@@ -152,7 +154,7 @@ var toAbiInput = function (json, methodName, params) { ...@@ -152,7 +154,7 @@ var toAbiInput = function (json, methodName, params) {
} }
var method = json[index]; var method = json[index];
var padding = 32 * 2; var padding = ETH_PADDING * 2;
for (var i = 0; i < method.inputs.length; i++) { for (var i = 0; i < method.inputs.length; i++) {
var typeMatch = false; var typeMatch = false;
...@@ -241,7 +243,7 @@ var fromAbiOutput = function (json, methodName, output) { ...@@ -241,7 +243,7 @@ var fromAbiOutput = function (json, methodName, output) {
var result = []; var result = [];
var method = json[index]; var method = json[index];
var padding = 32 * 2; var padding = ETH_PADDING * 2;
for (var i = 0; i < method.outputs.length; i++) { for (var i = 0; i < method.outputs.length; i++) {
var typeMatch = false; var typeMatch = false;
for (var j = 0; j < outputTypes.length && !typeMatch; j++) { for (var j = 0; j < outputTypes.length && !typeMatch; j++) {
......
This diff is collapsed.
This diff is collapsed.
...@@ -30,6 +30,8 @@ var web3 = require('./web3'); // jshint ignore:line ...@@ -30,6 +30,8 @@ var web3 = require('./web3'); // jshint ignore:line
BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN }); BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
var ETH_PADDING = 32;
// TODO: make these be actually accurate instead of falling back onto JS's doubles. // TODO: make these be actually accurate instead of falling back onto JS's doubles.
var hexToDec = function (hex) { var hexToDec = function (hex) {
return parseInt(hex, 16).toString(); return parseInt(hex, 16).toString();
...@@ -92,7 +94,7 @@ var setupInputTypes = function () { ...@@ -92,7 +94,7 @@ var setupInputTypes = function () {
/// If the value is floating point, round it down /// If the value is floating point, round it down
/// @returns right-aligned byte representation of int /// @returns right-aligned byte representation of int
var formatInt = function (value) { var formatInt = function (value) {
var padding = 32 * 2; var padding = ETH_PADDING * 2;
if (value instanceof BigNumber || typeof value === 'number') { if (value instanceof BigNumber || typeof value === 'number') {
if (typeof value === 'number') if (typeof value === 'number')
value = new BigNumber(value); value = new BigNumber(value);
...@@ -114,7 +116,7 @@ var setupInputTypes = function () { ...@@ -114,7 +116,7 @@ var setupInputTypes = function () {
/// Formats input value to byte representation of string /// Formats input value to byte representation of string
/// @returns left-algined byte representation of string /// @returns left-algined byte representation of string
var formatString = function (value) { var formatString = function (value) {
return web3.fromAscii(value, 32).substr(2); return web3.fromAscii(value, ETH_PADDING).substr(2);
}; };
/// Formats input value to byte representation of bool /// Formats input value to byte representation of bool
...@@ -151,7 +153,7 @@ var toAbiInput = function (json, methodName, params) { ...@@ -151,7 +153,7 @@ var toAbiInput = function (json, methodName, params) {
} }
var method = json[index]; var method = json[index];
var padding = 32 * 2; var padding = ETH_PADDING * 2;
for (var i = 0; i < method.inputs.length; i++) { for (var i = 0; i < method.inputs.length; i++) {
var typeMatch = false; var typeMatch = false;
...@@ -240,7 +242,7 @@ var fromAbiOutput = function (json, methodName, output) { ...@@ -240,7 +242,7 @@ var fromAbiOutput = function (json, methodName, output) {
var result = []; var result = [];
var method = json[index]; var method = json[index];
var padding = 32 * 2; var padding = ETH_PADDING * 2;
for (var i = 0; i < method.outputs.length; i++) { for (var i = 0; i < method.outputs.length; i++) {
var typeMatch = false; var typeMatch = false;
for (var j = 0; j < outputTypes.length && !typeMatch; j++) { for (var j = 0; j < outputTypes.length && !typeMatch; j++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment