aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-09 19:55:04 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-01-09 19:55:04 +0800
commit0538c11576a020a0e7fe19652398547fdad4b84b (patch)
tree48da1c79361403f9739be8014e94b68bfbf16a2c /lib
parent807ec60e63e54f648bea47037c307b63d1bc6c04 (diff)
downloaddexon-0538c11576a020a0e7fe19652398547fdad4b84b.tar.gz
dexon-0538c11576a020a0e7fe19652398547fdad4b84b.tar.zst
dexon-0538c11576a020a0e7fe19652398547fdad4b84b.zip
sha3 method signature
Diffstat (limited to 'lib')
-rw-r--r--lib/abi.js16
-rw-r--r--lib/contract.js6
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/abi.js b/lib/abi.js
index 5a4d64515..80cc0d551 100644
--- a/lib/abi.js
+++ b/lib/abi.js
@@ -140,7 +140,6 @@ var toAbiInput = function (json, methodName, params) {
return;
}
- bytes = "0x" + padLeft(index.toString(16), 2);
var method = json[index];
for (var i = 0; i < method.inputs.length; i++) {
@@ -259,7 +258,20 @@ var outputParser = function (json) {
return parser;
};
+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(result);
+};
+
module.exports = {
inputParser: inputParser,
- outputParser: outputParser
+ outputParser: outputParser,
+ methodSignature: methodSignature
};
diff --git a/lib/contract.js b/lib/contract.js
index b10339003..1a03849bf 100644
--- a/lib/contract.js
+++ b/lib/contract.js
@@ -46,8 +46,10 @@ var contract = function (address, desc) {
call: function (extra) {
extra = extra || {};
extra.to = address;
- extra.data = parsed;
- return web3.eth.call(extra).then(onSuccess);
+ return abi.methodSignature(desc, method.name).then(function (signature) {
+ extra.data = signature.slice(0, 10) + parsed;
+ return web3.eth.call(extra).then(onSuccess);
+ });
},
transact: function (extra) {
extra = extra || {};