Skip to content

Commit

Permalink
Make the canister status public (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 18, 2024
1 parent 5b98364 commit f7beaf5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions canister/can.did
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
type CanisterStatusResponse = record {
status : CanisterStatusType;
memory_size : nat;
cycles : nat;
settings : DefiniteCanisterSettings;
query_stats : QueryStats;
idle_cycles_burned_per_day : nat;
module_hash : opt blob;
reserved_cycles : nat;
};
type CanisterStatusType = variant { stopped; stopping; running };
type DefiniteCanisterSettings = record {
freezing_threshold : nat;
controllers : vec principal;
reserved_cycles_limit : nat;
log_visibility : LogVisibility;
wasm_memory_limit : nat;
memory_allocation : nat;
compute_allocation : nat;
};
type DeregisterNeuronPairArgs = record { pair_id : nat64 };
type InitArgs = record {
wtn_governance_canister_id : opt principal;
nns_governance_canister_id : opt principal;
wtn_protocol_canister_id : opt principal;
};
type InitOrUpgradeArgs = variant { Upgrade : record {}; Init : InitArgs };
type LogVisibility = variant {
controllers;
public;
allowed_viewers : vec principal;
};
type NeuronPairPublic = record {
id : nat64;
admin : principal;
name : text;
nns_neuron_id : nat64;
wtn_neuron_id : blob;
};
type QueryStats = record {
response_payload_bytes_total : nat;
num_instructions_total : nat;
num_calls_total : nat;
request_payload_bytes_total : nat;
};
type RegisterNeuronPairArgs = record {
name : text;
nns_neuron_id : nat64;
Expand All @@ -30,4 +61,5 @@ service : (InitOrUpgradeArgs) -> {
list_neuron_pairs : () -> (vec NeuronPairPublic) query;
logs : () -> (vec text) query;
register_neuron_pair : (RegisterNeuronPairArgs) -> (Result);
status : () -> (CanisterStatusResponse);
}
1 change: 1 addition & 0 deletions canister/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use candid::CandidType;
use ic_cdk::api::management_canister::main::{CanisterIdRecord, CanisterStatusResponse};
use ic_principal::Principal;
use serde::{Deserialize, Serialize};

Expand Down
1 change: 1 addition & 0 deletions canister/src/updates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod deregister_neuron_pair;
mod register_neuron_pair;
mod status;
11 changes: 11 additions & 0 deletions canister/src/updates/status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::{CanisterIdRecord, CanisterStatusResponse};
use ic_cdk::update;

#[update]
async fn status() -> CanisterStatusResponse {
let canister_id = ic_cdk::id();
ic_cdk::api::management_canister::main::canister_status(CanisterIdRecord { canister_id })
.await
.unwrap()
.0
}

0 comments on commit f7beaf5

Please sign in to comment.