Skip to content

Commit

Permalink
Add bindings to backup & restore wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
tmalahie committed Dec 7, 2024
1 parent a920f58 commit 038045d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
18 changes: 18 additions & 0 deletions bindings/c-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ 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_blind_receive(
wallet: &COpaqueStruct,
Expand Down Expand Up @@ -244,6 +253,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,
Expand Down
24 changes: 24 additions & 0 deletions bindings/c-ffi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ 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);
let res = wallet.backup(&backup_path, &password)?;
Ok(res)
}

pub(crate) fn blind_receive(
wallet: &COpaqueStruct,
asset_id_opt: *const c_char,
Expand Down Expand Up @@ -404,6 +416,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);
let res = rgb_lib::restore_backup(&backup_path, &password, &target_dir)?;
Ok(res)
}

pub(crate) fn restore_keys(
bitcoin_network: *const c_char,
mnemonic: *const c_char,
Expand Down

0 comments on commit 038045d

Please sign in to comment.