@@ -43,15 +43,48 @@ import (
43
43
"github.com/onflow/flowkit/v2/output"
44
44
)
45
45
46
+ type categorizedLogs struct {
47
+ fileSystemActions []string
48
+ stateUpdates []string
49
+ }
50
+
51
+ func (cl * categorizedLogs ) LogAll (logger output.Logger ) {
52
+ logger .Info ("📝 Dependency Manager Actions Summary" )
53
+ logger .Info ("" ) // Add a line break after the section
54
+
55
+ if len (cl .fileSystemActions ) > 0 {
56
+ logger .Info ("🗃️ File System Actions:" )
57
+ for _ , msg := range cl .fileSystemActions {
58
+ logger .Info (fmt .Sprintf ("✅ %s" , msg ))
59
+ }
60
+ logger .Info ("" ) // Add a line break after the section
61
+ }
62
+
63
+ if len (cl .stateUpdates ) > 0 {
64
+ logger .Info ("💾 State Updates:" )
65
+ for _ , msg := range cl .stateUpdates {
66
+ logger .Info (fmt .Sprintf ("✅ %s" , msg ))
67
+ }
68
+ logger .Info ("" ) // Add a line break after the section
69
+ }
70
+ }
71
+
72
+ type dependencyManagerFlagsCollection struct {
73
+ skipDeployments bool `default:"false" flag:"skip-deployments" info:"Skip adding the dependency to deployments"`
74
+ skipAlias bool `default:"false" flag:"skip-alias" info:"Skip prompting for an alias"`
75
+ }
76
+
46
77
type DependencyInstaller struct {
47
78
Gateways map [string ]gateway.Gateway
48
79
Logger output.Logger
49
80
State * flowkit.State
50
81
SkipDeployments bool
82
+ SkipAlias bool
83
+ logs categorizedLogs
51
84
}
52
85
53
86
// NewDependencyInstaller creates a new instance of DependencyInstaller
54
- func NewDependencyInstaller (logger output.Logger , state * flowkit.State , skipDeployments bool ) (* DependencyInstaller , error ) {
87
+ func NewDependencyInstaller (logger output.Logger , state * flowkit.State , flags dependencyManagerFlagsCollection ) (* DependencyInstaller , error ) {
55
88
emulatorGateway , err := gateway .NewGrpcGateway (config .EmulatorNetwork )
56
89
if err != nil {
57
90
return nil , fmt .Errorf ("error creating emulator gateway: %v" , err )
@@ -83,7 +116,8 @@ func NewDependencyInstaller(logger output.Logger, state *flowkit.State, skipDepl
83
116
Gateways : gateways ,
84
117
Logger : logger ,
85
118
State : state ,
86
- SkipDeployments : skipDeployments ,
119
+ SkipDeployments : flags .skipDeployments ,
120
+ SkipAlias : flags .skipAlias ,
87
121
}, nil
88
122
}
89
123
@@ -95,6 +129,14 @@ func (di *DependencyInstaller) Install() error {
95
129
return err
96
130
}
97
131
}
132
+
133
+ err := di .State .SaveDefault ()
134
+ if err != nil {
135
+ return fmt .Errorf ("error saving state: %w" , err )
136
+ }
137
+
138
+ di .logs .LogAll (di .Logger )
139
+
98
140
return nil
99
141
}
100
142
@@ -124,6 +166,13 @@ func (di *DependencyInstaller) Add(depSource, customName string) error {
124
166
return fmt .Errorf ("error processing dependency: %w" , err )
125
167
}
126
168
169
+ err = di .State .SaveDefault ()
170
+ if err != nil {
171
+ return fmt .Errorf ("error saving state: %w" , err )
172
+ }
173
+
174
+ di .logs .LogAll (di .Logger )
175
+
127
176
return nil
128
177
}
129
178
@@ -218,7 +267,7 @@ func (di *DependencyInstaller) handleFileSystem(contractAddr, contractName, cont
218
267
return fmt .Errorf ("failed to create contract file: %w" , err )
219
268
}
220
269
221
- di .Logger . Info ( fmt .Sprintf ("Dependency Manager: %s from %s on %s installed" , contractName , contractAddr , networkName ))
270
+ di .logs . fileSystemActions = append ( di . logs . fileSystemActions , fmt .Sprintf ("%s from %s on %s installed" , contractName , contractAddr , networkName ))
222
271
}
223
272
224
273
return nil
@@ -273,12 +322,26 @@ func (di *DependencyInstaller) handleFoundContract(networkName, contractAddr, as
273
322
return err
274
323
}
275
324
325
+ // If the contract is not a core contract and the user does not want to skip deployments, then prompt for a deployment
276
326
if ! di .SkipDeployments && ! isCoreContract (contractName ) {
277
327
err = di .updateDependencyDeployment (contractName )
278
328
if err != nil {
279
329
di .Logger .Error (fmt .Sprintf ("Error updating deployment: %v" , err ))
280
330
return err
281
331
}
332
+
333
+ di .logs .stateUpdates = append (di .logs .stateUpdates , fmt .Sprintf ("%s added to emulator deployments" , contractName ))
334
+ }
335
+
336
+ // If the contract is not a core contract and the user does not want to skip aliasing, then prompt for an alias
337
+ if ! di .SkipAlias && ! isCoreContract (contractName ) {
338
+ err = di .updateDependencyAlias (contractName , networkName )
339
+ if err != nil {
340
+ di .Logger .Error (fmt .Sprintf ("Error updating alias: %v" , err ))
341
+ return err
342
+ }
343
+
344
+ di .logs .stateUpdates = append (di .logs .stateUpdates , fmt .Sprintf ("Alias added for %s on %s" , contractName , networkName ))
282
345
}
283
346
284
347
return nil
@@ -302,13 +365,30 @@ func (di *DependencyInstaller) updateDependencyDeployment(contractName string) e
302
365
for _ , c := range raw .Contracts {
303
366
deployment .AddContract (config.ContractDeployment {Name : c })
304
367
}
368
+ }
369
+
370
+ return nil
371
+ }
372
+
373
+ func (di * DependencyInstaller ) updateDependencyAlias (contractName , aliasNetwork string ) error {
374
+ var missingNetwork string
375
+
376
+ if aliasNetwork == config .TestnetNetwork .Name {
377
+ missingNetwork = config .MainnetNetwork .Name
378
+ } else {
379
+ missingNetwork = config .TestnetNetwork .Name
380
+ }
305
381
306
- err := di .State .SaveDefault ()
382
+ label := fmt .Sprintf ("Enter an alias address for %s on %s if you have one, otherwise leave blank" , contractName , missingNetwork )
383
+ raw := util .AddressPromptOrEmpty (label , "Invalid alias address" )
384
+
385
+ if raw != "" {
386
+ contract , err := di .State .Contracts ().ByName (contractName )
307
387
if err != nil {
308
388
return err
309
389
}
310
390
311
- di . Logger . Info ( fmt . Sprintf ( "Dependency Manager: %s added to emulator deployments in flow.json" , contractName ))
391
+ contract . Aliases . Add ( missingNetwork , flowsdk . HexToAddress ( raw ))
312
392
}
313
393
314
394
return nil
@@ -329,13 +409,9 @@ func (di *DependencyInstaller) updateDependencyState(networkName, contractAddres
329
409
330
410
di .State .Dependencies ().AddOrUpdate (dep )
331
411
di .State .Contracts ().AddDependencyAsContract (dep , networkName )
332
- err := di .State .SaveDefault ()
333
- if err != nil {
334
- return err
335
- }
336
412
337
413
if isNewDep {
338
- di .Logger . Info ( fmt .Sprintf ("Dependency Manager: %s added to flow.json" , dep .Name ))
414
+ di .logs . stateUpdates = append ( di . logs . stateUpdates , fmt .Sprintf ("%s added to flow.json" , dep .Name ))
339
415
}
340
416
341
417
return nil
0 commit comments