transaction_processor/
lib.rs

1pub extern crate serde;
2pub extern crate serde_json;
3
4pub mod account;
5pub mod startup;
6pub mod sys;
7pub mod transfer;
8pub mod stake;
9pub mod types;
10pub mod utils;
11pub mod contract;
12
13#[macro_export]
14macro_rules! log {
15    () => ($crate::utils::log(""));
16    ($fmt:expr) => ($crate::utils::log(&format!($fmt)));
17    ($fmt:expr, $($arg:tt)*) => ($crate::utils::log(&format!($fmt, $($arg)*)));
18}
19
20#[macro_export]
21macro_rules! processor_entry {
22    // entry: fn (tag: &str, payload: &[u8]) -> Result<(), ProcessError>
23    ($entry:ident) => {
24        #[allow(unused_imports)]
25        use $crate::types::*;
26
27        #[no_mangle]
28        pub extern "C" fn process() -> InternalProcessResult {
29            fn assert_entry_type<
30                F: Fn($crate::startup::TransactionContext) -> ProcessResult<()>,
31            >(
32                _: F,
33            ) {
34            }
35            assert_entry_type($entry);
36
37            let result: ProcessResult<()> = $crate::startup::TransactionContext::initial_read()
38                .and_then(|context| $entry(context));
39
40            if let Err(ref e) = result {
41                match *e {
42                    ProcessError::Ignore => {}
43                    _ => {
44                        log!("Got an error while processing transaction: {:?}", e);
45                    }
46                }
47            }
48
49            result.into()
50        }
51    };
52}
53
54#[cfg(test)]
55#[allow(private_no_mangle_fns)]
56#[allow(dead_code)]
57mod compile_test {
58    use startup::TransactionContext;
59    fn process_transaction(_: TransactionContext) -> Result<(), ProcessError> {
60        Err(ProcessError::Generic)
61    }
62    processor_entry!(process_transaction);
63}