-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinfo.rs
More file actions
83 lines (65 loc) · 2.13 KB
/
info.rs
File metadata and controls
83 lines (65 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use clap::Args;
use ic_agent::AgentError;
use ic_utils::interfaces::management_canister::CanisterStatusResult;
use icp::{agent, context::GetCanisterIdAndAgentError, identity, network};
use itertools::Itertools;
use icp::context::Context;
use crate::commands::args;
use icp::store_id::LookupIdError;
#[derive(Debug, Args)]
pub(crate) struct InfoArgs {
#[command(flatten)]
pub(crate) cmd_args: args::CanisterCommandArgs,
}
#[derive(Debug, thiserror::Error)]
pub(crate) enum CommandError {
#[error(transparent)]
Project(#[from] icp::LoadError),
#[error(transparent)]
Identity(#[from] identity::LoadError),
#[error(transparent)]
Access(#[from] network::AccessError),
#[error(transparent)]
Agent(#[from] agent::CreateAgentError),
#[error(transparent)]
Lookup(#[from] LookupIdError),
#[error(transparent)]
Status(#[from] AgentError),
#[error(transparent)]
GetCanisterIdAndAgent(#[from] GetCanisterIdAndAgentError),
}
pub(crate) async fn exec(ctx: &Context, args: &InfoArgs) -> Result<(), CommandError> {
let selections = args.cmd_args.selections();
let (cid, agent) = ctx
.get_canister_id_and_agent(
&selections.canister,
&selections.environment,
&selections.network,
&selections.identity,
)
.await?;
// Management Interface
let mgmt = ic_utils::interfaces::ManagementCanister::create(&agent);
// Retrieve canister status from management canister
let (result,) = mgmt.canister_status(&cid).await?;
// Info printout
print_info(&result);
Ok(())
}
pub(crate) fn print_info(result: &CanisterStatusResult) {
let controllers: Vec<String> = result
.settings
.controllers
.iter()
.map(|p| p.to_string())
.sorted()
.collect();
eprintln!("Controllers: {}", controllers.join(", "));
match &result.module_hash {
Some(hash) => {
let hex_string: String = hash.iter().map(|b| format!("{b:02x}")).collect();
eprintln!("Module hash: 0x{hex_string}");
}
None => eprintln!("Module hash: <none>"),
}
}