lib.rs 1.01 KB
Newer Older
clabby's avatar
clabby committed
1 2
#![doc = include_str!("../README.md")]

clabby's avatar
clabby committed
3 4
use receipts::{read_receipts_inner, ReceiptsResult};
use std::os::raw::c_char;
clabby's avatar
clabby committed
5

clabby's avatar
clabby committed
6
mod receipts;
clabby's avatar
clabby committed
7

clabby's avatar
clabby committed
8 9
/// Read the receipts for a blockhash from the RETH database directly.
///
clabby's avatar
clabby committed
10 11 12
/// # Safety
/// - All possible nil pointer dereferences are checked, and the function will return a
///   failing [ReceiptsResult] if any are found.
clabby's avatar
clabby committed
13
#[no_mangle]
clabby's avatar
clabby committed
14
pub unsafe extern "C" fn rdb_read_receipts(
clabby's avatar
clabby committed
15 16 17
    block_hash: *const u8,
    block_hash_len: usize,
    db_path: *const c_char,
clabby's avatar
clabby committed
18
) -> ReceiptsResult {
clabby's avatar
clabby committed
19
    read_receipts_inner(block_hash, block_hash_len, db_path).unwrap_or(ReceiptsResult::fail())
clabby's avatar
clabby committed
20 21
}

clabby's avatar
clabby committed
22
/// Free a string that was allocated in Rust and passed to C.
clabby's avatar
clabby committed
23 24 25
///
/// # Safety
/// - All possible nil pointer dereferences are checked.
clabby's avatar
clabby committed
26
#[no_mangle]
clabby's avatar
clabby committed
27
pub unsafe extern "C" fn rdb_free_string(string: *mut c_char) {
clabby's avatar
clabby committed
28 29 30 31
    // Convert the raw pointer back to a CString and let it go out of scope,
    // which will deallocate the memory.
    if !string.is_null() {
        let _ = std::ffi::CString::from_raw(string);
clabby's avatar
clabby committed
32 33
    }
}