Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update StagingStatusUpdated.code event value to SHA3_256 hash #38

Merged
merged 6 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.13.1
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
- name: Flow CLI Version
run: flow version
- name: Update PATH
Expand Down
25 changes: 21 additions & 4 deletions contracts/MigrationContractStaging.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ access(all) contract MigrationContractStaging {
access(all) event StagingStatusUpdated(
capsuleUUID: UInt64,
address: Address,
code: String,
codeHash: [UInt8],
contract: String,
action: String
)
Expand Down Expand Up @@ -112,7 +112,7 @@ access(all) contract MigrationContractStaging {
emit StagingStatusUpdated(
capsuleUUID: capsuleUUID,
address: address,
code: "",
codeHash: [],
contract: name,
action: "unstage"
)
Expand Down Expand Up @@ -156,6 +156,15 @@ access(all) contract MigrationContractStaging {
return self.getStagedContractUpdate(address: address, name: name)?.code
}

/// Returns the staged contract code hash for the given address and name or nil if it's not staged
///
access(all) view fun getStagedContractCodeHash(address: Address, name: String): [UInt8]? {
if let update = self.getStagedContractUpdate(address: address, name: name) {
return self.getCodeHash(update.code)
}
return nil
}

/// Returns the ContractUpdate struct for the given contract if it's been staged.
///
access(all) view fun getStagedContractUpdate(address: Address, name: String): ContractUpdate? {
Expand Down Expand Up @@ -207,6 +216,14 @@ access(all) contract MigrationContractStaging {
?? panic("Could not derive Capsule StoragePath for given address")
}

/* --- Util --- */

/// Returns the hash of the given code, hashing with SHA3-256
///
access(all) fun getCodeHash(_ code: String): [UInt8] {
return HashAlgorithm.SHA3_256.hash(code.utf8)
}

/* ------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------ Constructs ------------------------------------------------ */
/* ------------------------------------------------------------------------------------------------------------ */
Expand Down Expand Up @@ -352,7 +369,7 @@ access(all) contract MigrationContractStaging {
emit StagingStatusUpdated(
capsuleUUID: self.uuid,
address: self.update.address,
code: code,
codeHash: MigrationContractStaging.getCodeHash(code),
contract: self.update.name,
action: "replace"
)
Expand Down Expand Up @@ -406,7 +423,7 @@ access(all) contract MigrationContractStaging {
emit StagingStatusUpdated(
capsuleUUID: capsule.uuid,
address: host.address(),
code: code,
codeHash: MigrationContractStaging.getCodeHash(code),
contract: name,
action: "stage"
)
Expand Down
Loading
Loading