mirror of https://github.com/embarklabs/embark.git
extend with current contract methods
This commit is contained in:
parent
29599112de
commit
22021ccca9
23
js/embark.js
23
js/embark.js
|
@ -30,6 +30,29 @@ EmbarkJS.Contract = function(options) {
|
||||||
ContractClass.options.data = this.code;
|
ContractClass.options.data = this.code;
|
||||||
ContractClass.abi = ContractClass.options.abi;
|
ContractClass.abi = ContractClass.options.abi;
|
||||||
ContractClass.address = this.address;
|
ContractClass.address = this.address;
|
||||||
|
|
||||||
|
let originalMethods = Object.keys(ContractClass);
|
||||||
|
|
||||||
|
ContractClass._jsonInterface.forEach((abi) => {
|
||||||
|
if (originalMethods.indexOf(abi.name) >= 0) {
|
||||||
|
console.log(abi.name + " is a reserved word and cannot be used as a contract method, property or event");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (abi.constant) {
|
||||||
|
ContractClass[abi.name] = function() {
|
||||||
|
let ref = ContractClass.methods[abi.name];
|
||||||
|
let send = ref.apply(ref, ..arguments).send;
|
||||||
|
return send.apply(call, []);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
ContractClass[abi.name] = function() {
|
||||||
|
let ref = ContractClass.methods[abi.name];
|
||||||
|
let call = ref.apply(ref, ..arguments).call;
|
||||||
|
return call.apply(call, []);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return ContractClass;
|
return ContractClass;
|
||||||
} else {
|
} else {
|
||||||
ContractClass = this.web3.eth.contract(this.abi);
|
ContractClass = this.web3.eth.contract(this.abi);
|
||||||
|
|
Loading…
Reference in New Issue