(agent: &Agent, canister_id: Principal)
| 529 | |
| 530 | #[tokio::main] |
| 531 | async 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 | |
| 566 | pub enum FileSource<'a> { |
| 567 | Text(&'a str), |
no test coverage detected