use miden_protocol::account::AccountId;
use miden_protocol::crypto::rand::FeltRng;
use miden_protocol::errors::NoteError;
use miden_protocol::note::{Note, NoteScript, NoteScriptRoot};
use miden_protocol::utils::sync::LazyLock;
use miden_protocol::vm::Package;
use miden_protocol::{Felt, Word};
use super::build_admin_note;
static SET_ATTESTER_NOTE_SCRIPT: LazyLock<NoteScript> = LazyLock::new(|| {
let package = Package::read_from_bytes_trusted(include_bytes!(concat!(
env!("OUT_DIR"),
"/assets/notes/xreserve-set-attester-note.masp"
)))
.expect("the shipped note package deserializes");
NoteScript::from_package(&package).expect("the note package exports exactly one note script")
});
#[derive(Debug, Clone, Copy, PartialEq, Eq, bon::Builder)]
pub struct XReserveSetAttesterNoteStorage {
commitment: Word,
enabled: u8,
}
impl XReserveSetAttesterNoteStorage {
pub const NUM_ITEMS: usize = 5;
pub fn commitment(&self) -> Word {
self.commitment
}
pub fn enabled(&self) -> u8 {
self.enabled
}
pub fn into_items(self) -> Vec<Felt> {
vec![
self.commitment[0],
self.commitment[1],
self.commitment[2],
self.commitment[3],
Felt::from(u32::from(self.enabled)),
]
}
}
pub struct XReserveSetAttesterNote;
#[bon::bon]
impl XReserveSetAttesterNote {
pub fn script() -> NoteScript {
SET_ATTESTER_NOTE_SCRIPT.clone()
}
pub fn script_root() -> NoteScriptRoot {
SET_ATTESTER_NOTE_SCRIPT.root()
}
#[builder]
pub fn new<R: FeltRng>(
sender: AccountId,
faucet_id: AccountId,
storage: XReserveSetAttesterNoteStorage,
rng: &mut R,
) -> Result<Note, NoteError> {
build_admin_note(sender, faucet_id, Self::script(), storage.into_items(), rng)
}
pub fn create<R: FeltRng>(
sender: AccountId,
faucet_id: AccountId,
commitment: Word,
enabled: u8,
rng: &mut R,
) -> Result<Note, NoteError> {
Self::builder()
.sender(sender)
.faucet_id(faucet_id)
.storage(
XReserveSetAttesterNoteStorage::builder()
.commitment(commitment)
.enabled(enabled)
.build(),
)
.rng(rng)
.build()
}
}