Gas exception warnings on deployment (#3938)
* add deployEstimateGas function * Render gas warning with Warning component * estimateGas, display warning on contract deploy * Update messages * Removed unused import * Fix calculated gas usage * Basic component smoktest * Only display warning on edit steps
This commit is contained in:
@@ -89,9 +89,15 @@ export default class Contract {
|
||||
return this;
|
||||
}
|
||||
|
||||
deploy (options, values, statecb) {
|
||||
let gas;
|
||||
deployEstimateGas (options, values) {
|
||||
return this._api.eth
|
||||
.estimateGas(this._encodeOptions(this.constructors[0], options, values))
|
||||
.then((gasEst) => {
|
||||
return [gasEst, gasEst.mul(1.2)];
|
||||
});
|
||||
}
|
||||
|
||||
deploy (options, values, statecb) {
|
||||
const setState = (state) => {
|
||||
if (!statecb) {
|
||||
return;
|
||||
@@ -102,31 +108,32 @@ export default class Contract {
|
||||
|
||||
setState({ state: 'estimateGas' });
|
||||
|
||||
return this._api.eth
|
||||
.estimateGas(this._encodeOptions(this.constructors[0], options, values))
|
||||
.then((_gas) => {
|
||||
gas = _gas.mul(1.2);
|
||||
return this
|
||||
.deployEstimateGas(options, values)
|
||||
.then(([gasEst, gas]) => {
|
||||
options.gas = gas.toFixed(0);
|
||||
|
||||
setState({ state: 'postTransaction', gas });
|
||||
return this._api.parity.postTransaction(this._encodeOptions(this.constructors[0], options, values));
|
||||
})
|
||||
.then((requestId) => {
|
||||
setState({ state: 'checkRequest', requestId });
|
||||
return this._pollCheckRequest(requestId);
|
||||
})
|
||||
.then((txhash) => {
|
||||
setState({ state: 'getTransactionReceipt', txhash });
|
||||
return this._pollTransactionReceipt(txhash, gas);
|
||||
})
|
||||
.then((receipt) => {
|
||||
if (receipt.gasUsed.eq(gas)) {
|
||||
throw new Error(`Contract not deployed, gasUsed == ${gas.toFixed(0)}`);
|
||||
}
|
||||
|
||||
setState({ state: 'hasReceipt', receipt });
|
||||
this._address = receipt.contractAddress;
|
||||
return this._address;
|
||||
return this._api.parity
|
||||
.postTransaction(this._encodeOptions(this.constructors[0], options, values))
|
||||
.then((requestId) => {
|
||||
setState({ state: 'checkRequest', requestId });
|
||||
return this._pollCheckRequest(requestId);
|
||||
})
|
||||
.then((txhash) => {
|
||||
setState({ state: 'getTransactionReceipt', txhash });
|
||||
return this._pollTransactionReceipt(txhash, gas);
|
||||
})
|
||||
.then((receipt) => {
|
||||
if (receipt.gasUsed.eq(gas)) {
|
||||
throw new Error(`Contract not deployed, gasUsed == ${gas.toFixed(0)}`);
|
||||
}
|
||||
|
||||
setState({ state: 'hasReceipt', receipt });
|
||||
this._address = receipt.contractAddress;
|
||||
return this._address;
|
||||
});
|
||||
})
|
||||
.then((address) => {
|
||||
setState({ state: 'getCode' });
|
||||
|
||||
Reference in New Issue
Block a user