use miden_protocol::Word;
use miden_protocol::account::AccountId;
use miden_protocol::assembly::Path;
use miden_protocol::asset::Asset;
use miden_protocol::crypto::rand::FeltRng;
use miden_protocol::errors::NoteError;
use miden_protocol::note::{
Note,
NoteAssets,
NoteAttachment,
NoteMetadata,
NoteRecipient,
NoteScript,
NoteStorage,
NoteTag,
NoteType,
};
use miden_protocol::utils::sync::LazyLock;
use crate::StandardsLib;
const BURN_SCRIPT_PATH: &str = "::miden::standards::notes::burn::main";
static BURN_SCRIPT: LazyLock<NoteScript> = LazyLock::new(|| {
let standards_lib = StandardsLib::default();
let path = Path::new(BURN_SCRIPT_PATH);
NoteScript::from_library_reference(standards_lib.as_ref(), path)
.expect("Standards library contains BURN note script procedure")
});
pub struct BurnNote;
impl BurnNote {
pub const NUM_STORAGE_ITEMS: usize = 0;
pub fn script() -> NoteScript {
BURN_SCRIPT.clone()
}
pub fn script_root() -> Word {
BURN_SCRIPT.root()
}
pub fn create<R: FeltRng>(
sender: AccountId,
faucet_id: AccountId,
fungible_asset: Asset,
attachment: NoteAttachment,
rng: &mut R,
) -> Result<Note, NoteError> {
let note_script = Self::script();
let serial_num = rng.draw_word();
let note_type = NoteType::Public;
let inputs = NoteStorage::new(vec![])?;
let tag = NoteTag::with_account_target(faucet_id);
let metadata =
NoteMetadata::new(sender, note_type).with_tag(tag).with_attachment(attachment);
let assets = NoteAssets::new(vec![fungible_asset])?; let recipient = NoteRecipient::new(serial_num, note_script, inputs);
Ok(Note::new(assets, metadata, recipient))
}
}