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

Function fetch_actor

src/helper.rs:531–564  ·  view source on GitHub ↗
(agent: &Agent, canister_id: Principal)

Source from the content-addressed store, hash-verified

529
530#[tokio::main]
531async fn fetch_actor(agent: &Agent, canister_id: Principal) -> anyhow::Result<CanisterInfo> {
532 let response = fetch_metadata(agent, canister_id, "metadata/candid:service").await;
533 let profiling = fetch_metadata(agent, canister_id, "metadata/name")
534 .await
535 .ok()
536 .as_ref()
537 .and_then(|bytes| Decode!(bytes, BTreeMap<u16, String>).ok());
538 let candid = match response {
539 Ok(blob) => std::str::from_utf8(&blob)?.to_owned(),
540 Err(_) => {
541 let response = agent
542 .query(&canister_id, "__get_candid_interface_tmp_hack")
543 .with_arg(Encode!()?)
544 .call()
545 .await;
546 match response {
547 Ok(response) => Decode!(&response, String)?,
548 Err(_) => {
549 return Ok(CanisterInfo {
550 env: Default::default(),
551 methods: Default::default(),
552 init: None,
553 profiling,
554 })
555 }
556 }
557 }
558 };
559 did_to_canister_info(
560 &format!("did file for {canister_id}"),
561 FileSource::Text(&candid),
562 profiling,
563 )
564}
565
566pub enum FileSource<'a> {
567 Text(&'a str),

Callers 1

getMethod · 0.85

Calls 3

fetch_metadataFunction · 0.85
did_to_canister_infoFunction · 0.85
TextEnum · 0.85

Tested by

no test coverage detected