aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/contract.ts')
-rw-r--r--src/contract.ts28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/contract.ts b/src/contract.ts
index b4a54ca09..0c76571cc 100644
--- a/src/contract.ts
+++ b/src/contract.ts
@@ -2,27 +2,37 @@ import * as Web3 from 'web3';
import * as _ from 'lodash';
import promisify = require('es6-promisify');
-export class Contract<A extends Web3.ContractInstance> implements Web3.ContractInstance {
+export class Contract implements Web3.ContractInstance {
public address: string;
public abi: Web3.ContractAbi;
- private contract: A;
+ private contract: Web3.ContractInstance;
[name: string]: any;
- constructor(web3ContractInstance: A) {
+ constructor(web3ContractInstance: Web3.ContractInstance) {
this.contract = web3ContractInstance;
this.address = web3ContractInstance.address;
this.abi = web3ContractInstance.abi;
+ this.populateEvents();
+ this.populateFunctions();
+ }
+ private populateFunctions(): void {
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function');
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
- const cbStyleFunction = web3ContractInstance[functionAbi.name];
- this[functionAbi.name] = promisify(cbStyleFunction, web3ContractInstance);
+ const cbStyleFunction = this.contract[functionAbi.name];
+ this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
if (functionAbi.constant) {
- const cbStyleCallFunction = web3ContractInstance[functionAbi.name].call;
- this[functionAbi.name].call = promisify(cbStyleCallFunction, web3ContractInstance);
+ const cbStyleCallFunction = this.contract[functionAbi.name].call;
+ this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract);
} else {
- const cbStyleEstimateGasFunction = web3ContractInstance[functionAbi.name].estimateGas;
+ const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
this[functionAbi.name].estimateGas =
- promisify(cbStyleEstimateGasFunction, web3ContractInstance);
+ promisify(cbStyleEstimateGasFunction, this.contract);
}
});
}
+ private populateEvents(): void {
+ const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === 'event');
+ _.forEach(eventsAbi, (eventAbi: Web3.EventAbi) => {
+ this[eventAbi.name] = this.contract[eventAbi.name];
+ });
+ }
}