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
53
54
55
56
57
58
use eosio::{PermissionLevel, PublicKey, Transaction, Write, WriteError};
#[inline]
pub fn has_transaction_authority<T, K, L>(
trx: T,
public_keys: K,
permission_levels: L,
) -> Result<bool, WriteError>
where
T: AsRef<Transaction>,
K: AsRef<[PublicKey]>,
L: AsRef<[PermissionLevel]>,
{
let trx = trx.as_ref().pack()?;
has_transaction_authority_bytes(trx, public_keys, permission_levels)
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
pub fn has_transaction_authority_bytes<T, K, L>(
trx: T,
public_keys: K,
permission_levels: L,
) -> Result<bool, WriteError>
where
T: AsRef<[u8]>,
K: AsRef<[PublicKey]>,
L: AsRef<[PermissionLevel]>,
{
let trx = trx.as_ref();
let public_keys = public_keys.as_ref().pack()?;
let permission_levels = permission_levels.as_ref().pack()?;
let result = unsafe {
eosio_cdt_sys::check_transaction_authorization(
trx.as_ptr(),
trx.len() as u32,
public_keys.as_ptr(),
public_keys.len() as u32,
permission_levels.as_ptr(),
permission_levels.len() as u32,
)
};
Ok(result == 1)
}