From a4b3ea165eb2b3a8af575c1ce6d38ce8095ec60c Mon Sep 17 00:00:00 2001 From: optout <13562139+optout21@users.noreply.github.com> Date: Wed, 27 May 2026 22:07:19 +0200 Subject: [PATCH] Add missing _c wrapper for get_xpub and get_address --- Cargo.toml | 2 +- lib-py/Cargo.toml | 4 ++-- src/lib.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 52456c5..0ce35e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dlccryptlib" -version = "2.0.0" +version = "2.0.1" edition = "2021" description = "Library for working with DLC's with adaptor signatures (Discrete Log Contracts), by Cadena Bitcoin" license = "MIT" diff --git a/lib-py/Cargo.toml b/lib-py/Cargo.toml index 0f2ec19..2a743d7 100644 --- a/lib-py/Cargo.toml +++ b/lib-py/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dlccryptlib-py" -version = "2.0.0" +version = "2.0.1" edition = "2021" description = "Python-wrapped library for working with DLC's with adaptor signatures (Discrete Log Contracts), by Cadena Bitcoin" license = "MIT" @@ -9,6 +9,6 @@ license = "MIT" name = "dlccryptlib_py" [dependencies] -#dlccryptlib = "2.0.0" +#dlccryptlib = "2.0.1" dlccryptlib = { path = "../" } pyo3 = { version = "0.23.1" } diff --git a/src/lib.rs b/src/lib.rs index 35bdcdb..a9c92c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -627,6 +627,32 @@ pub extern "C" fn create_deterministic_nonce_c(event_id: *const c_char, index: u } } +#[no_mangle] +pub extern "C" fn get_xpub_c() -> *mut c_char { + match get_xpub() { + Ok(xpub) => CString::new(xpub).unwrap().into_raw(), + Err(e) => error_as_cstr_prefix(e), + } +} + +#[no_mangle] +pub extern "C" fn get_address_c(index4: u32, index5: u32) -> *mut c_char { + match get_address(index4, index5) { + Ok(address) => CString::new(address).unwrap().into_raw(), + Err(e) => error_as_cstr_prefix(e), + } +} + +#[no_mangle] +pub extern "C" fn free_cstring(s: *mut c_char) { + unsafe { + if s.is_null() { + return; + } + let _ = CString::from_raw(s); + } +} + // Return error with an "ERROR: " prefix, as a C string fn error_as_cstr_prefix(error: String) -> *mut c_char { CString::new(format!("ERROR: {}", error))