Skip to content

Commit

Permalink
fixes calling overloaded functions
Browse files Browse the repository at this point in the history
preserves web3 syntax
  • Loading branch information
Marcin Rudolf committed Sep 28, 2017
1 parent c32d6c9 commit ecae099
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,24 @@ var contract = (function(module) {
for (var i = 0; i < this.abi.length; i++) {
var item = this.abi[i];
if (item.type == "function") {
if (item.constant == true) {
this[item.name] = Utils.promisifyFunction(contract[item.name], constructor);
} else {
this[item.name] = Utils.synchronizeFunction(contract[item.name], this, constructor);
}

this[item.name].call = Utils.promisifyFunction(contract[item.name].call, constructor);
this[item.name].sendTransaction = Utils.promisifyFunction(contract[item.name].sendTransaction, constructor);
this[item.name].request = contract[item.name].request;
this[item.name].estimateGas = Utils.promisifyFunction(contract[item.name].estimateGas, constructor);
var wrapFunction = function(isConstant, web3Func) {
var wrapped = isConstant ? Utils.promisifyFunction(web3Func, constructor) :
Utils.synchronizeFunction(web3Func, this, constructor);
wrapped.call = Utils.promisifyFunction(web3Func.call, constructor);
wrapped.sendTransaction = Utils.promisifyFunction(web3Func.sendTransaction, constructor);
wrapped.request = web3Func.request;
wrapped.estimateGas = Utils.promisifyFunction(web3Func.estimateGas, constructor);

return wrapped;
};

this[item.name] = wrapFunction(item.constant, contract[item.name]);
if (item.inputs.length > 0) {
var argsString = item.inputs.reduce(function(concat, curr) { return concat + "," + curr["type"]}, "").substring(1);
// console.log(argsString);
this[item.name][argsString] = wrapFunction(item.constant, contract[item.name][argsString]);
}
}

if (item.type == "event") {
Expand Down

0 comments on commit ecae099

Please sign in to comment.