mazzaroth_rs/external/
account.rs

1//! Provides access to contract account objects stored in state.
2
3#[cfg(not(feature = "host-mock"))]
4use super::externs::_is_owner;
5
6#[cfg(feature = "host-mock")]
7pub static mut OWNER: bool = false;
8
9/// Check if an account is the owner of the channel.
10///
11/// # Arguments
12///
13/// * `key` - The public key of the account to access
14///
15/// # Returns
16///
17/// * `Bool` - True if the account is the channel owner
18///
19/// # Example
20///
21/// ```ignore
22/// use mazzaroth_rs::account;
23/// let is_owner = account::is_owner(vec![0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
24/// ```
25#[cfg(not(feature = "host-mock"))]
26pub fn is_owner(key: Vec<u8>) -> bool {
27    unsafe { _is_owner(key.as_ptr(), key.len()) }
28}
29
30#[cfg(feature = "host-mock")]
31pub fn is_owner(_key: Vec<u8>) -> bool {
32    unsafe { OWNER }
33}
34
35#[cfg(test)]
36#[cfg(feature = "host-mock")]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_is_owner_true() {
42        unsafe {
43            OWNER = true;
44        }
45        assert_eq!(is_owner(vec![]), true);
46    }
47}