aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-05 17:38:28 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-05 17:38:28 +0800
commita12df1c73a97b3ba18ab53c1b25be39b837f6240 (patch)
tree6d9ea6902ad1011b0395fc62fa89e89eca259dd9 /src/contract.ts
parent876032a8a71f9eedbf3394727dbc0ea513100836 (diff)
downloaddexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.tar
dexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.tar.gz
dexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.tar.bz2
dexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.tar.lz
dexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.tar.xz
dexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.tar.zst
dexon-sol-tools-a12df1c73a97b3ba18ab53c1b25be39b837f6240.zip
Fix gasPrice regression
Diffstat (limited to 'src/contract.ts')
-rw-r--r--src/contract.ts34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/contract.ts b/src/contract.ts
index 0c76571cc..3592e0e71 100644
--- a/src/contract.ts
+++ b/src/contract.ts
@@ -6,11 +6,13 @@ export class Contract implements Web3.ContractInstance {
public address: string;
public abi: Web3.ContractAbi;
private contract: Web3.ContractInstance;
+ private defaults: Partial<Web3.TxData>;
[name: string]: any;
- constructor(web3ContractInstance: Web3.ContractInstance) {
+ constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<Web3.TxData>) {
this.contract = web3ContractInstance;
this.address = web3ContractInstance.address;
this.abi = web3ContractInstance.abi;
+ this.defaults = defaults;
this.populateEvents();
this.populateFunctions();
}
@@ -18,11 +20,12 @@ export class Contract implements Web3.ContractInstance {
const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === 'function');
_.forEach(functionsAbi, (functionAbi: Web3.MethodAbi) => {
const cbStyleFunction = this.contract[functionAbi.name];
- this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
if (functionAbi.constant) {
+ this[functionAbi.name] = promisify(cbStyleFunction, this.contract);
const cbStyleCallFunction = this.contract[functionAbi.name].call;
this[functionAbi.name].call = promisify(cbStyleCallFunction, this.contract);
} else {
+ this[functionAbi.name] = this.promisifyWithDefaultParams(cbStyleFunction);
const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
this[functionAbi.name].estimateGas =
promisify(cbStyleEstimateGasFunction, this.contract);
@@ -35,4 +38,31 @@ export class Contract implements Web3.ContractInstance {
this[eventAbi.name] = this.contract[eventAbi.name];
});
}
+ private promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise<any> {
+ const promisifiedWithDefaultParams = (...args: any[]) => {
+ const promise = new Promise((resolve, reject) => {
+ const lastArg = args[args.length - 1];
+ let txData: Partial<Web3.TxData> = {};
+ if (_.isObject(lastArg) && !_.isArray(lastArg) && !lastArg.isBigNumber) {
+ txData = args.pop();
+ }
+ txData = {
+ ...txData,
+ ...this.defaults,
+ };
+ const callback = (err: Error, data: any) => {
+ if (_.isNull(err)) {
+ resolve(data);
+ } else {
+ reject(err);
+ }
+ };
+ args.push(txData);
+ args.push(callback);
+ fn.apply(this.contract, args);
+ });
+ return promise;
+ };
+ return promisifiedWithDefaultParams;
+ }
}