Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed May 30, 2024
1 parent 77c9134 commit b8824ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 13 additions & 9 deletions integration_tests/src/chat_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,22 @@ extern "C" fn callback_read_confirmation_received(_state: *mut c_void) {
extern "C" {
pub fn create_chat_client(
config: *mut c_void,
error_out: *const c_int,
callback_contact_status_change: unsafe extern "C" fn(*mut c_void),
callback_message_received: unsafe extern "C" fn(*mut c_void),
callback_delivery_confirmation_received: unsafe extern "C" fn(*mut c_void),
callback_read_confirmation_received: unsafe extern "C" fn(*mut c_void),
tari_address: *mut c_void,
error_out: *const c_int,
) -> *mut ClientFFI;
pub fn sideload_chat_client(
config: *mut c_void,
contact_handle: *mut c_void,
error_out: *const c_int,
callback_contact_status_change: unsafe extern "C" fn(*mut c_void),
callback_message_received: unsafe extern "C" fn(*mut c_void),
callback_delivery_confirmation_received: unsafe extern "C" fn(*mut c_void),
callback_read_confirmation_received: unsafe extern "C" fn(*mut c_void),
tari_address: *mut c_void,
error_out: *const c_int,
) -> *mut ClientFFI;
pub fn create_chat_message(
receiver: *mut c_void,
Expand Down Expand Up @@ -310,26 +312,26 @@ pub async fn spawn_ffi_chat_client(name: &str, seed_peers: Vec<Peer>, base_dir:
let client_ptr;

let error_out = Box::into_raw(Box::new(0));

let address =
TariAddress::new_single_address_with_default_features(identity.public_key().clone(), Network::LocalNet);
let address_ptr = Box::into_raw(Box::new(address.clone())) as *mut c_void;
unsafe {
*ChatCallback::instance().contact_status_change.lock().unwrap() = 0;

client_ptr = create_chat_client(
config_ptr,
error_out,
callback_contact_status_change,
callback_message_received,
callback_delivery_confirmation_received,
callback_read_confirmation_received,
address_ptr,
error_out,
);
}

ChatFFI {
ptr: Arc::new(Mutex::new(PtrWrapper(client_ptr))),
address: TariAddress::new_single_address_with_default_features(
identity.public_key().clone(),
Network::LocalNet,
),
address,
}
}

Expand All @@ -342,6 +344,7 @@ pub async fn sideload_ffi_chat_client(
config.chat_client.set_base_path(base_dir);

let config_ptr = Box::into_raw(Box::new(config)) as *mut c_void;
let adress_ptr = Box::into_raw(Box::new(address.clone())) as *mut c_void;

let client_ptr;
let error_out = Box::into_raw(Box::new(0));
Expand All @@ -351,11 +354,12 @@ pub async fn sideload_ffi_chat_client(
client_ptr = sideload_chat_client(
config_ptr,
contacts_handle_ptr,
error_out,
callback_contact_status_change,
callback_message_received,
callback_delivery_confirmation_received,
callback_read_confirmation_received,
adress_ptr,
error_out,
);
}

Expand Down
5 changes: 2 additions & 3 deletions integration_tests/tests/steps/chat_ffi_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ async fn chat_ffi_client_connected_to_base_node(world: &mut TariWorld, name: Str
#[when(expr = "I have a sideloaded chat FFI client {word} from {word}")]
async fn sideloaded_chat_ffi_client_connected_to_wallet(world: &mut TariWorld, chat_name: String, wallet_name: String) {
let wallet = world.get_ffi_wallet(&wallet_name).unwrap();
let pubkey = world.get_wallet_address(&wallet_name).await.unwrap();
let address = TariAddress::from_hex(&pubkey).unwrap();

let address = world.get_wallet_address(&wallet_name).await.unwrap();
let address = TariAddress::from_hex(&address).unwrap();
let client = sideload_ffi_chat_client(address, wallet.base_dir.clone(), wallet.contacts_handle()).await;
world.chat_clients.insert(chat_name, Box::new(client));
}
Expand Down

0 comments on commit b8824ba

Please sign in to comment.