removed padding calculation from ethereum.js, padding is always 32
This commit is contained in:
parent
9a9987aeed
commit
7595a5dfcb
83
dist/ethereum.js
vendored
83
dist/ethereum.js
vendored
@ -55,47 +55,16 @@ var padLeft = function (string, chars) {
|
|||||||
return new Array(chars - string.length + 1).join("0") + string;
|
return new Array(chars - string.length + 1).join("0") + string;
|
||||||
};
|
};
|
||||||
|
|
||||||
var calcBitPadding = function (type, expected) {
|
|
||||||
var value = type.slice(expected.length);
|
|
||||||
if (value === "") {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
return parseInt(value) / 8;
|
|
||||||
};
|
|
||||||
|
|
||||||
var calcBytePadding = function (type, expected) {
|
|
||||||
var value = type.slice(expected.length);
|
|
||||||
if (value === "") {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
return parseInt(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
var calcRealPadding = function (type, expected) {
|
|
||||||
var value = type.slice(expected.length);
|
|
||||||
if (value === "") {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
var sizes = value.split('x');
|
|
||||||
for (var padding = 0, i = 0; i < sizes; i++) {
|
|
||||||
padding += (sizes[i] / 8);
|
|
||||||
}
|
|
||||||
return padding;
|
|
||||||
};
|
|
||||||
|
|
||||||
var setupInputTypes = function () {
|
var setupInputTypes = function () {
|
||||||
|
|
||||||
var prefixedType = function (prefix, calcPadding) {
|
var prefixedType = function (prefix) {
|
||||||
return function (type, value) {
|
return function (type, value) {
|
||||||
var expected = prefix;
|
var expected = prefix;
|
||||||
if (type.indexOf(expected) !== 0) {
|
if (type.indexOf(expected) !== 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var padding = calcPadding(type, expected);
|
var padding = 32; // override as per the new ABI.
|
||||||
if (padding > 32)
|
|
||||||
return false; // not allowed to be so big.
|
|
||||||
padding = 32; // override as per the new ABI.
|
|
||||||
|
|
||||||
if (prefix === "string")
|
if (prefix === "string")
|
||||||
return web3.fromAscii(value, padding).substr(2);
|
return web3.fromAscii(value, padding).substr(2);
|
||||||
@ -111,13 +80,13 @@ var setupInputTypes = function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var namedType = function (name, padding, formatter) {
|
var namedType = function (name, formatter) {
|
||||||
return function (type, value) {
|
return function (type, value) {
|
||||||
if (type !== name) {
|
if (type !== name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
padding = 32; //override as per the new ABI.
|
var padding = 32; //override as per the new ABI.
|
||||||
|
|
||||||
return padLeft(formatter ? formatter(value) : value, padding * 2);
|
return padLeft(formatter ? formatter(value) : value, padding * 2);
|
||||||
};
|
};
|
||||||
@ -128,14 +97,14 @@ var setupInputTypes = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
prefixedType('uint', calcBitPadding),
|
prefixedType('uint'),
|
||||||
prefixedType('int', calcBitPadding),
|
prefixedType('int'),
|
||||||
prefixedType('hash', calcBitPadding),
|
prefixedType('hash'),
|
||||||
prefixedType('string', calcBytePadding),
|
prefixedType('string'),
|
||||||
prefixedType('real', calcRealPadding),
|
prefixedType('real'),
|
||||||
prefixedType('ureal', calcRealPadding),
|
prefixedType('ureal'),
|
||||||
namedType('address', 20),
|
namedType('address'),
|
||||||
namedType('bool', 1, formatBool),
|
namedType('bool', formatBool),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -166,24 +135,20 @@ var toAbiInput = function (json, methodName, params) {
|
|||||||
|
|
||||||
var setupOutputTypes = function () {
|
var setupOutputTypes = function () {
|
||||||
|
|
||||||
var prefixedType = function (prefix, calcPadding) {
|
var prefixedType = function (prefix) {
|
||||||
return function (type) {
|
return function (type) {
|
||||||
var expected = prefix;
|
var expected = prefix;
|
||||||
if (type.indexOf(expected) !== 0) {
|
if (type.indexOf(expected) !== 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
var padding = 32; // override as per the new ABI.
|
||||||
var padding = calcPadding(type, expected);
|
|
||||||
if (padding > 32)
|
|
||||||
return -1; // not allowed to be so big.
|
|
||||||
padding = 32; // override as per the new ABI.
|
|
||||||
return padding * 2;
|
return padding * 2;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var namedType = function (name, padding) {
|
var namedType = function (name) {
|
||||||
return function (type) {
|
return function (type) {
|
||||||
padding = 32; // override as per the new ABI.
|
var padding = 32; // override as per the new ABI.
|
||||||
return name === type ? padding * 2 : -1;
|
return name === type ? padding * 2 : -1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -205,14 +170,14 @@ var setupOutputTypes = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ padding: prefixedType('uint', calcBitPadding), format: formatInt },
|
{ padding: prefixedType('uint'), format: formatInt },
|
||||||
{ padding: prefixedType('int', calcBitPadding), format: formatInt },
|
{ padding: prefixedType('int'), format: formatInt },
|
||||||
{ padding: prefixedType('hash', calcBitPadding), format: formatHash },
|
{ padding: prefixedType('hash'), format: formatHash },
|
||||||
{ padding: prefixedType('string', calcBytePadding), format: formatString },
|
{ padding: prefixedType('string'), format: formatString },
|
||||||
{ padding: prefixedType('real', calcRealPadding), format: formatInt },
|
{ padding: prefixedType('real'), format: formatInt },
|
||||||
{ padding: prefixedType('ureal', calcRealPadding), format: formatInt },
|
{ padding: prefixedType('ureal'), format: formatInt },
|
||||||
{ padding: namedType('address', 20) },
|
{ padding: namedType('address') },
|
||||||
{ padding: namedType('bool', 1), format: formatBool }
|
{ padding: namedType('bool'), format: formatBool }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
4
dist/ethereum.js.map
vendored
4
dist/ethereum.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/ethereum.min.js
vendored
2
dist/ethereum.min.js
vendored
File diff suppressed because one or more lines are too long
83
lib/abi.js
83
lib/abi.js
@ -54,47 +54,16 @@ var padLeft = function (string, chars) {
|
|||||||
return new Array(chars - string.length + 1).join("0") + string;
|
return new Array(chars - string.length + 1).join("0") + string;
|
||||||
};
|
};
|
||||||
|
|
||||||
var calcBitPadding = function (type, expected) {
|
|
||||||
var value = type.slice(expected.length);
|
|
||||||
if (value === "") {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
return parseInt(value) / 8;
|
|
||||||
};
|
|
||||||
|
|
||||||
var calcBytePadding = function (type, expected) {
|
|
||||||
var value = type.slice(expected.length);
|
|
||||||
if (value === "") {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
return parseInt(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
var calcRealPadding = function (type, expected) {
|
|
||||||
var value = type.slice(expected.length);
|
|
||||||
if (value === "") {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
var sizes = value.split('x');
|
|
||||||
for (var padding = 0, i = 0; i < sizes; i++) {
|
|
||||||
padding += (sizes[i] / 8);
|
|
||||||
}
|
|
||||||
return padding;
|
|
||||||
};
|
|
||||||
|
|
||||||
var setupInputTypes = function () {
|
var setupInputTypes = function () {
|
||||||
|
|
||||||
var prefixedType = function (prefix, calcPadding) {
|
var prefixedType = function (prefix) {
|
||||||
return function (type, value) {
|
return function (type, value) {
|
||||||
var expected = prefix;
|
var expected = prefix;
|
||||||
if (type.indexOf(expected) !== 0) {
|
if (type.indexOf(expected) !== 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var padding = calcPadding(type, expected);
|
var padding = 32; // override as per the new ABI.
|
||||||
if (padding > 32)
|
|
||||||
return false; // not allowed to be so big.
|
|
||||||
padding = 32; // override as per the new ABI.
|
|
||||||
|
|
||||||
if (prefix === "string")
|
if (prefix === "string")
|
||||||
return web3.fromAscii(value, padding).substr(2);
|
return web3.fromAscii(value, padding).substr(2);
|
||||||
@ -110,13 +79,13 @@ var setupInputTypes = function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var namedType = function (name, padding, formatter) {
|
var namedType = function (name, formatter) {
|
||||||
return function (type, value) {
|
return function (type, value) {
|
||||||
if (type !== name) {
|
if (type !== name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
padding = 32; //override as per the new ABI.
|
var padding = 32; //override as per the new ABI.
|
||||||
|
|
||||||
return padLeft(formatter ? formatter(value) : value, padding * 2);
|
return padLeft(formatter ? formatter(value) : value, padding * 2);
|
||||||
};
|
};
|
||||||
@ -127,14 +96,14 @@ var setupInputTypes = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
prefixedType('uint', calcBitPadding),
|
prefixedType('uint'),
|
||||||
prefixedType('int', calcBitPadding),
|
prefixedType('int'),
|
||||||
prefixedType('hash', calcBitPadding),
|
prefixedType('hash'),
|
||||||
prefixedType('string', calcBytePadding),
|
prefixedType('string'),
|
||||||
prefixedType('real', calcRealPadding),
|
prefixedType('real'),
|
||||||
prefixedType('ureal', calcRealPadding),
|
prefixedType('ureal'),
|
||||||
namedType('address', 20),
|
namedType('address'),
|
||||||
namedType('bool', 1, formatBool),
|
namedType('bool', formatBool),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,24 +134,20 @@ var toAbiInput = function (json, methodName, params) {
|
|||||||
|
|
||||||
var setupOutputTypes = function () {
|
var setupOutputTypes = function () {
|
||||||
|
|
||||||
var prefixedType = function (prefix, calcPadding) {
|
var prefixedType = function (prefix) {
|
||||||
return function (type) {
|
return function (type) {
|
||||||
var expected = prefix;
|
var expected = prefix;
|
||||||
if (type.indexOf(expected) !== 0) {
|
if (type.indexOf(expected) !== 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
var padding = 32; // override as per the new ABI.
|
||||||
var padding = calcPadding(type, expected);
|
|
||||||
if (padding > 32)
|
|
||||||
return -1; // not allowed to be so big.
|
|
||||||
padding = 32; // override as per the new ABI.
|
|
||||||
return padding * 2;
|
return padding * 2;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var namedType = function (name, padding) {
|
var namedType = function (name) {
|
||||||
return function (type) {
|
return function (type) {
|
||||||
padding = 32; // override as per the new ABI.
|
var padding = 32; // override as per the new ABI.
|
||||||
return name === type ? padding * 2 : -1;
|
return name === type ? padding * 2 : -1;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -204,14 +169,14 @@ var setupOutputTypes = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ padding: prefixedType('uint', calcBitPadding), format: formatInt },
|
{ padding: prefixedType('uint'), format: formatInt },
|
||||||
{ padding: prefixedType('int', calcBitPadding), format: formatInt },
|
{ padding: prefixedType('int'), format: formatInt },
|
||||||
{ padding: prefixedType('hash', calcBitPadding), format: formatHash },
|
{ padding: prefixedType('hash'), format: formatHash },
|
||||||
{ padding: prefixedType('string', calcBytePadding), format: formatString },
|
{ padding: prefixedType('string'), format: formatString },
|
||||||
{ padding: prefixedType('real', calcRealPadding), format: formatInt },
|
{ padding: prefixedType('real'), format: formatInt },
|
||||||
{ padding: prefixedType('ureal', calcRealPadding), format: formatInt },
|
{ padding: prefixedType('ureal'), format: formatInt },
|
||||||
{ padding: namedType('address', 20) },
|
{ padding: namedType('address') },
|
||||||
{ padding: namedType('bool', 1), format: formatBool }
|
{ padding: namedType('bool'), format: formatBool }
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user