Skip to main content

interstice_sdk_core/host_calls/
module.rs

1use crate::host_calls::{host_call, unpack};
2use interstice_abi::{HostCall, ModuleCall, ModuleCallResponse, NodeSelection};
3
4pub fn publish(node_selection: NodeSelection, wasm_binary: Vec<u8>) -> Result<(), String> {
5    let pack = host_call(HostCall::Module(ModuleCall::Publish {
6        node_selection,
7        wasm_binary,
8    }));
9    let response: ModuleCallResponse = unpack(pack);
10    match response {
11        ModuleCallResponse::Ok => Ok(()),
12        ModuleCallResponse::Err(err) => Err(err),
13    }
14}
15
16pub fn remove(node_selection: NodeSelection, module_name: String) -> Result<(), String> {
17    let pack = host_call(HostCall::Module(ModuleCall::Remove {
18        node_selection,
19        module_name,
20    }));
21    let response: ModuleCallResponse = unpack(pack);
22    match response {
23        ModuleCallResponse::Ok => Ok(()),
24        ModuleCallResponse::Err(err) => Err(err),
25    }
26}
27
28pub struct ModuleAuthority;
29
30impl ModuleAuthority {
31    pub fn publish(
32        &self,
33        node_selection: NodeSelection,
34        wasm_binary: Vec<u8>,
35    ) -> Result<(), String> {
36        publish(node_selection, wasm_binary)
37    }
38
39    pub fn remove(&self, node_selection: NodeSelection, module_name: String) -> Result<(), String> {
40        remove(node_selection, module_name)
41    }
42}