casper_contract_sdk_sys/
lib.rs1pub mod for_each_host_function;
2
3#[repr(C)]
4pub struct Param {
5 pub name_ptr: *const u8,
6 pub name_len: usize,
7}
8
9pub type Fptr = extern "C" fn() -> ();
11
12#[derive(Debug)]
13#[repr(C)]
14pub struct ReadInfo {
15 pub data: *const u8,
16 pub size: usize,
18}
19
20#[repr(C)]
21#[derive(Debug)]
22pub struct CreateResult {
23 pub contract_address: [u8; 32],
24}
25
26#[repr(C)]
27#[derive(Debug)]
28pub struct UpgradeResult {
29 pub package_address: [u8; 32],
30 pub contract_address: [u8; 32],
31 pub version: u32,
32}
33
34macro_rules! visit_host_function {
35 ( $( $(#[$cfg:meta])? $vis:vis fn $name:ident $(( $($arg:ident: $argty:ty,)* ))? $(-> $ret:ty)?;)+) => {
36 $(
37 $(#[$cfg])? $vis fn $name($($($arg: $argty,)*)?) $(-> $ret)?;
38 )*
39 }
40}
41
42extern "C" {
43 for_each_host_function!(visit_host_function);
44}
45
46macro_rules! visit_host_function_name {
47 ( $( $(#[$cfg:meta])? $vis:vis fn $name:ident $(( $($arg:ident: $argty:ty,)* ))? $(-> $ret:ty)?;)+) => {
48 &[
49 $(
50 stringify!($name),
51 )*
52 ]
53 }
54}
55
56pub const HOST_FUNCTIONS: &[&str] = for_each_host_function!(visit_host_function_name);
57
58#[cfg(test)]
59mod tests {
60 use std::collections::BTreeSet;
61
62 use crate::HOST_FUNCTIONS;
63
64 mod separate_module {
65 use crate::for_each_host_function;
66
67 macro_rules! visit_host_function {
68 ( $( $(#[$cfg:meta])? $vis:vis fn $name:ident $(( $($arg:ident: $argty:ty,)* ))? $(-> $ret:ty)?;)+) => {
69 $(
70 #[allow(dead_code, unused_variables, clippy::too_many_arguments)]
71 $(#[$cfg])? $vis fn $name($($($arg: $argty,)*)?) $(-> $ret)? {
72 todo!("Called fn {}", stringify!($name));
73 }
74 )*
75 }
76 }
77 for_each_host_function!(visit_host_function);
78 }
79
80 #[test]
81 #[should_panic(expected = "Called fn casper_print")]
82 fn different_module() {
83 const MSG: &str = "foobar";
84 separate_module::casper_print(MSG.as_ptr(), MSG.len());
85 }
86
87 #[test]
88 fn all_host_functions() {
89 let host_functions = BTreeSet::from_iter(HOST_FUNCTIONS);
90 assert!(host_functions.contains(&"casper_call"));
91 }
92}