1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use miden_protocol::account::{Account, AccountPatch, AccountUpdateDetails};
use miden_standards::account::auth::NetworkAccount;
// NETWORK ACCOUNT EFFECT
// ================================================================================================
/// Represents the effect of a transaction on a network account.
///
/// The caller must know from the block if the account is new and select the constructor that matches.
#[derive(Debug, Clone)]
pub enum NetworkAccountEffect {
Created(Account),
Updated(AccountPatch),
}
impl NetworkAccountEffect {
/// Returns the effect of an update that creates an account, or `None` if the new account is
/// private or is not a network account.
///
/// # Panics
///
/// **WARNING**: Panics if the patch cannot be converted into a new account. Only pass the
/// update of an account that a committed block creates. The update of an existing account,
/// including a code upgrade, can panic or produce an incorrect account.
pub fn from_account_creation(update: &AccountUpdateDetails) -> Option<Self> {
match update {
AccountUpdateDetails::Private => None,
AccountUpdateDetails::Public(patch) => {
// Only treat creations as network if the storage carries the standardized
// `NetworkAccountNoteAllowlist` slot.
let account = patch
.try_to_new_account()
.expect("the patch of a committed account creation should build an account");
NetworkAccount::new(account)
.ok()
.map(|network_account| Self::Created(network_account.into_account()))
},
}
}
/// Returns the effect of an update to an existing account, or `None` if the account is private.
pub fn from_account_update(update: &AccountUpdateDetails) -> Option<Self> {
match update {
AccountUpdateDetails::Private => None,
AccountUpdateDetails::Public(patch) => {
// Updates carry no storage we can inspect here. Forward them as updates;
// `apply_committed_block` drops the ones whose account is not tracked locally.
Some(Self::Updated(patch.clone()))
},
}
}
}