MCPcopy Create free account
hub / github.com/dfinity/ic-repl / get_info

Method get_info

src/exp.rs:813–902  ·  view source on GitHub ↗
(&self, helper: &MyHelper, is_encode: bool)

Source from the content-addressed store, hash-verified

811}
812impl Method {
813 pub fn get_info(&self, helper: &MyHelper, is_encode: bool) -> Result<MethodInfo> {
814 if is_encode && self.method == "__init_args" {
815 if let Some(IDLValue::Blob(bytes)) = helper.env.0.get(&self.canister) {
816 use ic_wasm::{metadata::get_metadata, utils::parse_wasm};
817 let m = parse_wasm(bytes, false)?;
818 let args = get_metadata(&m, "candid:args");
819 let candid = get_metadata(&m, "candid:service");
820 let canister_id = Principal::anonymous();
821 match args {
822 None => {
823 eprintln!("Warning: no candid:args metadata in the Wasm module, use types inferred from textual value.");
824 return Ok(MethodInfo {
825 canister_id,
826 signature: None,
827 profiling: None,
828 });
829 }
830 Some(args) => {
831 let candid = candid
832 .as_ref()
833 .map(|x| std::str::from_utf8(x).unwrap())
834 .unwrap_or("service : {}");
835 let (env, ty) = candid_parser::utils::merge_init_args(
836 candid,
837 std::str::from_utf8(&args)?,
838 )?;
839 let init_args = find_init_args(&env, &ty).expect("invalid init arg types");
840 let signature = Some((
841 env,
842 Function {
843 args: init_args,
844 rets: Vec::new(),
845 modes: Vec::new(),
846 },
847 ));
848 return Ok(MethodInfo {
849 canister_id,
850 signature,
851 profiling: None,
852 });
853 }
854 }
855 }
856 }
857 let canister_id = str_to_principal(&self.canister, helper)?;
858 let agent = &helper.agent;
859 let mut map = helper.canister_map.borrow_mut();
860 Ok(match map.get(agent, &canister_id) {
861 Err(_) => MethodInfo {
862 canister_id,
863 signature: None,
864 profiling: None,
865 },
866 Ok(info) => {
867 let signature = if self.method == "__init_args" {
868 eprintln!(
869 "Warning: no init args in did file, use types inferred from textual value."
870 );

Callers 2

evalMethod · 0.80
sendFunction · 0.80

Calls 3

find_init_argsFunction · 0.85
str_to_principalFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected