extern crate alloc;
use alloc::string::ToString;
use alloc::vec;
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,
NoteStorage,
NoteType,
PartialNoteMetadata,
};
use miden_standards::note::{NetworkAccountTarget, NoteExecutionHint};
use crate::ExitRoot;
pub(crate) fn create_ger_note<R: FeltRng>(
ger: ExitRoot,
sender_account_id: AccountId,
target_account_id: AccountId,
script: NoteScript,
rng: &mut R,
) -> Result<Note, NoteError> {
let storage_values = ger.to_elements().to_vec();
let note_storage = NoteStorage::new(storage_values)?;
let serial_num = rng.draw_word();
let recipient = NoteRecipient::new(serial_num, 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))
}