extern crate alloc;
use alloc::string::ToString;
use alloc::vec;
use alloc::vec::Vec;
use miden_core::Felt;
use miden_protocol::account::AccountId;
use miden_protocol::crypto::rand::FeltRng;
use miden_protocol::errors::NoteError;
use miden_protocol::note::{
Note,
NoteAssets,
NoteAttachment,
NoteAttachments,
NoteRecipient,
NoteScript,
NoteScriptRoot,
NoteStorage,
NoteType,
PartialNoteMetadata,
};
use miden_standards::note::costs::NoteConsumptionCost;
use miden_standards::note::{NetworkAccountTarget, NoteExecutionHint};
use miden_utils_sync::LazyLock;
use crate::costs::DEREGISTER_AGG_FAUCET_CONSUMPTION_CYCLES;
use crate::note_script;
const DEREGISTER_AGG_FAUCET_SCRIPT_PATH: &str = "::agglayer::notes::deregister_agg_faucet::main";
static DEREGISTER_AGG_FAUCET_SCRIPT: LazyLock<NoteScript> =
LazyLock::new(|| note_script(DEREGISTER_AGG_FAUCET_SCRIPT_PATH));
pub struct DeregisterAggFaucetNote;
impl DeregisterAggFaucetNote {
pub const NUM_STORAGE_ITEMS: usize = 2;
pub fn script() -> NoteScript {
DEREGISTER_AGG_FAUCET_SCRIPT.clone()
}
pub fn script_root() -> NoteScriptRoot {
DEREGISTER_AGG_FAUCET_SCRIPT.root()
}
pub fn create<R: FeltRng>(
faucet_account_id: AccountId,
sender_account_id: AccountId,
target_account_id: AccountId,
rng: &mut R,
) -> Result<Note, NoteError> {
let storage_values: Vec<Felt> =
vec![faucet_account_id.suffix(), faucet_account_id.prefix().as_felt()];
let note_storage = NoteStorage::new(storage_values)?;
let serial_num = rng.draw_word();
let recipient = NoteRecipient::new(serial_num, Self::script(), note_storage);
let attachment = NetworkAccountTarget::new(target_account_id, NoteExecutionHint::Always)
.map_err(|e| NoteError::other(e.to_string()))?;
let attachments = NoteAttachments::from(NoteAttachment::from(attachment));
let metadata = PartialNoteMetadata::new(sender_account_id, NoteType::Public);
let assets = NoteAssets::new(vec![])?;
Ok(Note::with_attachments(assets, metadata, recipient, attachments))
}
}
impl NoteConsumptionCost for DeregisterAggFaucetNote {
fn consumption_cycles() -> u32 {
DEREGISTER_AGG_FAUCET_CONSUMPTION_CYCLES
}
}