Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change ffi wallet recovery interface #6636

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8901,7 +8901,7 @@ pub unsafe extern "C" fn wallet_is_recovery_in_progress(wallet: *mut TariWallet,
///
/// ## Arguments
/// `wallet` - The TariWallet pointer.
/// `base_node_public_key` - The TariPublicKey pointer of the Base Node the recovery process will use
/// `base_node_public_keys` - An optional TariPublicKeys pointer of the Base Nodes the recovery process must use
/// `recovery_progress_callback` - The callback function pointer that will be used to asynchronously communicate
/// progress to the client. The first argument of the callback is an event enum encoded as a u8 as follows:
/// ```
Expand Down Expand Up @@ -8955,7 +8955,7 @@ pub unsafe extern "C" fn wallet_is_recovery_in_progress(wallet: *mut TariWallet,
#[no_mangle]
pub unsafe extern "C" fn wallet_start_recovery(
wallet: *mut TariWallet,
base_node_public_key: *mut TariPublicKey,
base_node_public_keys: *mut TariPublicKeys,
hansieodendaal marked this conversation as resolved.
Show resolved Hide resolved
recovery_progress_callback: unsafe extern "C" fn(context: *mut c_void, u8, u64, u64),
recovered_output_message: *const c_char,
error_out: *mut c_int,
Expand All @@ -8970,7 +8970,28 @@ pub unsafe extern "C" fn wallet_start_recovery(
}

let shutdown_signal = (*wallet).shutdown.to_signal();
let peer_public_keys: Vec<TariPublicKey> = vec![(*base_node_public_key).clone()];
let peer_public_keys = if base_node_public_keys.is_null() {
let peer_manager = (*wallet).wallet.comms.peer_manager();
let query = PeerQuery::new().select_where(|p| p.is_seed());
#[allow(clippy::blocks_in_conditions)]
match (*wallet).runtime.block_on(async move {
let peers = peer_manager.perform_query(query).await?;
let mut public_keys = Vec::with_capacity(peers.len());
for peer in peers {
public_keys.push(peer.public_key);
}
Result::<_, WalletError>::Ok(public_keys)
}) {
Ok(public_keys) => public_keys,
Err(e) => {
error = LibWalletError::from(InterfaceError::NullError(format!("{}", e))).code;
ptr::swap(error_out, &mut error as *mut c_int);
return false;
},
}
} else {
(*base_node_public_keys).0.clone()
};
let mut recovery_task_builder = UtxoScannerService::<WalletSqliteDatabase, WalletConnectivityHandle>::builder();

if !recovered_output_message.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4021,7 +4021,7 @@ bool wallet_is_recovery_in_progress(struct TariWallet *wallet,
* None
*/
bool wallet_start_recovery(struct TariWallet *wallet,
TariPublicKey *base_node_public_key,
struct TariPublicKeys *base_node_public_keys,
void (*recovery_progress_callback)(void *context,
uint8_t,
uint64_t,
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/ffi/ffi_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ extern "C" {
pub fn wallet_is_recovery_in_progress(wallet: *mut TariWallet, error_out: *mut c_int) -> bool;
pub fn wallet_start_recovery(
wallet: *mut TariWallet,
base_node_public_key: *mut TariPublicKey,
base_node_public_keys: *mut TariPublicKeys,
recovery_progress_callback: unsafe extern "C" fn(context: *mut c_void, u8, u64, u64),
recovered_output_message: *const c_char,
error_out: *mut c_int,
Expand Down
Loading