@@ -3,7 +3,12 @@ var fs = require('fs');
33var grunt = require ( 'grunt' ) ;
44var readYaml = require ( 'read-yaml' ) ;
55var Config = require ( './config/config.js' ) ;
6- var sleep = require ( 'sleep' ) ;
6+
7+ // Ugly, but sleep lib has issues on osx
8+ sleep = function sleep ( ms ) {
9+ var start = new Date ( ) . getTime ( ) ;
10+ while ( new Date ( ) . getTime ( ) < start + ms ) ;
11+ }
712
813Deploy = function ( env , contractFiles , blockchainConfig , contractsConfig ) {
914 //this.blockchainConfig = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
@@ -25,6 +30,20 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
2530 console . log ( "primary account address is : " + primaryAddress ) ;
2631} ;
2732
33+ Deploy . prototype . deploy_contract = function ( contractObject , contractParams ) {
34+ var transactionHash = contractObject [ "new" ] . apply ( contractObject , contractParams ) . transactionHash ;
35+ var receipt = null ;
36+ var time = 0 ;
37+ while ( ( receipt = web3 . eth . getTransactionReceipt ( transactionHash ) ) === null || receipt . contractAddress === null ) {
38+ sleep ( 1000 ) ;
39+ time += 1 ;
40+ if ( time >= 20 ) {
41+ return false ;
42+ }
43+ }
44+ return receipt ;
45+ }
46+
2847Deploy . prototype . deploy_contracts = function ( env ) {
2948 this . contractsManager . compileContracts ( env ) ;
3049 all_contracts = this . contractsManager . all_contracts ;
@@ -64,16 +83,12 @@ Deploy.prototype.deploy_contracts = function(env) {
6483 gasPrice : contract . gasPrice
6584 } ) ;
6685
67- var transactionHash = contractObject [ "new" ] . apply ( contractObject , contractParams ) . transactionHash ;
68- // TODO: get this with sync until a different mechanism is implemented
69- //this.deployedContracts[className] = contractAddress;
70- //console.log("address is " + contractAddress);
71-
7286 console . log ( 'trying to obtain ' + className + ' address...' ) ;
73- var receipt = null ;
74- while ( ( receipt = web3 . eth . getTransactionReceipt ( transactionHash ) ) === null || receipt . contractAddress === null ) {
75- sleep . sleep ( 1 ) ;
87+
88+ while ( ( receipt = this . deploy_contract ( contractObject , contractParams ) ) === false ) {
89+ console . log ( "timeout... failed to deploy contract.. retrying..." ) ;
7690 }
91+
7792 var contractAddress = receipt . contractAddress ;
7893 this . deployedContracts [ className ] = contractAddress ;
7994
0 commit comments