@@ -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);
@@ -22,9 +27,23 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
2227 throw new Error ( "==== can't connect to " + this . blockchainConfig . rpcHost + ":" + this . blockchainConfig . rpcPort + " check if an ethereum node is running" ) ;
2328 }
2429
25- console . log ( "address is : " + primaryAddress ) ;
30+ 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,19 +83,25 @@ 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 ;
93+
94+ if ( web3 . eth . getCode ( contractAddress ) === "0x" ) {
95+ console . log ( "=========" ) ;
96+ console . log ( "contract was deployed at " + contractAddress + " but doesn't seem to be working" ) ;
97+ console . log ( "try adjusting your gas values" ) ;
98+ console . log ( "=========" ) ;
99+ }
100+ else {
101+ console . log ( "deployed " + className + " at " + contractAddress ) ;
102+ }
103+
78104 this . deployedContracts [ className ] = contractAddress ;
79- console . log ( 'address is ' + contractAddress ) ;
80105
81106 console . log ( "deployed " + className + " at " + contractAddress ) ;
82107 }
0 commit comments