neptune_common/debug.rs
1/// This macro prints debug information to the wasm attributes
2/// and then exits without sending any additional messages.
3/// Additional information is included in the attributes like the function name.
4/// ```
5/// # use cosmwasm_std::{attr, Response, StdResult};
6/// # use neptune_common::debug;
7/// let mut attrs = vec![];
8/// let a = (1u32, 2u32, "Hello World".to_string());
9/// let b = "data";
10/// debug!(attrs, a, b); // attrs will be populated with debug information of a, b, ...
11/// let res: Response<()> = Response::default().add_attributes(attrs); // Attributes must be manually added to the response
12/// ```
13#[macro_export]
14macro_rules! debug {
15 ($attrs:ident, $( $vars:expr ),*) => {{
16 fn f() {}
17 fn type_name_of<T>(_: T) -> &'static str {
18 std::any::type_name::<T>()
19 }
20 let name = type_name_of(f);
21 let func_name = format!("In function: {}", &name[..name.len() - 3]);
22 $attrs.push(attr("neptune_debug", func_name));
23 $(
24 $attrs.push(attr(stringify!($vars), format!("{0:?}",$vars)));
25 )*
26 }};
27}
28
29/// This macro prints debug information to the wasm attributes
30/// and then exits without sending any additional messages.
31/// Additional information is included in the attributes like the function name.
32/// ```
33/// # use cosmwasm_std::{attr, Response, StdResult};
34/// # use neptune_common::debug_and_exit;
35/// # fn test_execute() -> StdResult<Response> {
36/// let a = (1u32, 2u32, "Hello World".to_string());
37/// let b = "data";
38/// debug_and_exit!(a, b); // Function will exit here and print the debug information of a, b, ...
39/// Ok(Response::default()) // This line will never be reached
40/// # }
41/// # test_execute().unwrap();
42/// ```
43#[macro_export]
44macro_rules! debug_and_exit {
45 ($( $vars:expr ),*) => {{
46 fn f() {}
47 fn type_name_of<T>(_: T) -> &'static str {
48 std::any::type_name::<T>()
49 }
50 let name = type_name_of(f);
51 let func_name = format!("In function: {}", &name[..name.len() - 3]);
52 let mut attrs = vec![];
53 attrs.push(attr("neptune_debug", func_name));
54 $(
55 attrs.push(attr(stringify!($vars), format!("{0:?}",$vars)));
56 )*
57 return Ok(Response::new().add_attributes(attrs));
58 }};
59}