mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-17 01:37:26 +00:00
fix contract deployment; timeout & retry
This commit is contained in:
parent
dec7ae8a94
commit
3a1828f1f6
@ -3,7 +3,12 @@ var fs = require('fs');
|
|||||||
var grunt = require('grunt');
|
var grunt = require('grunt');
|
||||||
var readYaml = require('read-yaml');
|
var readYaml = require('read-yaml');
|
||||||
var Config = require('./config/config.js');
|
var Config = require('./config/config.js');
|
||||||
var sleep = require('sleep');
|
|
||||||
|
// Ugly, but sleep lib has issues on osx
|
||||||
|
sleep = function sleep(ms) {
|
||||||
|
var start = new Date().getTime();
|
||||||
|
while (new Date().getTime() < start + ms);
|
||||||
|
}
|
||||||
|
|
||||||
Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
|
Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
|
||||||
//this.blockchainConfig = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
|
//this.blockchainConfig = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
|
||||||
@ -25,6 +30,20 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
|
|||||||
console.log("primary account address is : " + primaryAddress);
|
console.log("primary account address is : " + primaryAddress);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Deploy.prototype.deploy_contract = function(contractObject, contractParams) {
|
||||||
|
var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash;
|
||||||
|
var receipt = null;
|
||||||
|
var time = 0;
|
||||||
|
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null || receipt.contractAddress === null) {
|
||||||
|
sleep(1000);
|
||||||
|
time += 1;
|
||||||
|
if (time >= 20) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return receipt;
|
||||||
|
}
|
||||||
|
|
||||||
Deploy.prototype.deploy_contracts = function(env) {
|
Deploy.prototype.deploy_contracts = function(env) {
|
||||||
this.contractsManager.compileContracts(env);
|
this.contractsManager.compileContracts(env);
|
||||||
all_contracts = this.contractsManager.all_contracts;
|
all_contracts = this.contractsManager.all_contracts;
|
||||||
@ -64,16 +83,12 @@ Deploy.prototype.deploy_contracts = function(env) {
|
|||||||
gasPrice: contract.gasPrice
|
gasPrice: contract.gasPrice
|
||||||
});
|
});
|
||||||
|
|
||||||
var transactionHash = contractObject["new"].apply(contractObject, contractParams).transactionHash;
|
|
||||||
// TODO: get this with sync until a different mechanism is implemented
|
|
||||||
//this.deployedContracts[className] = contractAddress;
|
|
||||||
//console.log("address is " + contractAddress);
|
|
||||||
|
|
||||||
console.log('trying to obtain ' + className + ' address...');
|
console.log('trying to obtain ' + className + ' address...');
|
||||||
var receipt = null;
|
|
||||||
while ((receipt = web3.eth.getTransactionReceipt(transactionHash)) === null || receipt.contractAddress === null) {
|
while((receipt = this.deploy_contract(contractObject, contractParams)) === false) {
|
||||||
sleep.sleep(1);
|
console.log("timeout... failed to deploy contract.. retrying...");
|
||||||
}
|
}
|
||||||
|
|
||||||
var contractAddress = receipt.contractAddress;
|
var contractAddress = receipt.contractAddress;
|
||||||
this.deployedContracts[className] = contractAddress;
|
this.deployedContracts[className] = contractAddress;
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
"python": "^0.0.4",
|
"python": "^0.0.4",
|
||||||
"read-yaml": "^1.0.0",
|
"read-yaml": "^1.0.0",
|
||||||
"shelljs": "^0.5.0",
|
"shelljs": "^0.5.0",
|
||||||
"sleep": "^3.0.0",
|
|
||||||
"sync-me": "^0.1.1",
|
"sync-me": "^0.1.1",
|
||||||
"toposort": "^0.2.10",
|
"toposort": "^0.2.10",
|
||||||
"web3": "^0.8.1",
|
"web3": "^0.8.1",
|
||||||
|
@ -6,7 +6,7 @@ development:
|
|||||||
genesis_block: config/genesis.json
|
genesis_block: config/genesis.json
|
||||||
datadir: /tmp/embark
|
datadir: /tmp/embark
|
||||||
mine_when_needed: true
|
mine_when_needed: true
|
||||||
gas_limit: 500000
|
gas_limit: 1000000
|
||||||
gas_price: 10000000000000
|
gas_price: 10000000000000
|
||||||
console: false
|
console: false
|
||||||
account:
|
account:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user