Skip to content

Commit

Permalink
revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
jessiemongeon1 committed Jun 23, 2023
1 parent ee0b718 commit ec1f02a
Showing 1 changed file with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

The [asset canister](https://github.com/dfinity/sdk/tree/master/src/canisters/frontend/ic-frontend-canister) provides users with a way to store and retrieve static assets from a canister deployed on the IC. Generally, asset canisters are used to serve HTML, CSS, or JavaScript assets, which are typically part of a dapp's frontend. For this reason, the asset canister is also referred to as the frontend canister. For purposes of this guide, we'll refer to it as the asset canister.


In the context of the SNS, a dapp's associated asset canister serves the frontend assets related to dapp and may also include a frontend to the SNS DAO, e.g., through which users can vote on governance proposals.

The contents of the asset canister must be configured prior to the launch of the SNS, and any changes afterwards must be made by a principal with the permission to do so. The SNS is the only one that can update the list of approved principals that have this permission, and any additions to this list approved on via an SNS proposal. This configuration assures that changes to the asset canister are only made by authorized principals that the SNS has agreed on through proposals. These changes are referred to as 'upgrades' to the asset canister in the remainder of this document.
Expand Down Expand Up @@ -80,17 +79,7 @@ Once the asset canister has been deployed, the SNS can be launched. You can lear

## Submitting an SNS proposal

Imagine a scenario where you'd like to upload a frontend file to the SNS's asset canister. To do this, the governance canister must call the asset canister to upload the file.

- #### Step 1: To get the governance canister to call the asset canister, we first make the proposal to `AddGenericNervousSystemFunction`, which is like adding a new proposal type that uploads files to the asset canister.

- #### Step 2: Next, we can make an `ExecuteGenericNervousSystemFunction` proposal that will make the governance-canister call the asset-canister’s store method with a payload of the frontend asset Candid parameter for the ‘store’ method.

- #### Step 3: Then, submit a new `AddGenericNervousSystemFunction` SNS Proposal to support the `commit_proposed_batch` API.

The target canister id should be the asset canister (that is upgraded in the below upgrade steps) and the target function is `commit_proposed_batch`. The validate function should be `validate_commit_proposed_batch`.

THe following asset canister APIs can be used in the proposal:
The following asset canister APIs can be used within a proposal:

```
type CommitProposedBatchArguments = record {
Expand All @@ -117,11 +106,11 @@ If the proposal is rejected, the preparer should use this new asset canister API
```


## Upgrade steps
## Submitting an SNS proposal and upgrading an asset canister

- #### Step 1: Upgrade the asset canister (by proposal, as with any other canister) to the asset canister wasm bundled with dfx 0.14.1, available [here](https://github.com/dfinity/sdk/blob/release-0.14.1/src/distributed/assetstorage.wasm.gz).
- #### Step 1: First, upgrade the asset canister (by proposal, as with any other canister) to the asset canister wasm bundled with dfx 0.14.1, available [here](https://github.com/dfinity/sdk/blob/release-0.14.1/src/distributed/assetstorage.wasm.gz).

- #### Step 2: After upgrading the asset canister by proposal, have someone with Prepare permission run:
- #### Step 2: After upgrading the asset canister by proposal, have someone with `Prepare` permission run:

```
dfx deploy <frontend canister name> --network ic --by-proposal
Expand All @@ -143,24 +132,41 @@ dfx deploy <frontend canister name> --network ic --compute-evidence

The computed evidence should match the evidence from step 2.

- #### Step 5: Submit a new proposal to commit the batch, using the ‘New Canister APIs’ above.
- #### Step 5: Submit a new proposal to commit the batch, using the APIs below:

Use these asset canister APIs in the proposal:

```
type CommitProposedBatchArguments = record {
batch_id: BatchId;
evidence: blob;
};
type ValidationResult = variant { Ok : text; Err : text };
validate_commit_proposed_batch: (CommitProposedBatchArguments) -> (ValidationResult);
commit_proposed_batch: (CommitProposedBatchArguments) -> ();
```

An example can be found [here](https://github.com/dfinity/sdk/blob/master/e2e/tests-dfx/assetscanister.bash#L133).

If the proposal is rejected, the preparer should use this new asset canister API:

```
type DeleteBatchArguments = record {
batch_id: BatchId;
};
delete_batch: (DeleteBatchArguments) -> ();
```


## Asset canister examples

An example of an SNS asset canister is canister `sqbzf-5aaaa-aaaam-aavya-cai`, which is an asset canister part of the [Dragginz Dapp SNS](https://dashboard.internetcomputer.org/canister/sqbzf-5aaaa-aaaam-aavya-cai).

By viewing the above asset canister, you can view example method that can be used to add, remove, or change assets.
## SNS GenericNervousSystemFunctions

The following is an example of a simple 'store' method:
To submit a new `AddGenericNervouSystemFunction` SNS Proposal to support the `commit_proposed_batch` API, the target canister id should be the asset canister (that is upgraded in upgrade steps) and the target function is `commit_proposed_batch`. The validate function should be `validate_commit_proposed_batch`.

```
// Single call to create an asset with content for a single content encoding that
// fits within the message ingress limit.
store: (record {
key: Key;
content_type: text;
content_encoding: text;
content: blob;
sha256: opt blob
}) -> ();
```
To submit an `ExecuteNervousSystemFunction` SNS Proposal with the output from `dfx deploy <frontend canister name> --network ic --by-proposal` see upgrade steps above.

0 comments on commit ec1f02a

Please sign in to comment.