{% extends "layout.njk" %}

{% block main %}

{% if hasAccounts %}
pub mod accounts_parser;
{% endif %}

pub mod instructions_parser;

{% if hasProtoHelpers %}
pub mod proto_helpers;
{% endif %}

/// Deserialize a Borsh-encoded account, checking that all significant bytes are read.
pub fn deserialize_checked<T: borsh::BorshDeserialize>(
    data: &[u8],
    discriminator: &[u8],
) -> Result<T, std::io::Error> {
    let mut data_bytes = data;
    let account = T::deserialize(&mut data_bytes)?;

    if !data_bytes.is_empty() && data_bytes.iter().any(|b| *b != 0) {
        #[cfg(feature = "tracing")]
        tracing::warn!(
            name: "non_zeroed_end_bytes",
            name = "non_zeroed_end_bytes",
            length = data_bytes.len(),
            program = crate::ID.to_string(),
            type_name = ?discriminator,
        );
    }

    Ok(account)
}

{% endblock %}
