-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
272df6c
commit 43a6787
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import "MigrationContractStaging" | ||
|
||
access(all) contract DependencyAudit { | ||
// The system addresses have contracts that will not be stages via the migration contract so we exclude them from the dependency chekcs | ||
access(self) excludedAddresses: {Address: Bool} | ||
|
||
access(all) event UnstagedDependencies(dependenciesAddresses: [Address], dependenciesNames: [String]) | ||
|
||
// checkDependencies is called from the FlowServiceAccount contract | ||
access(all) fun checkDependencies(_ dependenciesAddresses: [Address], _ dependenciesNames: [String], _ authorizers: [Address]) { | ||
var numDependencies = dependenciesAddresses.length | ||
var i = 0 | ||
|
||
var unstagedDependenciesAddresses: [Address] = [] | ||
var unstagedDependenciesNames: [String] = [] | ||
|
||
while i < numDependencies { | ||
i = i + 1 | ||
|
||
let isExcluded = DependencyAudit.excludedAddresses[dependenciesAddresses[i]] ?? false | ||
if isExcluded { | ||
continue | ||
} | ||
|
||
let staged = MigrationContractStaging.isStaged(address: dependenciesAddresses[i], name: dependenciesNames[i]) | ||
if !staged { | ||
unstagedDependenciesAddresses.append(dependenciesAddresses[i]) | ||
unstagedDependenciesNames.append(dependenciesNames[i]) | ||
} | ||
} | ||
|
||
if unstagedDependenciesAddresses.length > 0 { | ||
emit UnstagedDependencies(dependenciesAddresses: unstagedDependenciesAddresses, dependenciesNames: unstagedDependenciesNames) | ||
// or alternatively panic("Found unstaged dependencies: ... ") | ||
} | ||
} | ||
|
||
access(all) resource Administrator { | ||
access(all) fun addExcludedAddresses(addresses: [Address]) { | ||
for address in addresses { | ||
DependencyAudit.excludedAddresses[address] = true | ||
} | ||
} | ||
|
||
access(all) fun removeExcludedAddresses(addresses: [Address]) { | ||
for address in addresses { | ||
DependencyAudit.excludedAddresses.remove(key: address) | ||
} | ||
} | ||
} | ||
|
||
init(excludedAddresses: [Address]) { | ||
self.excludedAddresses = {} | ||
|
||
for address in excludedAddresses { | ||
self.excludedAddresses[address] = true | ||
} | ||
|
||
let admin <- create Administrator() | ||
self.account.save(<-admin, to: /storage/flowDependencyAuditAdmin) | ||
} | ||
} |