use {{candid_crate}}::{CandidType, Deserialize, Principal};
use ic_cdk::call::{Call, CallResult};
// START -- Types
{{type_defs}}
// END -- Types
/// Get the canister ID via the environment variable `{{env_var_name}}`.
#[inline]
pub fn __get_canister_id() -> Principal {
if !::ic_cdk::api::env_var_name_exists("{{env_var_name}}") {
panic!("env var `{{env_var_name}}` is not set. Canister controller can set it using tools like icp-cli.");
}
let canister_id_str = ::ic_cdk::api::env_var_value("{{env_var_name}}");
Principal::from_text(&canister_id_str).unwrap_or_else(|e| {
panic!("failed to parse Principal from env var `{{env_var_name}}`, value `{}`: {}", canister_id_str, e)
})
}
// START -- Methods
{{#if methods}}
{{#each methods}}
{{#each this.docs}}
{{../../doc_comment_prefix}}{{this}}
{{/each}}
pub async fn {{this.name}}({{#each this.args}}{{this.0}}: &{{this.1}}, {{/each}}) -> CallResult<{{#if (eq (len this.rets) 1)}}{{this.rets.0}}{{else}}({{#each this.rets}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}){{/if}}> {
Ok(Call::bounded_wait(__get_canister_id(), "{{escape_debug this.original_name}}"){{#if (eq (len this.args) 0)}}{{else}}{{#if (eq (len this.args) 1)}}.with_arg({{this.args.0.0}}){{else}}.with_args(&({{#each this.args}}{{this.0}}{{#unless @last}}, {{/unless}}{{/each}})){{/if}}{{/if}}.await?.candid()?)
}
{{/each}}
{{/if}}
// END -- Methods