#[cfg(test)]
mod tests;
use serde::{Deserialize, Serialize};
pub const CANDID_PAYLOAD_CONTRACT_PREFIX: &str = "// canic:payload-contract ";
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct PayloadContract {
pub schema_version: u8,
pub default_update_ingress_max_bytes: u64,
pub update_overrides: Vec<UpdatePayloadDescriptor>,
pub variant_dependent_methods: Vec<String>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct UpdatePayloadDescriptor {
pub method: String,
pub max_bytes: u64,
}
#[must_use]
pub fn annotate_candid(mut candid: String, variant_dependent_methods: &[&str]) -> String {
let contract = PayloadContract {
schema_version: 1,
default_update_ingress_max_bytes: super::payload::DEFAULT_UPDATE_INGRESS_MAX_BYTES as u64,
update_overrides: super::payload::declaration_limits(),
variant_dependent_methods: variant_dependent_methods
.iter()
.map(|method| (*method).into())
.collect(),
};
let mut bytes = Vec::new();
ciborium::ser::into_writer(&contract, &mut bytes).expect("compiled payload contract encodes");
candid.push('\n');
candid.push_str(CANDID_PAYLOAD_CONTRACT_PREFIX);
candid.push_str(&crate::cdk::utils::hash::hex_bytes(&bytes));
candid.push('\n');
candid
}