aboutsummaryrefslogtreecommitdiffstats
path: root/lib/abi.js
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-20 22:06:05 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-20 22:06:05 +0800
commit380c1522ac450fdafe9bfb8e2d2f60fdfe918745 (patch)
tree8ec905b875a77a86f279f174a32e413ebe22a25a /lib/abi.js
parent6a58db66f7f42a49667bcc751418256441752279 (diff)
downloaddexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.tar
dexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.tar.gz
dexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.tar.bz2
dexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.tar.lz
dexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.tar.xz
dexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.tar.zst
dexon-380c1522ac450fdafe9bfb8e2d2f60fdfe918745.zip
solidity methods "overloading"
Diffstat (limited to 'lib/abi.js')
-rw-r--r--lib/abi.js50
1 files changed, 38 insertions, 12 deletions
diff --git a/lib/abi.js b/lib/abi.js
index 72001eaa0..c896ab28a 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -330,15 +330,37 @@ var fromAbiOutput = function (json, methodName, output) {
return result;
};
+/// @returns display name for method eg. multiply(uint256) -> multiply
+var methodDisplayName = function (method) {
+ var length = method.indexOf('(');
+ return length !== -1 ? method.substr(0, length) : method;
+};
+
+/// @returns overloaded part of method's name
+var methodTypeName = function (method) {
+ /// TODO: make it not vulnerable
+ var length = method.indexOf('(');
+ return length !== -1 ? method.substr(length + 1, method.length - 1 - (length + 1)) : "";
+};
+
/// @param json abi for contract
/// @returns input parser object for given json abi
var inputParser = function (json) {
var parser = {};
json.forEach(function (method) {
- parser[method.name] = function () {
+ var displayName = methodDisplayName(method.name);
+ var typeName = methodTypeName(method.name);
+
+ var impl = function () {
var params = Array.prototype.slice.call(arguments);
return toAbiInput(json, method.name, params);
};
+
+ if (parser[displayName] === undefined) {
+ parser[displayName] = impl;
+ }
+
+ parser[displayName][typeName] = impl;
});
return parser;
@@ -349,9 +371,19 @@ var inputParser = function (json) {
var outputParser = function (json) {
var parser = {};
json.forEach(function (method) {
- parser[method.name] = function (output) {
+
+ var displayName = methodDisplayName(method.name);
+ var typeName = methodTypeName(method.name);
+
+ var impl = function (output) {
return fromAbiOutput(json, method.name, output);
};
+
+ if (parser[displayName] === undefined) {
+ parser[displayName] = impl;
+ }
+
+ parser[displayName][typeName] = impl;
});
return parser;
@@ -361,20 +393,14 @@ var outputParser = function (json) {
/// @param method name for which we want to get method signature
/// @returns (promise) contract method signature for method with given name
var methodSignature = function (json, name) {
- var method = json[findMethodIndex(json, name)];
- var result = name + '(';
- var inputTypes = method.inputs.map(function (inp) {
- return inp.type;
- });
- result += inputTypes.join(',');
- result += ')';
-
- return web3.sha3(web3.fromAscii(result));
+ return web3.sha3(web3.fromAscii(name));
};
module.exports = {
inputParser: inputParser,
outputParser: outputParser,
- methodSignature: methodSignature
+ methodSignature: methodSignature,
+ methodDisplayName: methodDisplayName,
+ methodTypeName: methodTypeName
};