Skip to main content

miden_base_sys/bindings/
tx.rs

1use miden_stdlib_sys::{Felt, Word};
2
3#[allow(improper_ctypes)]
4unsafe extern "C" {
5    #[link_name = "miden::protocol::tx::get_block_number"]
6    pub fn extern_tx_get_block_number() -> Felt;
7
8    #[link_name = "miden::protocol::tx::get_block_commitment"]
9    pub fn extern_tx_get_block_commitment(ptr: *mut Word);
10
11    #[link_name = "miden::protocol::tx::get_block_timestamp"]
12    pub fn extern_tx_get_block_timestamp() -> Felt;
13
14    #[link_name = "miden::protocol::tx::get_input_notes_commitment"]
15    pub fn extern_tx_get_input_notes_commitment(ptr: *mut Word);
16
17    #[link_name = "miden::protocol::tx::get_output_notes_commitment"]
18    pub fn extern_tx_get_output_notes_commitment(ptr: *mut Word);
19
20    #[link_name = "miden::protocol::tx::get_num_input_notes"]
21    pub fn extern_tx_get_num_input_notes() -> Felt;
22
23    #[link_name = "miden::protocol::tx::get_num_output_notes"]
24    pub fn extern_tx_get_num_output_notes() -> Felt;
25
26    #[link_name = "miden::protocol::tx::get_expiration_block_delta"]
27    pub fn extern_tx_get_expiration_block_delta() -> Felt;
28
29    #[link_name = "miden::protocol::tx::update_expiration_block_delta"]
30    pub fn extern_tx_update_expiration_block_delta(delta: Felt);
31}
32
33/// Returns the current block number.
34pub fn get_block_number() -> Felt {
35    unsafe { extern_tx_get_block_number() }
36}
37
38/// Returns the input notes commitment digest.
39pub fn get_input_notes_commitment() -> Word {
40    unsafe {
41        let mut ret_area = ::core::mem::MaybeUninit::<Word>::uninit();
42        extern_tx_get_input_notes_commitment(ret_area.as_mut_ptr());
43        ret_area.assume_init().reverse()
44    }
45}
46
47/// Returns the block commitment of the reference block.
48pub fn get_block_commitment() -> Word {
49    unsafe {
50        let mut ret_area = ::core::mem::MaybeUninit::<Word>::uninit();
51        extern_tx_get_block_commitment(ret_area.as_mut_ptr());
52        ret_area.assume_init().reverse()
53    }
54}
55
56/// Returns the timestamp of the reference block.
57pub fn get_block_timestamp() -> Felt {
58    unsafe { extern_tx_get_block_timestamp() }
59}
60
61/// Returns the total number of input notes consumed by the transaction.
62pub fn get_num_input_notes() -> Felt {
63    unsafe { extern_tx_get_num_input_notes() }
64}
65
66/// Returns the number of output notes created so far in the transaction.
67pub fn get_num_output_notes() -> Felt {
68    unsafe { extern_tx_get_num_output_notes() }
69}
70
71/// Returns the transaction expiration block delta.
72pub fn get_expiration_block_delta() -> Felt {
73    unsafe { extern_tx_get_expiration_block_delta() }
74}
75
76/// Updates the transaction expiration block delta.
77pub fn update_expiration_block_delta(delta: Felt) {
78    unsafe {
79        extern_tx_update_expiration_block_delta(delta);
80    }
81}
82
83/// Returns the output notes commitment digest.
84pub fn get_output_notes_commitment() -> Word {
85    unsafe {
86        let mut ret_area = ::core::mem::MaybeUninit::<Word>::uninit();
87        extern_tx_get_output_notes_commitment(ret_area.as_mut_ptr());
88        ret_area.assume_init().reverse()
89    }
90}