Skip to content

Commit

Permalink
Merge branch 'development' into libp2p
Browse files Browse the repository at this point in the history
* development:
  feat: change ffi wallet recovery interface (tari-project#6636)
  • Loading branch information
sdbondi committed Oct 17, 2024
2 parents c8b7cf7 + c6cbbc1 commit d9dfaee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
19 changes: 15 additions & 4 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8748,7 +8748,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 @@ -8802,7 +8802,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,
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 @@ -8817,7 +8817,18 @@ pub unsafe extern "C" fn wallet_start_recovery(
}

let shutdown_signal = (*wallet).shutdown.to_signal();
let peer_id = (*base_node_public_key).to_peer_id();
let peer_ids = if base_node_public_keys.is_null() {
match (*wallet).runtime.block_on((*wallet).wallet.network.get_seed_peers()) {
Ok(peers) => peers.into_iter().map(|p| p.peer_id()).collect(),
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.iter().map(|pk| pk.to_peer_id()).collect()
};
let mut recovery_task_builder = UtxoScannerService::<WalletSqliteDatabase, WalletConnectivityHandle>::builder();

if !recovered_output_message.is_null() {
Expand All @@ -8841,7 +8852,7 @@ pub unsafe extern "C" fn wallet_start_recovery(
};
let mut recovery_task = match runtime.block_on(async {
recovery_task_builder
.with_peers(vec![peer_id])
.with_peers(peer_ids)
.with_retry_limit(10)
.build_with_wallet(&(*wallet).wallet, shutdown_signal)
.await
Expand Down
4 changes: 2 additions & 2 deletions base_layer/wallet_ffi/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3806,7 +3806,7 @@ bool wallet_is_recovery_in_progress(struct TariWallet *wallet,
*
* ## 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 @@ -3859,7 +3859,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 @@ -576,7 +576,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

0 comments on commit d9dfaee

Please sign in to comment.