diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-07 01:29:38 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-07 01:29:38 +0800 |
commit | 1d139f7a0b54cd3344e32245a06ed29d92f0ae0b (patch) | |
tree | c0ecff92101487a87d2371624e04ead0787d74dc /lib/abi.js | |
parent | b6232cfdd1f23447d900728be0b142d05aca0009 (diff) | |
download | go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.tar go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.tar.gz go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.tar.bz2 go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.tar.lz go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.tar.xz go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.tar.zst go-tangerine-1d139f7a0b54cd3344e32245a06ed29d92f0ae0b.zip |
solidity string support
Diffstat (limited to 'lib/abi.js')
-rw-r--r-- | lib/abi.js | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/abi.js b/lib/abi.js index 21607f140..e80406ef9 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -21,6 +21,11 @@ * @date 2014 */ +// TODO: is these line is supposed to be here? +if (process.env.NODE_ENV !== 'build') { + var web3 = require('./web3'); // jshint ignore:line +} + // TODO: make these be actually accurate instead of falling back onto JS's doubles. var hexToDec = function (hex) { return parseInt(hex, 16).toString(); @@ -50,16 +55,20 @@ var padLeft = function (string, chars) { }; var setupInputTypes = function () { - var prefixedType = function (prefix) { + // @param prefix is the string prefix of the type + // @param bitsInNumber is number of bits per number in type + var prefixedType = function (prefix, bitsInNumber) { return function (type, value) { var expected = prefix; if (type.indexOf(expected) !== 0) { return false; } - var padding = parseInt(type.slice(expected.length)) / 8; + var padding = parseInt(type.slice(expected.length)) / 8 * bitsInNumber; 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 @@ -83,9 +92,10 @@ var setupInputTypes = function () { }; return [ - prefixedType('uint'), - prefixedType('int'), - prefixedType('hash'), + prefixedType('uint', 1), + prefixedType('int', 1), + prefixedType('hash', 1), + prefixedType('string', 8), namedType('address', 20), namedType('bool', 1, formatBool), ]; @@ -118,14 +128,17 @@ var toAbiInput = function (json, methodName, params) { }; var setupOutputTypes = function () { - var prefixedType = function (prefix) { + + // @param prefix is the string prefix of the type + // @param bitsInNumber is number of bits per number in type + var prefixedType = function (prefix, bitsInNumber) { return function (type) { var expected = prefix; if (type.indexOf(expected) !== 0) { return -1; } - var padding = parseInt(type.slice(expected.length)) / 8; + var padding = parseInt(type.slice(expected.length)) / 8 * bitsInNumber; return padding * 2; }; }; @@ -148,10 +161,15 @@ var setupOutputTypes = function () { return value === '1' ? true : false; }; + var formatString = function (value) { + return web3.toAscii(value); + }; + return [ - { padding: prefixedType('uint'), format: formatInt }, - { padding: prefixedType('int'), format: formatInt }, - { padding: prefixedType('hash'), format: formatHash }, + { padding: prefixedType('uint', 1), format: formatInt }, + { padding: prefixedType('int', 1), format: formatInt }, + { padding: prefixedType('hash', 1), format: formatHash }, + { padding: prefixedType('string', 8), format: formatString }, { padding: namedType('address', 20) }, { padding: namedType('bool', 1), format: formatBool } ]; |