mirror of https://github.com/embarklabs/embark.git
Merge pull request #618 from embark-framework/bug_fix/deployment-stuck
Fix deployment getting stuck
This commit is contained in:
commit
4882333e85
|
@ -240,13 +240,58 @@ class Blockchain {
|
||||||
}
|
}
|
||||||
|
|
||||||
deployContractFromObject(deployContractObject, params, cb) {
|
deployContractFromObject(deployContractObject, params, cb) {
|
||||||
|
const self = this;
|
||||||
|
let hash;
|
||||||
|
let calledBacked = false;
|
||||||
|
|
||||||
|
function callback(err, receipt) {
|
||||||
|
if (calledBacked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!err && !receipt.contractAddress) {
|
||||||
|
return; // Not deployed yet. Need to wait
|
||||||
|
}
|
||||||
|
if (interval) {
|
||||||
|
clearInterval(interval);
|
||||||
|
}
|
||||||
|
calledBacked = true;
|
||||||
|
cb(err, receipt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This interval is there to compensate for the event that sometimes doesn't get triggered when using WebSocket
|
||||||
|
// FIXME The issue somehow only happens when the blockchain node is started in the same terminal
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
if (!hash) {
|
||||||
|
return; // Wait until we receive the hash
|
||||||
|
}
|
||||||
|
self.web3.eth.getTransactionReceipt(hash, (err, receipt) => {
|
||||||
|
if (!err && !receipt) {
|
||||||
|
return; // Transaction is not yet complete
|
||||||
|
}
|
||||||
|
callback(err, receipt);
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
|
||||||
deployContractObject.send({
|
deployContractObject.send({
|
||||||
from: params.from, gas: params.gas, gasPrice: params.gasPrice
|
from: params.from, gas: params.gas, gasPrice: params.gasPrice
|
||||||
}).on('receipt', function(receipt) {
|
}, function (err, transactionHash) {
|
||||||
if (receipt.contractAddress !== undefined) {
|
if (err) {
|
||||||
cb(null, receipt);
|
return callback(err);
|
||||||
}
|
}
|
||||||
}).on('error', cb);
|
hash = transactionHash;
|
||||||
|
})
|
||||||
|
.on('receipt', function (receipt) {
|
||||||
|
if (receipt.contractAddress !== undefined) {
|
||||||
|
callback(null, receipt);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(function (_contract) {
|
||||||
|
if (!hash) {
|
||||||
|
return; // Somehow we didn't get the receipt yet... Interval will catch it
|
||||||
|
}
|
||||||
|
self.web3.eth.getTransactionReceipt(hash, callback);
|
||||||
|
})
|
||||||
|
.catch(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNodeConnection(noLogs, cb) {
|
assertNodeConnection(noLogs, cb) {
|
||||||
|
|
Loading…
Reference in New Issue