Skip to main content

rshooks_api/api/
state.rs

1use super::*;
2
3/// Retrieve the data pointed to by a Hook State key and write it to an output buffer
4#[inline(always)]
5pub fn state(data: &mut [u8], key: &[u8]) -> Result<i64> {
6    buf_write_read(data, key, _c::state)
7}
8
9/// Set the Hook State for a given key and value
10#[inline(always)]
11pub fn state_set(data: &[u8], key: &[u8]) -> Result<i64> {
12    buf_2read(data, key, _c::state_set)
13}
14
15/// Retrieve the data pointed to, on another account, by a Hook State key and write it to an output buffer
16#[inline(always)]
17pub fn state_foreign(data: &mut [u8], key: &[u8], namespace: &[u8], accid: &[u8]) -> Result<i64> {
18    let res = unsafe {
19        _c::state_foreign(
20            data.as_mut_ptr() as u32,
21            data.len() as u32,
22            key.as_ptr() as u32,
23            key.len() as u32,
24            namespace.as_ptr() as u32,
25            namespace.len() as u32,
26            accid.as_ptr() as u32,
27            accid.len() as u32,
28        )
29    };
30
31    result_i64(res)
32}
33
34/// Set the Hook State on another account for a given key, value and namespace
35#[inline(always)]
36pub fn state_foreign_set(data: &[u8], key: &[u8], namespace: &[u8], accid: &[u8]) -> Result<i64> {
37    let res = unsafe {
38        _c::state_foreign_set(
39            data.as_ptr() as u32,
40            data.len() as u32,
41            key.as_ptr() as u32,
42            key.len() as u32,
43            namespace.as_ptr() as u32,
44            namespace.len() as u32,
45            accid.as_ptr() as u32,
46            accid.len() as u32,
47        )
48    };
49
50    result_i64(res)
51}