diff --git a/bindings/c-ffi/src/lib.rs b/bindings/c-ffi/src/lib.rs index 9ddd8db..3cf5218 100644 --- a/bindings/c-ffi/src/lib.rs +++ b/bindings/c-ffi/src/lib.rs @@ -54,6 +54,20 @@ pub extern "C" fn free_wallet(obj: COpaqueStruct) { } } +#[no_mangle] +pub extern "C" fn rgblib_backup( + wallet: &COpaqueStruct, + backup_path: *const c_char, + password: *const c_char, +) -> CResult { + backup(wallet, backup_path, password).into() +} + +#[no_mangle] +pub extern "C" fn rgblib_backup_info(wallet: &COpaqueStruct) -> CResultString { + backup_info(wallet).into() +} + #[no_mangle] pub extern "C" fn rgblib_blind_receive( wallet: &COpaqueStruct, @@ -244,6 +258,15 @@ pub extern "C" fn rgblib_refresh( refresh(wallet, online, asset_id_opt, filter, skip_sync).into() } +#[no_mangle] +pub extern "C" fn rgblib_restore_backup( + backup_path: *const c_char, + password: *const c_char, + target_dir: *const c_char, +) -> CResult { + restore_backup(backup_path, password, target_dir).into() +} + #[no_mangle] pub extern "C" fn rgblib_restore_keys( bitcoin_network: *const c_char, diff --git a/bindings/c-ffi/src/utils.rs b/bindings/c-ffi/src/utils.rs index b61a816..01a09af 100644 --- a/bindings/c-ffi/src/utils.rs +++ b/bindings/c-ffi/src/utils.rs @@ -166,6 +166,24 @@ fn string_to_ptr(other: String) -> *mut c_char { cstr.into_raw() } +pub(crate) fn backup( + wallet: &COpaqueStruct, + backup_path: *const c_char, + password: *const c_char, +) -> Result<(), Error> { + let wallet = Wallet::from_opaque(wallet)?; + let backup_path = ptr_to_string(backup_path); + let password = ptr_to_string(password); + wallet.backup(&backup_path, &password)?; + Ok(()) +} + +pub(crate) fn backup_info(wallet: &COpaqueStruct) -> Result { + let wallet = Wallet::from_opaque(wallet)?; + let res = wallet.backup_info()?; + Ok(serde_json::to_string(&res)?) +} + pub(crate) fn blind_receive( wallet: &COpaqueStruct, asset_id_opt: *const c_char, @@ -404,6 +422,18 @@ pub(crate) fn refresh( Ok(serde_json::to_string(&res)?) } +pub(crate) fn restore_backup( + backup_path: *const c_char, + password: *const c_char, + target_dir: *const c_char, +) -> Result<(), Error> { + let backup_path = ptr_to_string(backup_path); + let password = ptr_to_string(password); + let target_dir = ptr_to_string(target_dir); + rgb_lib::restore_backup(&backup_path, &password, &target_dir)?; + Ok(()) +} + pub(crate) fn restore_keys( bitcoin_network: *const c_char, mnemonic: *const c_char,