aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-04 20:45:01 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-04 20:45:01 +0800
commit9818eb2835a8c06006514c44340c95c709f4aa9f (patch)
tree2a9f3c184184b56a0d5e2d5062add5e58564848f /src
parent59fed02a8b044703f569d94ff9dda889812a71b0 (diff)
downloaddexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.tar
dexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.tar.gz
dexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.tar.bz2
dexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.tar.lz
dexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.tar.xz
dexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.tar.zst
dexon-sol-tools-9818eb2835a8c06006514c44340c95c709f4aa9f.zip
Use custom contract abstraction
Diffstat (limited to 'src')
-rw-r--r--src/contract.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/contract.ts b/src/contract.ts
new file mode 100644
index 000000000..b4a54ca09
--- /dev/null
+++ b/src/contract.ts
@@ -0,0 +1,28 @@
+import * as Web3 from 'web3';
+import * as _ from 'lodash';
+import promisify = require('es6-promisify');
+
+export class Contract<A extends Web3.ContractInstance> implements Web3.ContractInstance {
+ public address: string;
+ public abi: Web3.ContractAbi;
+ private contract: A;
+ [name: string]: any;
+ constructor(web3ContractInstance: A) {
+ this.contract = web3ContractInstance;
+ this.address = web3ContractInstance.address;
+ this.abi = web3ContractInstance.abi;
+ 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);
+ if (functionAbi.constant) {
+ const cbStyleCallFunction = web3ContractInstance[functionAbi.name].call;
+ this[functionAbi.name].call = promisify(cbStyleCallFunction, web3ContractInstance);
+ } else {
+ const cbStyleEstimateGasFunction = web3ContractInstance[functionAbi.name].estimateGas;
+ this[functionAbi.name].estimateGas =
+ promisify(cbStyleEstimateGasFunction, web3ContractInstance);
+ }
+ });
+ }
+}