check_canister_status function
Returns a status map for the convenience using the canister_status
method on the management canister.
The caller
must be a controller of the canister_id
.
Implementation
Future<Map> check_canister_status(Caller caller, Principal canister_id) async {
Uint8List canister_status_sponse_bytes = await SYSTEM_CANISTERS.management.call(
caller: caller,
calltype: CallType.call,
method_name: 'canister_status',
put_bytes: c_forwards([
Record.of_the_map({
'canister_id': canister_id }) ])
);
Record canister_status_record = c_backwards(canister_status_sponse_bytes)[0] as Record;
Map canister_status_map = {};
// status
Variant status_variant = canister_status_record['status'] as Variant;
['running', 'stopping', 'stopped'].forEach((status_possibility) {
if (status_variant.containsKey(status_possibility)) {
canister_status_map['status'] = status_possibility; }
});
// settings
Record settings_record = canister_status_record['settings'] as Record;
canister_status_map['settings'] = {};
canister_status_map['settings']['controllers'] = (settings_record['controllers'] as Vector).cast<Principal>();
canister_status_map['settings']['compute_allocation'] = (settings_record['compute_allocation'] as Nat).value;
canister_status_map['settings']['memory_allocation'] = (settings_record['memory_allocation'] as Nat).value;
canister_status_map['settings']['freezing_threshold'] = (settings_record['freezing_threshold'] as Nat).value;
// module_hash
Option optional_module_hash = canister_status_record['module_hash'] as Option;
canister_status_map['module_hash'] = optional_module_hash.value != null ? Blob.of_the_vector_nat8((optional_module_hash.value as Vector).cast_vector<Nat8>()).bytes : null;
// memory_size
canister_status_map['memory_size'] = (canister_status_record['memory_size'] as Nat).value;
// cycles
canister_status_map['cycles'] = (canister_status_record['cycles'] as Nat).value;
return canister_status_map;
}