aboutsummaryrefslogtreecommitdiffstats
path: root/lib/abi.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-31 20:54:39 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-31 20:54:39 +0800
commit4bdf52fc1e5030d53a8b7337051e12ebd0509009 (patch)
tree68a2e7415e035fe946b229bc78ac405f4a4d8710 /lib/abi.js
parent0b82a05a75a0a7592e4fe391120f90d7cee495ac (diff)
downloaddexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar
dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.gz
dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.bz2
dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.lz
dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.xz
dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.tar.zst
dexon-4bdf52fc1e5030d53a8b7337051e12ebd0509009.zip
toAscii && fromAscii moved to utils
Diffstat (limited to 'lib/abi.js')
-rw-r--r--lib/abi.js37
1 files changed, 7 insertions, 30 deletions
diff --git a/lib/abi.js b/lib/abi.js
index fcf787419..1fd3a58fc 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -37,23 +37,6 @@ var ETH_PADDING = 32;
/// method signature length in bytes
var ETH_METHOD_SIGNATURE_LENGTH = 4;
-/// @returns a function that is used as a pattern for 'findIndex'
-var findMethodIndex = function (json, methodName) {
- return utils.findIndex(json, function (method) {
- return method.name === 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];
-};
-
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
var filterFunctions = function (json) {
@@ -86,14 +69,11 @@ var dynamicTypeBytes = function (type, value) {
var inputTypes = types.inputTypes();
/// Formats input params to bytes
-/// @param contract json abi
-/// @param name of the method that we want to use
+/// @param abi contract method
/// @param array of params that will be formatted to bytes
/// @returns bytes representation of input params
-var toAbiInput = function (json, methodName, params) {
+var toAbiInput = function (method, params) {
var bytes = "";
-
- var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
/// first we iterate in search for dynamic
@@ -134,15 +114,13 @@ var dynamicBytesLength = function (type) {
var outputTypes = types.outputTypes();
/// Formats output bytes back to param list
-/// @param contract json abi
-/// @param name of the method that we want to use
+/// @param contract abi method
/// @param bytes representtion of output
/// @returns array of output params
-var fromAbiOutput = function (json, methodName, output) {
+var fromAbiOutput = function (method, output) {
output = output.slice(2);
var result = [];
- var method = getMethodWithName(json, methodName);
var padding = ETH_PADDING * 2;
var dynamicPartLength = method.outputs.reduce(function (acc, curr) {
@@ -194,7 +172,7 @@ var methodDisplayName = function (method) {
/// @returns overloaded part of method's name
var methodTypeName = function (method) {
- /// TODO: make it not vulnerable
+ /// TODO: make it invulnerable
var length = method.indexOf('(');
return length !== -1 ? method.substr(length + 1, method.length - 1 - (length + 1)) : "";
};
@@ -210,7 +188,7 @@ var inputParser = function (json) {
var impl = function () {
var params = Array.prototype.slice.call(arguments);
- return toAbiInput(json, method.name, params);
+ return toAbiInput(method, params);
};
if (parser[displayName] === undefined) {
@@ -233,7 +211,7 @@ var outputParser = function (json) {
var typeName = methodTypeName(method.name);
var impl = function (output) {
- return fromAbiOutput(json, method.name, output);
+ return fromAbiOutput(method, output);
};
if (parser[displayName] === undefined) {
@@ -258,7 +236,6 @@ module.exports = {
methodSignature: methodSignature,
methodDisplayName: methodDisplayName,
methodTypeName: methodTypeName,
- getMethodWithName: getMethodWithName,
filterFunctions: filterFunctions,
filterEvents: filterEvents
};