miden_protocol/asset/
asset_callbacks.rs1use alloc::vec::Vec;
2
3use crate::Word;
4use crate::account::{StorageSlot, StorageSlotName};
5use crate::utils::sync::LazyLock;
6
7static ON_BEFORE_ASSET_ADDED_TO_ACCOUNT_SLOT_NAME: LazyLock<StorageSlotName> =
11 LazyLock::new(|| {
12 StorageSlotName::new("miden::protocol::faucet::callback::on_before_asset_added_to_account")
13 .expect("storage slot name should be valid")
14 });
15
16static ON_BEFORE_ASSET_ADDED_TO_NOTE_SLOT_NAME: LazyLock<StorageSlotName> = LazyLock::new(|| {
17 StorageSlotName::new("miden::protocol::faucet::callback::on_before_asset_added_to_note")
18 .expect("storage slot name should be valid")
19});
20
21#[derive(Debug, Clone, Default, PartialEq, Eq)]
35pub struct AssetCallbacks {
36 on_before_asset_added_to_account: Word,
37 on_before_asset_added_to_note: Word,
38}
39
40impl AssetCallbacks {
41 pub fn new() -> Self {
46 Self::default()
47 }
48
49 pub fn on_before_asset_added_to_account(mut self, proc_root: Word) -> Self {
51 self.on_before_asset_added_to_account = proc_root;
52 self
53 }
54
55 pub fn on_before_asset_added_to_note(mut self, proc_root: Word) -> Self {
57 self.on_before_asset_added_to_note = proc_root;
58 self
59 }
60
61 pub fn on_before_asset_added_to_account_slot() -> &'static StorageSlotName {
67 &ON_BEFORE_ASSET_ADDED_TO_ACCOUNT_SLOT_NAME
68 }
69
70 pub fn on_before_asset_added_to_note_slot() -> &'static StorageSlotName {
73 &ON_BEFORE_ASSET_ADDED_TO_NOTE_SLOT_NAME
74 }
75
76 pub fn slot_names() -> [&'static StorageSlotName; 2] {
78 [
79 Self::on_before_asset_added_to_account_slot(),
80 Self::on_before_asset_added_to_note_slot(),
81 ]
82 }
83
84 pub fn on_before_asset_added_to_account_proc_root(&self) -> Word {
86 self.on_before_asset_added_to_account
87 }
88
89 pub fn on_before_asset_added_to_note_proc_root(&self) -> Word {
91 self.on_before_asset_added_to_note
92 }
93
94 pub fn into_storage_slots(self) -> Vec<StorageSlot> {
95 let mut slots = Vec::new();
96
97 if !self.on_before_asset_added_to_account.is_empty() {
98 slots.push(StorageSlot::with_value(
99 AssetCallbacks::on_before_asset_added_to_account_slot().clone(),
100 self.on_before_asset_added_to_account,
101 ));
102 }
103
104 if !self.on_before_asset_added_to_note.is_empty() {
105 slots.push(StorageSlot::with_value(
106 AssetCallbacks::on_before_asset_added_to_note_slot().clone(),
107 self.on_before_asset_added_to_note,
108 ));
109 }
110
111 slots
112 }
113}