diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-27 21:05:06 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-27 21:05:30 +0800 |
commit | ad7c05778f3aa2d4b42c9fa401f57b24370f65ad (patch) | |
tree | 46ac4543f0ae4b3508956d56dd48068598555dfc /lib/abi.js | |
parent | f02368141f11511c06306184df0eda372382c2bf (diff) | |
download | dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.tar dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.tar.gz dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.tar.bz2 dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.tar.lz dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.tar.xz dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.tar.zst dexon-ad7c05778f3aa2d4b42c9fa401f57b24370f65ad.zip |
getMethodWithName
Diffstat (limited to 'lib/abi.js')
-rw-r--r-- | lib/abi.js | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/abi.js b/lib/abi.js index d81c2f0c3..0989f4e15 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -55,6 +55,16 @@ var findMethodIndex = function (json, methodName) { }); }; +/// @returns method with given method name +var getMethodWithName = function (json, methodName) { + var index = findMethodIndex(json, methodName); + if (index === -1) { + console.error('method ' + methodName + ' not found in the abi'); + return undefined; + } + return json[index]; +}; + /// @param string string to be padded /// @param number of characters that result string should have /// @param sign, by default 0 @@ -158,13 +168,8 @@ var inputTypes = setupInputTypes(); /// @returns bytes representation of input params var toAbiInput = function (json, methodName, params) { var bytes = ""; - var index = findMethodIndex(json, methodName); - - if (index === -1) { - return; - } - var method = json[index]; + var method = getMethodWithName(json, methodName); var padding = ETH_PADDING * 2; /// first we iterate in search for dynamic @@ -280,16 +285,10 @@ var outputTypes = setupOutputTypes(); /// @param bytes representtion of output /// @returns array of output params var fromAbiOutput = function (json, methodName, output) { - var index = findMethodIndex(json, methodName); - - if (index === -1) { - return; - } - + output = output.slice(2); - var result = []; - var method = json[index]; + var method = getMethodWithName(json, methodName); var padding = ETH_PADDING * 2; var dynamicPartLength = method.outputs.reduce(function (acc, curr) { @@ -403,6 +402,7 @@ module.exports = { outputParser: outputParser, methodSignature: methodSignature, methodDisplayName: methodDisplayName, - methodTypeName: methodTypeName + methodTypeName: methodTypeName, + getMethodWithName: getMethodWithName }; |