aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/contract.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-24 01:14:21 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-28 07:35:55 +0800
commit7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d (patch)
treed86868444bc75f746ebd5d22acdaf853a795629e /packages/0x.js/src/contract.ts
parent54ef916b93ba0939dcb8824149c9a9fb74df4f2e (diff)
downloaddexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.gz
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.bz2
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.lz
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.xz
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.tar.zst
dexon-sol-tools-7a21c6854bec32f9a36e8ca3de14a815e9c9fa7d.zip
Add option config for gasPrice and gasLimit for every transaction sending method
Diffstat (limited to 'packages/0x.js/src/contract.ts')
-rw-r--r--packages/0x.js/src/contract.ts22
1 files changed, 17 insertions, 5 deletions
diff --git a/packages/0x.js/src/contract.ts b/packages/0x.js/src/contract.ts
index e9c49c9f1..347f47aa0 100644
--- a/packages/0x.js/src/contract.ts
+++ b/packages/0x.js/src/contract.ts
@@ -34,9 +34,10 @@ export class Contract implements Web3.ContractInstance {
} else {
const cbStyleFunction = this.contract[functionAbi.name];
const cbStyleEstimateGasFunction = this.contract[functionAbi.name].estimateGas;
+ const estimateGasAsync = promisify(cbStyleEstimateGasFunction, this.contract);
this[functionAbi.name] = {
- estimateGasAsync: promisify(cbStyleEstimateGasFunction, this.contract),
- sendTransactionAsync: this.promisifyWithDefaultParams(cbStyleFunction),
+ estimateGasAsync,
+ sendTransactionAsync: this.promisifyWithDefaultParams(cbStyleFunction, estimateGasAsync),
};
}
});
@@ -47,18 +48,29 @@ export class Contract implements Web3.ContractInstance {
this[eventAbi.name] = this.contract[eventAbi.name];
});
}
- private promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise<any> {
+ private promisifyWithDefaultParams(
+ web3CbStyleFunction: (...args: any[]) => void,
+ estimateGasAsync: (...args: any[]) => Promise<number>,
+ ): (...args: any[]) => Promise<any> {
const promisifiedWithDefaultParams = async (...args: any[]) => {
- const promise = new Promise((resolve, reject) => {
+ const promise = new Promise(async (resolve, reject) => {
const lastArg = args[args.length - 1];
let txData: Partial<Web3.TxData> = {};
if (this.isTxData(lastArg)) {
txData = args.pop();
}
+ // Gas amounts priorities:
+ // 1 - method level
+ // 2 - Library defaults
+ // 3 - estimate
txData = {
...this.defaults,
...txData,
};
+ if (_.isUndefined(txData.gas)) {
+ const estimatedGas = await estimateGasAsync.apply(this.contract, [...args, txData]);
+ txData.gas = estimatedGas;
+ }
const callback = (err: Error, data: any) => {
if (_.isNull(err)) {
resolve(data);
@@ -68,7 +80,7 @@ export class Contract implements Web3.ContractInstance {
};
args.push(txData);
args.push(callback);
- fn.apply(this.contract, args);
+ web3CbStyleFunction.apply(this.contract, args);
});
return promise;
};