Skip to content

Commit

Permalink
Merge pull request #38 from onflow/fix-event-limit
Browse files Browse the repository at this point in the history
Update StagingStatusUpdated.code event value to SHA3_256 hash
  • Loading branch information
sisyphusSmiling authored Jul 26, 2024
2 parents 5f45a7f + f165996 commit 8a179be
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 15 deletions.
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

0 comments on commit 8a179be

Please sign in to comment.