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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/// Base58 string to bytes conversion
///
/// # Result
/// The result of execution is `&[u8]` bytes
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
///     let address: Binary = base58!("3NzkzibVRkKUzaRzjUxndpTPvoBzQ3iLng3");
/// }
/// ```
#[macro_export]
macro_rules! base58 {
    ($value:expr) => {{
        let (error, ptr, len) = wevm::v0::bindings::base_58($value.as_ptr(), $value.len());
        error!(error);
        core::slice::from_raw_parts(ptr, len)
    }};
}

/// Bytes to Base58 string conversion
///
/// # Result
/// The result of execution is `&[u8]` bytes
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
///     let address: Binary = base58!("3NzkzibVRkKUzaRzjUxndpTPvoBzQ3iLng3");
///     let address_string: String = to_base58_string!(address);
/// }
/// ```
#[macro_export]
macro_rules! to_base58_string {
    ($value:expr) => {{
        let (error, ptr, len) =
            wevm::v0::bindings::to_base_58_string($value.as_ptr(), $value.len());
        error!(error);
        let bytes = core::slice::from_raw_parts(ptr, len);
        core::str::from_utf8_unchecked(bytes)
    }};
}

/// Get the ContractId of the calling contract
///
/// # Result
/// The result of execution is `&[u8]` ContractId
/// If the returned slice is empty, then the contract was called from a transaction
///
/// # Usage
/// ```
/// use we_cdk::*;
///
/// #[action]
/// fn _constructor() {
///     let caller: Binary = caller!();
/// }
/// ```
#[macro_export]
macro_rules! caller {
    () => {{
        let (error, ptr, len) = wevm::v0::bindings::caller();
        error!(error);
        core::slice::from_raw_parts(ptr, len)
    }};
}