diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 00:14:48 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-09-05 00:14:48 +0800 |
commit | 1ad395cf86b2006c09bdae814607c2baf9790b91 (patch) | |
tree | d05ed1febd8979b7967a42faaed45c3dd10356dd /src/contract.ts | |
parent | 1c2d4cbb1af9a5d4442857def622dc8068086953 (diff) | |
download | dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.gz dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.bz2 dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.lz dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.xz dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.tar.zst dexon-0x-contracts-1ad395cf86b2006c09bdae814607c2baf9790b91.zip |
Make the functions immidiately return txHash instead of awaiting for a transaction to be mined
Diffstat (limited to 'src/contract.ts')
-rw-r--r-- | src/contract.ts | 28 |
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]; + }); + } } |