aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2015-01-13 19:04:31 +0800
committerGav Wood <i@gavwood.com>2015-01-13 19:04:31 +0800
commite95bb34ea0ebc55eda5fed3db93efc93f9408fe0 (patch)
treee550bc4917e46338da702b779ec93450286ccebe
parent9a9987aeed7d1f82dd6b80a5d0ef24dfe668e630 (diff)
downloaddexon-e95bb34ea0ebc55eda5fed3db93efc93f9408fe0.tar.gz
dexon-e95bb34ea0ebc55eda5fed3db93efc93f9408fe0.tar.zst
dexon-e95bb34ea0ebc55eda5fed3db93efc93f9408fe0.zip
Fix for JS API formatting.
-rw-r--r--lib/abi.js26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/abi.js b/lib/abi.js
index cae4f7519..1a88317bc 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -84,6 +84,18 @@ var calcRealPadding = function (type, expected) {
var setupInputTypes = function () {
+ // convert from int, decimal-string, prefixed hex string whatever into a bare hex string.
+ var formatStandard = function (value) {
+ if (typeof value === "number")
+ return value.toString(16);
+ else if (typeof value === "string" && value.indexOf('0x') === 0)
+ return value.substr(2);
+ else if (typeof value === "string")
+ return web3.toHex(value);
+ else
+ return (+value).toString(16);
+ };
+
var prefixedType = function (prefix, calcPadding) {
return function (type, value) {
var expected = prefix;
@@ -98,15 +110,7 @@ var setupInputTypes = function () {
if (prefix === "string")
return web3.fromAscii(value, padding).substr(2);
- if (typeof value === "number")
- value = value.toString(16);
- else if (typeof value === "string")
- value = web3.toHex(value);
- else if (value.indexOf('0x') === 0)
- value = value.substr(2);
- else
- value = (+value).toString(16);
- return padLeft(value, padding * 2);
+ return padLeft(formatStandard(value), padding * 2);
};
};
@@ -123,7 +127,7 @@ var setupInputTypes = function () {
};
var formatBool = function (value) {
- return value ? '0x1' : '0x0';
+ return value ? '01' : '00';
};
return [
@@ -133,7 +137,7 @@ var setupInputTypes = function () {
prefixedType('string', calcBytePadding),
prefixedType('real', calcRealPadding),
prefixedType('ureal', calcRealPadding),
- namedType('address', 20),
+ namedType('address', 20, formatStandard),
namedType('bool', 1, formatBool),
];
};