Hey @infu!
The SNS-1 canister: sqbzf-5aaaa-aaaam-aavya-cai is an asset canister. Here you can see the simple ‘store’ method:
// 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 upload a frontend file, the governance canister must call the asset canister to upload the file. 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.
Then once that is done, 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.
For the AddGenericNervousSystemFunction proposal, there needs to be a validator method that the governance canister calls to validate that the ExecuteGenericNervousSystemFunction-proposal’s payload is well-formed, prior to putting the ExecuteGenericNervousSystemFunction-proposal up for a vote. ic/canister_control.rs at cbd16d23c673115d45ac902376ec194fc623611a · dfinity/ic · GitHub
![image](https://us1.discourse-cdn.com/flex015/uploads/dfn/original/2X/4/4c7d54b5416cbc9d9439954c3c8604584b0324dd.png)
![image](https://us1.discourse-cdn.com/flex015/uploads/dfn/original/2X/3/3ebad5f4e62066e1c7b8c8549ecf15bc88bae14c.png)
I made a canister for this validation method: epeco-piaaa-aaaai-qatka-cai
with the following source code:
use ic_cdk_macros::{query};
use serde_bytes::ByteBuf;
use ic_cdk::{
export::{
candid::{CandidType, Deserialize}
}
};
pub type Key = String;
#[derive(CandidType, Deserialize)]
pub struct StoreArg {
pub key: Key,
pub content_type: String,
pub content_encoding: String,
pub content: ByteBuf,
pub sha256: Option<ByteBuf>,
pub aliased: Option<bool>,
}
#[query]
pub fn validate_store_file_payload(_q: StoreArg) -> Result<String, String> {
Ok("Payload looks good!".to_string())
}
The method: validate_store_file_payload
will trap if the StoreArg
parameter is incorrectly encoded, and will return an Ok() if the payload is valid. This is due to the #[query]
macro decoding the payload into a StoreArg
.
The source code for the epeco-piaaa-aaaai-qatka-cai
canister is here: sns-1-epeco/lib.rs at master · levifeldman/sns-1-epeco · GitHub.
I made the SNS-1’s root canister: zxeu2-7aaaa-aaaaq-aaafa-cai
into the sole-controller of the epeco-piaaa-aaaai-qatka-cai
canister, so now it is part of the SNS-1. Canister: epeco-piaaa-aaaai-qatka-cai - IC Dashboard see the Controllers
section. Also see the SNS-1’s-root canister here: Canister: SNS-1 Root - IC Dashboard, click list_sns_canisters
, call, and see the epeco-piaaa-aaaai-qatka-cai
canister is part of the SNS-1.
The first proposal AddGenericNervousSystemFunction to add the upload-asset proposal-type is live! See here on the SNS-1 Governance canister! click on the list_proposals
method, limit: 10, and click ‘call’:
Vote here on open-chat!