Skip to content

Commit

Permalink
Merge pull request #28 from onflow/add-flix
Browse files Browse the repository at this point in the history
Add flix
  • Loading branch information
sisyphusSmiling authored Feb 15, 2024
2 parents a6b5904 + 115b403 commit 38f7bcf
Show file tree
Hide file tree
Showing 27 changed files with 1,218 additions and 35 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,29 @@ Armed with your pre-requisites, you're ready to stage your contract update. Simp
transaction](./transactions/migration-contract-staging/stage_contract.cdc), passing your contract's name and Cadence
code as arguments and signing as the contract host account.

You can stage your contract using the [Flow Interaction Templates
(FLIX)](https://developers.flow.com/tools/flow-cli/flix) and the following command to execute the staging transaction
from [its interaction template](./flix/stage_contract.cdc.flix.json):

> :warning: Be sure to execute this transaction passing your contract's updated Cadence 1.0-compatible code
```sh
flow flix execute https://raw.githubusercontent.com/onflow/contract-updater/main/flix/stage_contract.cdc.flix.json \
<CONTRACT_NAME> "$(cat <CONTRACT_FILEPATH>)" \
--signer <YOUR_SIGNER_ALIAS> \
--network <TARGET_NETWORK>
```

To execute the transaction from this project's local transaction code, run:

```sh
flow transactions send ./transactions/migration-contract-staging/stage_contract.cdc \
<CONTRACT_NAME> "$(cat <CONTRACT_FILEPATH>)" \
--signer <YOUR_SIGNER_ALIAS> \
--network <TARGET_NETWORK>
```

This will execute the following transaction:
Either of the above will execute the following transaction:

```cadence
import "MigrationContractStaging"
Expand Down Expand Up @@ -127,13 +142,25 @@ script](./scripts/migration-contract-staging/get_staged_contract_code.cdc), pass
you're requesting and getting the Cadence code in return. This script can also help you get the staged code for your
dependencies if the project owner has staged their code.

You can run this script from [its template](./flix/get_staged_contract_code.cdc.flix.json) using
[FLIX](https://developers.flow.com/tools/flow-cli/flix) without the need to pull dependencies into your local project
with the Flow CLI command below.

```sh
flow flix execute https://raw.githubusercontent.com/onflow/contract-updater/main/flix/get_staged_contract_code.cdc.flix.json \
<CONTRACT_ADDRESS> <CONTRACT_NAME> \
--network <TARGET_NETWORK>
```

Alternatively, you can run the script from this project's local Cadence code with:

```sh
flow scripts execute ./scripts/migration-contract-staging/get_staged_contract_code.cdc \
<CONTRACT_ADDRESS> <CONTRACT_NAME> \
--network <TARGET_NETWORK>
```

Which runs the script:
Either of the above runs the script:

```cadence
import "MigrationContractStaging"
Expand Down
66 changes: 66 additions & 0 deletions flix/commit_migration_results.cdc.flix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "b5d035292a57c659f4b7736626fc6499fb1e8395fee480da950f07f6e8c19c63",
"data": {
"type": "transaction",
"interface": "",
"messages": null,
"cadence": {
"body": "import \"MigrationContractStaging\"\n\n/// Commits the results of offchain emulated migration\n///\ntransaction(snapshotTimestamp: UFix64, failedContracts: [String]) {\n \n let admin: \u0026MigrationContractStaging.Admin\n\n prepare(signer: AuthAccount) {\n self.admin = signer.borrow\u003c\u0026MigrationContractStaging.Admin\u003e(from: MigrationContractStaging.AdminStoragePath)\n ?? panic(\"Could not borrow Admin reference\")\n }\n\n execute {\n self.admin.commitMigrationResults(snapshot: snapshotTimestamp, failed: failedContracts)\n }\n\n post {\n MigrationContractStaging.lastEmulatedMigrationResult!.failedContracts == failedContracts \u0026\u0026\n MigrationContractStaging.lastEmulatedMigrationResult!.snapshot == snapshotTimestamp:\n \"Problem committing migration results\"\n }\n}\n",
"network_pins": [
{
"network": "testnet",
"pin_self": "8d65a5baf3b2110f7aad12849a3339f469c7f422962f15b1958b654d41864f5f"
}
]
},
"dependencies": [
{
"contracts": [
{
"contract": "MigrationContractStaging",
"networks": [
{
"network": "testnet",
"address": "0x2ceae959ed1a7e7a",
"dependency_pin_block_height": 156164536,
"dependency_pin": {
"pin": "3db75e59355d07498d1dbd1719a383a487562c7cf558450898103212109954cb",
"pin_self": "ebb923e929faf7299d117ff5159becccb54378c47b08bf30c6d0774f3ee21d61",
"pin_contract_name": "MigrationContractStaging",
"pin_contract_address": "0x2ceae959ed1a7e7a",
"imports": []
}
},
{
"network": "crescendo",
"address": "0x27b2302520211b67",
"dependency_pin_block_height": 0
},
{
"network": "emulator",
"address": "0xf8d6e0586b0a20c7",
"dependency_pin_block_height": 0
}
]
}
]
}
],
"parameters": [
{
"label": "snapshotTimestamp",
"index": 0,
"type": "UFix64",
"messages": []
},
{
"label": "failedContracts",
"index": 1,
"type": "[String]",
"messages": []
}
]
}
}
85 changes: 85 additions & 0 deletions flix/get_all_staged_contract_code_for_address.cdc.flix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "3339b93ff5eeb990bf856cedfffcc475d4857271ca20e09e1536f819b308e46c",
"data": {
"type": "script",
"interface": "",
"messages": [
{
"key": "title",
"i18n": [
{
"tag": "en-US",
"translation": "Get All Staged Contract Code for Address"
}
]
},
{
"key": "description",
"i18n": [
{
"tag": "en-US",
"translation": "Returns a mapping of all contract code staged for a given address indexed on the contract name."
}
]
}
],
"cadence": {
"body": "import \"MigrationContractStaging\"\n\n#interaction (\n version: \"1.1.0\",\n title: \"Get All Staged Contract Code for Address\",\n description: \"Returns a mapping of all contract code staged for a given address indexed on the contract name.\",\n language: \"en-US\",\n)\n\n/// Returns the code for all staged contracts hosted by the given contract address.\n///\naccess(all) fun main(contractAddress: Address): {String: String} {\n return MigrationContractStaging.getAllStagedContractCode(forAddress: contractAddress)\n}\n",
"network_pins": [
{
"network": "testnet",
"pin_self": "a311a6849e9ee49e8204e9ebd6b623ae2edb1643b160bbcf4bf47c45e4ef7f74"
}
]
},
"dependencies": [
{
"contracts": [
{
"contract": "MigrationContractStaging",
"networks": [
{
"network": "crescendo",
"address": "0x27b2302520211b67",
"dependency_pin_block_height": 0
},
{
"network": "emulator",
"address": "0xf8d6e0586b0a20c7",
"dependency_pin_block_height": 0
},
{
"network": "testnet",
"address": "0x2ceae959ed1a7e7a",
"dependency_pin_block_height": 156164546,
"dependency_pin": {
"pin": "3db75e59355d07498d1dbd1719a383a487562c7cf558450898103212109954cb",
"pin_self": "ebb923e929faf7299d117ff5159becccb54378c47b08bf30c6d0774f3ee21d61",
"pin_contract_name": "MigrationContractStaging",
"pin_contract_address": "0x2ceae959ed1a7e7a",
"imports": []
}
}
]
}
]
}
],
"parameters": [
{
"label": "contractAddress",
"index": 0,
"type": "Address",
"messages": []
}
],
"output": {
"label": "result",
"index": 0,
"type": "{String: String}",
"messages": []
}
}
}
78 changes: 78 additions & 0 deletions flix/get_all_staged_contract_hosts.cdc.flix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "177036477cd12a2b30c54e841c690ed14fcee5f52174d30294debd3f3e264df0",
"data": {
"type": "script",
"interface": "",
"messages": [
{
"key": "title",
"i18n": [
{
"tag": "en-US",
"translation": "Get All Staged Contract Hosts"
}
]
},
{
"key": "description",
"i18n": [
{
"tag": "en-US",
"translation": "Returns an array containing the addresses of all contract hosting accounts that have staged contracts."
}
]
}
],
"cadence": {
"body": "import \"MigrationContractStaging\"\n\n#interaction (\n version: \"1.1.0\",\n title: \"Get All Staged Contract Hosts\",\n description: \"Returns an array containing the addresses of all contract hosting accounts that have staged contracts.\",\n language: \"en-US\",\n)\n\n/// Returns the code for all staged contracts hosted by the given contract address.\n///\naccess(all) fun main(): [Address] {\n return MigrationContractStaging.getAllStagedContractHosts()\n}\n",
"network_pins": [
{
"network": "testnet",
"pin_self": "93a15c87c9ac5bebb293094d1a7c96ea389a36331925065a0f15201c8804a3e0"
}
]
},
"dependencies": [
{
"contracts": [
{
"contract": "MigrationContractStaging",
"networks": [
{
"network": "testnet",
"address": "0x2ceae959ed1a7e7a",
"dependency_pin_block_height": 156164557,
"dependency_pin": {
"pin": "3db75e59355d07498d1dbd1719a383a487562c7cf558450898103212109954cb",
"pin_self": "ebb923e929faf7299d117ff5159becccb54378c47b08bf30c6d0774f3ee21d61",
"pin_contract_name": "MigrationContractStaging",
"pin_contract_address": "0x2ceae959ed1a7e7a",
"imports": []
}
},
{
"network": "crescendo",
"address": "0x27b2302520211b67",
"dependency_pin_block_height": 0
},
{
"network": "emulator",
"address": "0xf8d6e0586b0a20c7",
"dependency_pin_block_height": 0
}
]
}
]
}
],
"parameters": null,
"output": {
"label": "result",
"index": 0,
"type": "[Address]",
"messages": []
}
}
}
78 changes: 78 additions & 0 deletions flix/get_all_staged_contracts.cdc.flix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"f_type": "InteractionTemplate",
"f_version": "1.1.0",
"id": "18a15b80ffd7c8cf3203abcc5a92be4fce38b3d96e0873d63bb961ff1d88c759",
"data": {
"type": "script",
"interface": "",
"messages": [
{
"key": "title",
"i18n": [
{
"tag": "en-US",
"translation": "Get All Staged Contracts"
}
]
},
{
"key": "description",
"i18n": [
{
"tag": "en-US",
"translation": "Returns a mapping of all staged contract updates."
}
]
}
],
"cadence": {
"body": "import \"MigrationContractStaging\"\n\n#interaction (\n version: \"1.1.0\",\n title: \"Get All Staged Contracts\",\n description: \"Returns a mapping of all staged contract updates.\",\n language: \"en-US\",\n)\n\n/// Returns all staged contracts as a mapping of address to an array of contract names\n///\naccess(all) fun main(): {Address: [String]} {\n return MigrationContractStaging.getAllStagedContracts()\n}\n",
"network_pins": [
{
"network": "testnet",
"pin_self": "daa55e7567d1561aaab9ab9b68092dea8e13837b70b0c3eaa9fa257f09dd4595"
}
]
},
"dependencies": [
{
"contracts": [
{
"contract": "MigrationContractStaging",
"networks": [
{
"network": "testnet",
"address": "0x2ceae959ed1a7e7a",
"dependency_pin_block_height": 156164553,
"dependency_pin": {
"pin": "3db75e59355d07498d1dbd1719a383a487562c7cf558450898103212109954cb",
"pin_self": "ebb923e929faf7299d117ff5159becccb54378c47b08bf30c6d0774f3ee21d61",
"pin_contract_name": "MigrationContractStaging",
"pin_contract_address": "0x2ceae959ed1a7e7a",
"imports": []
}
},
{
"network": "crescendo",
"address": "0x27b2302520211b67",
"dependency_pin_block_height": 0
},
{
"network": "emulator",
"address": "0xf8d6e0586b0a20c7",
"dependency_pin_block_height": 0
}
]
}
]
}
],
"parameters": null,
"output": {
"label": "result",
"index": 0,
"type": "{Address: [String]}",
"messages": []
}
}
}
Loading

0 comments on commit 38f7bcf

Please sign in to comment.