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
use wallet_core::c::time::{block_date_from_system_time, max_epiration_date, BlockDate};

use crate::{ErrorPtr, Settings};

/// This function dereference raw pointers. Even though the function checks if
/// the pointers are null. Mind not to put random values in or you may see
/// unexpected behaviors.
///
/// # Arguments
///
/// *settings*: the blockchain settings previously allocated with this library.  
/// *date*: desired date of expiration for a fragment. It must be expressed in seconds since the
/// unix epoch.
/// *block_date_out*: pointer to an allocated BlockDate structure, the memory should be writable.
///
/// # Safety
///
/// pointers should be allocated by this library and be valid.
/// null pointers are checked and will result in an error.
///
#[no_mangle]
pub unsafe extern "C" fn iohk_jormungandr_block_date_from_system_time(
    settings: *const Settings,
    date: u64,
    block_date_out: *mut BlockDate,
) -> ErrorPtr {
    let r = block_date_from_system_time(settings.cast::<wallet::Settings>(), date, block_date_out);

    r.into_c_api() as ErrorPtr
}

/// This function dereference raw pointers. Even though the function checks if
/// the pointers are null. Mind not to put random values in or you may see
/// unexpected behaviors.
///
/// # Arguments
///
/// *settings*: the blockchain settings previously allocated with this library.  
/// *current_time*: Current real time. It must be expressed in seconds since the unix epoch.
/// *block_date_out*: pointer to an allocated BlockDate structure, the memory should be writable.
///
/// # Safety
///
/// pointers should be allocated by this library and be valid.
/// null pointers are checked and will result in an error.
///
#[no_mangle]
pub unsafe extern "C" fn iohk_jormungandr_max_expiration_date(
    settings: *const Settings,
    current_time: u64,
    block_date_out: *mut BlockDate,
) -> ErrorPtr {
    let r = max_epiration_date(
        settings.cast::<wallet::Settings>(),
        current_time,
        block_date_out,
    );

    r.into_c_api() as ErrorPtr
}