Skip to content

Commit

Permalink
Merge pull request #16 from onflow/migration-staging-updates
Browse files Browse the repository at this point in the history
README & getter updates
  • Loading branch information
sisyphusSmiling authored Feb 6, 2024
2 parents a7fffa0 + f7e6858 commit fc31fdc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ access(all) struct ContractUpdate {
access(all) view fun isValid(): Bool
/// Serializes the address and name into a string of the form 0xADDRESS.NAME
access(all) view fun toString(): String
/// Returns human-readable string of the Cadence code.
access(all) view fun codeAsCadence(): String
/// Replaces the ContractUpdate code with that provided.
access(contract) fun replaceCode(_ code: String)
}
Expand All @@ -182,27 +180,29 @@ contract is staged (`status == "stage"`), staged code is replaced (`status == "r
access(all) event StagingStatusUpdated(
capsuleUUID: UInt64,
address: Address,
codeHash: [UInt8],
code: String,
contract: String,
action: String
)
```
Included in the contact are methods for querying staging status and retrieval of staged code. This enables platforms
like Flowview, Flowdiver, ContractBrowser, etc. to display the staging status of contracts on any given account.
Included in the contact are methods for querying staging status and retrieval of staged code. This enables platforms to
display the staging status of contracts on any given account should.

```cadence
/* --- Public Getters --- */
//
/// Returns true if the contract is currently staged.
access(all) fun isStaged(address: Address, name: String): Bool
access(all) view fun isStaged(address: Address, name: String): Bool
/// Returns the names of all staged contracts for the given address.
access(all) fun getStagedContractNames(forAddress: Address): [String]
access(all) view fun getStagedContractNames(forAddress: Address): [String]
/// Returns the staged contract Cadence code for the given address and name.
access(all) fun getStagedContractCode(address: Address, name: String): String?
access(all) view fun getStagedContractCode(address: Address, name: String): String?
/// Returns an array of all staged contract host addresses.
access(all) view fun getAllStagedContractHosts(): [Address]
/// Returns a dictionary of all staged contract code for the given address.
access(all) fun getAllStagedContractCode(forAddress: Address): {String: String}
access(all) view fun getAllStagedContractCode(forAddress: Address): {String: String}
/// Returns all staged contracts as a mapping of address to an array of contract names
access(all) view fun getAllStagedContracts(): {Address: [String]}
```

## References
Expand Down
8 changes: 7 additions & 1 deletion contracts/MigrationContractStaging.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ access(all) contract MigrationContractStaging {

/// Returns the staged contract Cadence code for the given address and name.
///
access(all) fun getStagedContractCode(address: Address, name: String): String? {
access(all) view fun getStagedContractCode(address: Address, name: String): String? {
let capsulePath = self.deriveCapsuleStoragePath(contractAddress: address, contractName: name)
if let capsule = self.account.borrow<&Capsule>(from: capsulePath) {
return capsule.getContractUpdate().code
Expand Down Expand Up @@ -171,6 +171,12 @@ access(all) contract MigrationContractStaging {
return stagedCode
}

/// Returns all staged contracts as a mapping of address to an array of contract names
///
access(all) view fun getAllStagedContracts(): {Address: [String]} {
return self.stagedContracts
}

/// Returns a StoragePath to store the Capsule of the form:
/// /storage/self.capsulePathPrefix_ADDRESS_NAME
access(all) view fun deriveCapsuleStoragePath(contractAddress: Address, contractName: String): StoragePath {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "MigrationContractStaging"

/// Returns all staged contracts as a mapping of address to an array of contract names
///
access(all) fun main(): {Address: [String]} {
return MigrationContractStaging.getAllStagedContracts()
}

0 comments on commit fc31fdc

Please sign in to comment.