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
//! Contains traits that programs should implement, including Architecture-agnostic programs and generic programs.
//!
//! For runtime and binary size optimizations, program construction should be done at compile time by using `const` types, if possible. This can be done by using `const` generic parameters,
//! or by using a `const` builder. Both methods are described nicely here: https://wapl.es/rust/2022/07/03/const-builder-pattern.html
use crateArchitecture;
use crateError;
/// Programs using binary (or other unserialized) data must implement this. This is the most barebones trait for programs.
/// Any program using transaction-like/architecture-agnostic signature requests must implement this.
///
/// For example, a program that checks that the recipient is not a blacklisted address would implement this trait for EVM, and would be similar to this:
/// ```
/// use entropy_programs_acl::*;
/// use entropy_programs_evm::*;
///
/// let non_blacklisted_addr: [u8; 20] = [1u8; 20];
/// let blacklisted_addr_1: [u8; 20] = [2u8; 20];
/// let blacklisted_addr_2: [u8; 20] = [3u8; 20];
///
/// let no_malicious_addresses = Acl {
/// addresses: vec![blacklisted_addr_1, blacklisted_addr_2],
/// kind: AclKind::Deny,
/// allow_null_recipient: false,
/// };
///
/// let non_blacklisted_recipient_tx = EvmTransactionRequest {
/// to: Some(NameOrAddress::Address(H160::from(non_blacklisted_addr))),
/// ..Default::default()
/// };
///
/// let blacklisted_recipient_tx = EvmTransactionRequest {
/// to: Some(NameOrAddress::Address(H160::from(blacklisted_addr_1))),
/// ..Default::default()
/// };
///
/// // This will be allowed, since the recipient is not in the blacklisted ACL.
/// no_malicious_addresses.clone().is_satisfied_by(&non_blacklisted_recipient_tx)?;
/// // This will return an error, because the recipient is not in the ACL.
/// assert!(no_malicious_addresses.is_satisfied_by(&blacklisted_recipient_tx).is_err());
/// Ok::<(), CoreError>(())
/// ```
///