@@ -58,55 +58,66 @@ Deploy.prototype.deploy_contracts = function(env) {
5858 className = all_contracts [ k ] ;
5959 contract = this . contractDB [ className ] ;
6060
61+
6162 if ( contract . address !== undefined ) {
6263 this . deployedContracts [ className ] = contract . address ;
6364
6465 //console.log("contract " + className + " at " + contractAddress);
6566 console . log ( "contract " + className + " at " + contract . address ) ;
6667 }
6768 else {
68- contractObject = web3 . eth . contract ( contract . compiled . info . abiDefinition ) ;
69-
70- realArgs = [ ] ;
71- for ( var l = 0 ; l < contract . args . length ; l ++ ) {
72- arg = contract . args [ l ] ;
73- if ( arg [ 0 ] === "$" ) {
74- realArgs . push ( this . deployedContracts [ arg . substr ( 1 ) ] ) ;
75- } else {
76- realArgs . push ( arg ) ;
77- }
69+ var chainContract = this . chainManager . getContract ( contract . compiled . code ) ;
70+
71+ if ( chainContract != undefined ) {
72+ console . log ( "contract " + className + " is unchanged and already deployed at " + chainContract . address ) ;
7873 }
74+ else {
7975
80- contractParams = realArgs ;
81- contractParams . push ( {
82- from : primaryAddress ,
83- data : contract . compiled . code ,
84- gas : contract . gasLimit ,
85- gasPrice : contract . gasPrice
86- } ) ;
76+ contractObject = web3 . eth . contract ( contract . compiled . info . abiDefinition ) ;
8777
88- console . log ( 'trying to obtain ' + className + ' address...' ) ;
78+ realArgs = [ ] ;
79+ for ( var l = 0 ; l < contract . args . length ; l ++ ) {
80+ arg = contract . args [ l ] ;
81+ if ( arg [ 0 ] === "$" ) {
82+ realArgs . push ( this . deployedContracts [ arg . substr ( 1 ) ] ) ;
83+ } else {
84+ realArgs . push ( arg ) ;
85+ }
86+ }
8987
90- while ( ( receipt = this . deploy_contract ( contractObject , contractParams ) ) === false ) {
91- console . log ( "timeout... failed to deploy contract.. retrying..." ) ;
92- }
88+ contractParams = realArgs ;
89+ contractParams . push ( {
90+ from : primaryAddress ,
91+ data : contract . compiled . code ,
92+ gas : contract . gasLimit ,
93+ gasPrice : contract . gasPrice
94+ } ) ;
9395
94- var contractAddress = receipt . contractAddress ;
96+ console . log ( 'trying to obtain ' + className + ' address...' ) ;
9597
96- if ( web3 . eth . getCode ( contractAddress ) === "0x" ) {
97- console . log ( "=========" ) ;
98- console . log ( "contract was deployed at " + contractAddress + " but doesn't seem to be working" ) ;
99- console . log ( "try adjusting your gas values" ) ;
100- console . log ( "=========" ) ;
101- }
102- else {
103- console . log ( "deployed " + className + " at " + contractAddress ) ;
104- }
98+ while ( ( receipt = this . deploy_contract ( contractObject , contractParams ) ) === false ) {
99+ console . log ( "timeout... failed to deploy contract.. retrying..." ) ;
100+ }
101+
102+ var contractAddress = receipt . contractAddress ;
103+
104+ if ( web3 . eth . getCode ( contractAddress ) === "0x" ) {
105+ console . log ( "=========" ) ;
106+ console . log ( "contract was deployed at " + contractAddress + " but doesn't seem to be working" ) ;
107+ console . log ( "try adjusting your gas values" ) ;
108+ console . log ( "=========" ) ;
109+ }
110+ else {
111+ console . log ( "deployed " + className + " at " + contractAddress ) ;
112+ }
105113
106- this . deployedContracts [ className ] = contractAddress ;
114+ this . deployedContracts [ className ] = contractAddress ;
115+ this . chainManager . addContract ( className , contract . compiled . code , contractAddress ) ;
116+ this . chainManager . save ( ) ;
107117
108- console . log ( "deployed " + className + " at " + contractAddress ) ;
109- this . execute_cmds ( contract . onDeploy ) ;
118+ console . log ( "deployed " + className + " at " + contractAddress ) ;
119+ this . execute_cmds ( contract . onDeploy ) ;
120+ }
110121 }
111122 }
112123
0 commit comments