1919package services
2020
2121import (
22+ "bytes"
2223 "fmt"
2324 "strings"
2425
@@ -155,6 +156,7 @@ func (p *Project) Deploy(network string, update bool) ([]*contracts.Contract, er
155156 defer p .logger .StopProgress ()
156157
157158 deployErr := false
159+ numOfUpdates := 0
158160 for _ , contract := range orderedContracts {
159161 block , err := p .gateway .GetLatestBlock ()
160162 if err != nil {
@@ -184,7 +186,9 @@ func (p *Project) Deploy(network string, update bool) ([]*contracts.Contract, er
184186 return nil , err
185187 }
186188 // check if contract exists on account
187- _ , exists := targetAccountInfo .Contracts [contract .Name ()]
189+ existingContract , exists := targetAccountInfo .Contracts [contract .Name ()]
190+ noDiffInContract := bytes .Equal ([]byte (contract .Code ()), existingContract )
191+
188192 if exists && ! update {
189193 p .logger .Error (fmt .Sprintf (
190194 "contract %s is already deployed to this account. Use the --update flag to force update" ,
@@ -200,10 +204,19 @@ func (p *Project) Deploy(network string, update bool) ([]*contracts.Contract, er
200204 deployErr = true
201205 continue
202206 } else if exists {
207+ //only update contract if there is diff
208+ if noDiffInContract {
209+ p .logger .Info (fmt .Sprintf (
210+ "no diff found in %s, skipping update" ,
211+ contract .Name (),
212+ ))
213+ continue
214+ }
203215 tx , err = flowkit .NewUpdateAccountContractTransaction (targetAccount , contract .Name (), contract .TranspiledCode ())
204216 if err != nil {
205217 return nil , err
206218 }
219+ numOfUpdates ++
207220 }
208221
209222 tx .SetBlockReference (block )
@@ -246,25 +259,41 @@ func (p *Project) Deploy(network string, update bool) ([]*contracts.Contract, er
246259 if result .Error != nil {
247260 deployErr = true
248261 p .logger .StopProgress ()
249- p .logger .Error (fmt .Sprintf (
250- "Error deploying %s: (%s)\n " ,
251- output .Red (contract .Name ()),
252- result .Error .Error (),
253- ))
262+ if exists && update {
263+ p .logger .Error (fmt .Sprintf (
264+ "Error updating %s: (%s)\n " ,
265+ output .Red (contract .Name ()),
266+ result .Error .Error (),
267+ ))
268+ } else {
269+ p .logger .Error (fmt .Sprintf (
270+ "Error deploying %s: (%s)\n " ,
271+ output .Red (contract .Name ()),
272+ result .Error .Error (),
273+ ))
274+ }
254275 }
255276
256277 if result .Error == nil && ! deployErr {
278+ changeStatus := ""
279+ if exists && update {
280+ changeStatus = "(update)"
281+ }
257282 p .logger .StopProgress ()
258283 p .logger .Info (fmt .Sprintf (
259- "%s -> 0x%s (%s)\n " ,
284+ "%s -> 0x%s (%s) %s \n " ,
260285 output .Green (contract .Name ()),
261286 contract .Target (),
262287 sentTx .ID ().String (),
288+ changeStatus ,
263289 ))
264290 }
265291 }
266292
267293 if ! deployErr {
294+ if update && numOfUpdates > 0 {
295+ p .logger .Info (fmt .Sprintf ("%d contracts updated successfully" , numOfUpdates ))
296+ }
268297 p .logger .Info (fmt .Sprintf ("\n %s All contracts deployed successfully" , output .SuccessEmoji ()))
269298 } else {
270299 err = fmt .Errorf ("failed to deploy all contracts" )
0 commit comments