use crate::{delete_ptr, ErrorPtr};
use ergo_lib_c_core::address::AddressPtr;
use ergo_lib_c_core::derivation_path::ConstDerivationPathPtr;
use ergo_lib_c_core::ext_pub_key::{
ext_pub_key_address, ext_pub_key_child, ext_pub_key_derive, ext_pub_key_new, ConstExtPubKeyPtr,
ExtPubKeyPtr,
};
use ergo_lib_c_core::Error;
#[no_mangle]
pub unsafe extern "C" fn ergo_lib_ext_pub_key_new(
public_key_bytes: *const u8,
chain_code_ptr: *const u8,
derivation_path_ptr: ConstDerivationPathPtr,
ext_pub_key_out: *mut ExtPubKeyPtr,
) -> ErrorPtr {
let res = ext_pub_key_new(
public_key_bytes,
chain_code_ptr,
derivation_path_ptr,
ext_pub_key_out,
);
Error::c_api_from(res)
}
#[no_mangle]
pub unsafe extern "C" fn ergo_lib_ext_pub_key_child(
derive_from_key_ptr: ConstExtPubKeyPtr,
child_index: u32,
ext_pub_key_out: *mut ExtPubKeyPtr,
) -> ErrorPtr {
let res = ext_pub_key_child(derive_from_key_ptr, child_index, ext_pub_key_out);
Error::c_api_from(res)
}
#[no_mangle]
pub unsafe extern "C" fn ergo_lib_ext_pub_key_derive(
ext_pub_key_ptr: ConstExtPubKeyPtr,
derivation_path_ptr: ConstDerivationPathPtr,
ext_pub_key_out: *mut ExtPubKeyPtr,
) -> ErrorPtr {
let res = ext_pub_key_derive(ext_pub_key_ptr, derivation_path_ptr, ext_pub_key_out);
Error::c_api_from(res)
}
#[no_mangle]
pub unsafe extern "C" fn ergo_lib_ext_pub_key_address(
ext_pub_key_ptr: ConstExtPubKeyPtr,
address_out: *mut AddressPtr,
) {
#[allow(clippy::unwrap_used)]
ext_pub_key_address(ext_pub_key_ptr, address_out).unwrap()
}
#[no_mangle]
pub extern "C" fn ergo_lib_ext_pub_key_delete(ptr: ExtPubKeyPtr) {
unsafe { delete_ptr(ptr) }
}