aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/abi.js16
-rw-r--r--lib/contract.js6
-rw-r--r--lib/web3.js3
-rw-r--r--lib/websocket.js3
4 files changed, 22 insertions, 6 deletions
diff --git a/lib/abi.js b/lib/abi.js
index e37f477ee..5bfcdaf12 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,8 +258,21 @@ 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 || {};
diff --git a/lib/web3.js b/lib/web3.js
index b240bdae2..9a85c4d1b 100644
--- a/lib/web3.js
+++ b/lib/web3.js
@@ -505,4 +505,5 @@ function messageHandler(data) {
}
}
-module.exports = web3;
+if (typeof(module) !== "undefined")
+ module.exports = web3;
diff --git a/lib/websocket.js b/lib/websocket.js
index ddb44aed5..5b40075e4 100644
--- a/lib/websocket.js
+++ b/lib/websocket.js
@@ -74,4 +74,5 @@ Object.defineProperty(WebSocketProvider.prototype, "onmessage", {
set: function(provider) { this.onMessage(provider); }
});
-module.exports = WebSocketProvider;
+if (typeof(module) !== "undefined")
+ module.exports = WebSocketProvider;