MCPcopy Create free account
hub / github.com/dfinity/orbit / into_request

Method into_request

tools/dfx-orbit/src/canister/install.rs:53–108  ·  view source on GitHub ↗

Converts the CLI arg type into the equivalent Orbit API type.

(
        self,
        dfx_orbit: &DfxOrbit,
    )

Source from the content-addressed store, hash-verified

51 pub content: Vec<u8>,
52 pub content_type: String,
53 pub content_encoding: String,
54 pub sha256: Option<Vec<u8>>,
55}
56
57fn hash(data: &[u8]) -> Vec<u8> {
58 let mut hasher = Sha256::new();
59 hasher.update(data);
60 hasher.finalize().to_vec()
61}
62
63impl RequestCanisterInstallArgs {
64 /// Converts the CLI arg type into the equivalent Orbit API type.
65 pub(crate) async fn into_request(
66 self,
67 dfx_orbit: &DfxOrbit,
68 ) -> anyhow::Result<RequestOperationInput> {
69 let canister_id = dfx_orbit.canister_id(&self.canister)?;
70
71 let (module, arg) = self.load_module_and_args()?;
72 let mode = self.install_mode()?;
73
74 let (module, module_extra_chunks) = if let Some(ref asset_canister) = self.asset_canister {
75 let asset_canister_id = dfx_orbit.canister_id(asset_canister)?;
76 let asset_agent = dfx_orbit.canister_agent(asset_canister_id)?;
77
78 // compute module hash
79 let canister_wasm_hash = hash(&module);
80
81 // upload module as extra chunks to asset canister
82 let path: PathBuf = self.wasm.into();
83 let extra_chunks_key = path
84 .file_name()
85 .with_context(|| {
86 format!(
87 "Could not derive the WASM file name from {}",
88 path.display()
89 )
90 })?
91 .to_str()
92 .with_context(|| "The WASM file name cannot be converted to a String")?
93 .to_string();
94 ic_asset::upload(
95 &asset_agent,
96 HashMap::from([(extra_chunks_key.clone(), path)]),
97 &dfx_orbit.logger,
98 )
99 .await?;
100
101 (
102 vec![],
103 Some(WasmModuleExtraChunks {
104 store_canister: asset_canister_id,
105 extra_chunks_key,
106 wasm_module_hash: canister_wasm_hash,
107 }),
108 )
109 } else {
110 (module, None)

Callers

nothing calls this directly

Calls 4

canister_idMethod · 0.80
load_module_and_argsMethod · 0.80
canister_agentMethod · 0.80
hashFunction · 0.70

Tested by

no test coverage detected