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
use super::*;

/// Retrieve the data pointed to by a Hook State key and write it to an output buffer
#[inline(always)]
pub fn state(data: &mut [u8], key: &[u8]) -> Result<i64> {
    buf_write_read(data, key, _c::state)
}

/// Set the Hook State for a given key and value
#[inline(always)]
pub fn state_set(data: &[u8], key: &[u8]) -> Result<i64> {
    buf_2read(data, key, _c::state_set)
}

/// Retrieve the data pointed to, on another account, by a Hook State key and write it to an output buffer
#[inline(always)]
pub fn state_foreign(data: &mut [u8], key: &[u8], namespace: &[u8], accid: &[u8]) -> Result<i64> {
    let res = unsafe {
        _c::state_foreign(
            data.as_mut_ptr() as u32,
            data.len() as u32,
            key.as_ptr() as u32,
            key.len() as u32,
            namespace.as_ptr() as u32,
            namespace.len() as u32,
            accid.as_ptr() as u32,
            accid.len() as u32,
        )
    };

    result_i64(res)
}

/// Set the Hook State on another account for a given key, value and namespace
#[inline(always)]
pub fn state_foreign_set(data: &[u8], key: &[u8], namespace: &[u8], accid: &[u8]) -> Result<i64> {
    let res = unsafe {
        _c::state_foreign_set(
            data.as_ptr() as u32,
            data.len() as u32,
            key.as_ptr() as u32,
            key.len() as u32,
            namespace.as_ptr() as u32,
            namespace.len() as u32,
            accid.as_ptr() as u32,
            accid.len() as u32,
        )
    };

    result_i64(res)
}