From 7eec72474662d56f585d87a942ec9c7a9023c00b Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Thu, 15 Feb 2024 16:32:55 +0200 Subject: [PATCH 1/4] use dns for ffi --- base_layer/wallet_ffi/src/lib.rs | 42 +++++++++++++++++++++----------- base_layer/wallet_ffi/wallet.h | 1 + 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index b793a18c90..55e47de8dd 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -5259,6 +5259,7 @@ pub unsafe extern "C" fn wallet_create( passphrase: *const c_char, seed_words: *const TariSeedWords, network_str: *const c_char, + peer_seed_str: *const c_char, callback_received_transaction: unsafe extern "C" fn(*mut TariPendingInboundTransaction), callback_received_transaction_reply: unsafe extern "C" fn(*mut TariCompletedTransaction), @@ -5321,24 +5322,16 @@ pub unsafe extern "C" fn wallet_create( SafePassword::from(pf) }; - let network = if network_str.is_null() { - error = LibWalletError::from(InterfaceError::NullError("network".to_string())).code; + let peer_seed = if peer_seed_str.is_null() { + error = LibWalletError::from(InterfaceError::NullError("peer seed dns".to_string())).code; ptr::swap(error_out, &mut error as *mut c_int); return ptr::null_mut(); } else { - let network = CStr::from_ptr(network_str) + let peer_seed = CStr::from_ptr(peer_seed_str) .to_str() - .expect("A non-null network should be able to be converted to string"); - info!(target: LOG_TARGET, "network set to {}", network); - - match Network::from_str(network) { - Ok(n) => n, - Err(_) => { - error = LibWalletError::from(InterfaceError::InvalidArgument("network".to_string())).code; - ptr::swap(error_out, &mut error as *mut c_int); - return ptr::null_mut(); - }, - } + .expect("A non-null peer seed should be able to be converted to string"); + info!(target: LOG_TARGET, "peer seed dns {}", peer_seed); + peer_seed }; let recovery_seed = if seed_words.is_null() { @@ -5355,6 +5348,26 @@ pub unsafe extern "C" fn wallet_create( } }; + let network = if network_str.is_null() { + error = LibWalletError::from(InterfaceError::NullError("network".to_string())).code; + ptr::swap(error_out, &mut error as *mut c_int); + return ptr::null_mut(); + } else { + let network = CStr::from_ptr(network_str) + .to_str() + .expect("A non-null network should be able to be converted to string"); + info!(target: LOG_TARGET, "network set to {}", network); + + match Network::from_str(network) { + Ok(n) => n, + Err(_) => { + error = LibWalletError::from(InterfaceError::InvalidArgument("network".to_string())).code; + ptr::swap(error_out, &mut error as *mut c_int); + return ptr::null_mut(); + }, + } + }; + let runtime = match Runtime::new() { Ok(r) => r, Err(e) => { @@ -5473,6 +5486,7 @@ pub unsafe extern "C" fn wallet_create( let peer_seeds = PeerSeedsConfig { dns_seeds_name_server: DEFAULT_DNS_NAME_SERVER.parse().unwrap(), dns_seeds_use_dnssec: true, + dns_seeds: StringList::from(vec![peer_seed.to_string()]), ..Default::default() }; diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index e8bbfaa5f3..22aef37ea1 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -2707,6 +2707,7 @@ struct TariWallet *wallet_create(TariCommsConfig *config, const char *passphrase, const struct TariSeedWords *seed_words, const char *network_str, + const char *peer_seed_str, void (*callback_received_transaction)(TariPendingInboundTransaction*), void (*callback_received_transaction_reply)(TariCompletedTransaction*), void (*callback_received_finalized_transaction)(TariCompletedTransaction*), From ce2a6d7e100e80681b54e79cb3ac124e1af82a6a Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 20 Feb 2024 12:12:28 +0200 Subject: [PATCH 2/4] add get dns seeds call --- base_layer/wallet_ffi/src/lib.rs | 30 +++++++++++++++++++++++++++++- base_layer/wallet_ffi/wallet.h | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 55e47de8dd..2f71b7540b 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -123,7 +123,7 @@ use tari_common_types::{ }; use tari_comms::{ multiaddr::Multiaddr, - peer_manager::NodeIdentity, + peer_manager::{NodeIdentity, PeerQuery}, transports::MemoryTransport, types::CommsPublicKey, }; @@ -6380,6 +6380,34 @@ pub unsafe extern "C" fn wallet_set_base_node_peer( true } +#[no_mangle] +pub unsafe extern "C" fn wallet_get_seed_peers(wallet: *mut TariWallet, error_out: *mut c_int) -> *mut TariPublicKeys { + let mut error = 0; + ptr::swap(error_out, &mut error as *mut c_int); + if wallet.is_null() { + error = LibWalletError::from(InterfaceError::NullError("wallet".to_string())).code; + ptr::swap(error_out, &mut error as *mut c_int); + return ptr::null_mut(); + } + let peer_manager = (*wallet).wallet.comms.peer_manager(); + let query = PeerQuery::new().select_where(|p| p.is_seed()); + 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) => Box::into_raw(Box::new(TariPublicKeys(public_keys))), + Err(e) => { + error = LibWalletError::from(e).code; + ptr::swap(error_out, &mut error as *mut c_int); + ptr::null_mut() + }, + } +} + /// Upserts a TariContact to the TariWallet. If the contact does not exist it will be Inserted. If it does exist the /// Alias will be updated. /// diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index 22aef37ea1..34720c1b8f 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -3000,6 +3000,8 @@ bool wallet_set_base_node_peer(struct TariWallet *wallet, const char *address, int *error_out); +struct TariPublicKeys *wallet_get_seed_peers(struct TariWallet *wallet, int *error_out); + /** * Upserts a TariContact to the TariWallet. If the contact does not exist it will be Inserted. If it does exist the * Alias will be updated. From 1235f111fc85aae2dcb4b97c4be080235c1b1348 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 27 Feb 2024 10:22:09 +0200 Subject: [PATCH 3/4] fix tests --- base_layer/wallet_ffi/src/lib.rs | 45 ++++++++++++++++++++----- base_layer/wallet_ffi/wallet.h | 17 +++++++++- integration_tests/src/ffi/ffi_import.rs | 1 + integration_tests/src/ffi/wallet.rs | 1 + 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 2f71b7540b..5124e89246 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -6379,7 +6379,18 @@ pub unsafe extern "C" fn wallet_set_base_node_peer( } true } - +/// Gets all seed peers known by the wallet +/// +/// ## Arguments +/// `wallet` - The TariWallet pointer +/// `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions +/// as an out parameter. +/// +/// ## Returns +/// `TariPublicKeys` - Returns a list of all known public keys +/// +/// # Safety +/// None #[no_mangle] pub unsafe extern "C" fn wallet_get_seed_peers(wallet: *mut TariWallet, error_out: *mut c_int) -> *mut TariPublicKeys { let mut error = 0; @@ -9550,6 +9561,7 @@ mod test { let passphrase: *const c_char = CString::into_raw(CString::new("Hello from Alasca").unwrap()) as *const c_char; + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -9559,6 +9571,7 @@ mod test { passphrase, ptr::null(), alice_network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9603,6 +9616,7 @@ mod test { passphrase, ptr::null(), alice_network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9706,7 +9720,7 @@ mod test { let passphrase: *const c_char = CString::into_raw(CString::new("dolphis dancing in the coastal waters").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -9716,6 +9730,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9930,7 +9945,7 @@ mod test { let passphrase: *const c_char = CString::into_raw(CString::new("a cat outside in Istanbul").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let wallet = wallet_create( config, ptr::null(), @@ -9940,6 +9955,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9994,6 +10010,7 @@ mod test { let log_path: *const c_char = CString::into_raw(CString::new(temp_dir.path().join("asdf").to_str().unwrap()).unwrap()) as *const c_char; + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let recovered_wallet = wallet_create( config, log_path, @@ -10003,6 +10020,7 @@ mod test { passphrase, seed_words, network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10070,7 +10088,7 @@ mod test { let passphrase: *const c_char = CString::into_raw(CString::new("Satoshi Nakamoto").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -10080,6 +10098,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10219,7 +10238,7 @@ mod test { let passphrase: *const c_char = CString::into_raw(CString::new("J-bay open corona").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -10229,6 +10248,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10352,7 +10372,7 @@ mod test { let passphrase: *const c_char = CString::into_raw(CString::new("The master and margarita").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -10362,6 +10382,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10565,7 +10586,7 @@ mod test { ); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -10575,6 +10596,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10786,7 +10808,7 @@ mod test { ); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; - + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet = wallet_create( alice_config, ptr::null(), @@ -10796,6 +10818,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -11038,6 +11061,7 @@ mod test { error_ptr, ); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let wallet_ptr = wallet_create( config, ptr::null(), @@ -11047,6 +11071,7 @@ mod test { passphrase, ptr::null(), network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -11276,6 +11301,7 @@ mod test { error_ptr, ); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let alice_wallet_ptr = wallet_create( alice_config, ptr::null(), @@ -11285,6 +11311,7 @@ mod test { passphrase, ptr::null(), alice_network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -11336,6 +11363,7 @@ mod test { error_ptr, ); let passphrase: *const c_char = CString::into_raw(CString::new("niao").unwrap()) as *const c_char; + let dns_string: *const c_char = CString::into_raw(CString::new("").unwrap()) as *const c_char; let bob_wallet_ptr = wallet_create( bob_config, ptr::null(), @@ -11345,6 +11373,7 @@ mod test { passphrase, ptr::null(), bob_network_str, + dns_string, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index 34720c1b8f..9abd38d290 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -3000,7 +3000,22 @@ bool wallet_set_base_node_peer(struct TariWallet *wallet, const char *address, int *error_out); -struct TariPublicKeys *wallet_get_seed_peers(struct TariWallet *wallet, int *error_out); +/** + * Gets all seed peers known by the wallet + * + * ## Arguments + * `wallet` - The TariWallet pointer + * `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions + * as an out parameter. + * + * ## Returns + * `TariPublicKeys` - Returns a list of all known public keys + * + * # Safety + * None + */ +struct TariPublicKeys *wallet_get_seed_peers(struct TariWallet *wallet, + int *error_out); /** * Upserts a TariContact to the TariWallet. If the contact does not exist it will be Inserted. If it does exist the diff --git a/integration_tests/src/ffi/ffi_import.rs b/integration_tests/src/ffi/ffi_import.rs index 3a0d0c8171..7270c75905 100644 --- a/integration_tests/src/ffi/ffi_import.rs +++ b/integration_tests/src/ffi/ffi_import.rs @@ -386,6 +386,7 @@ extern "C" { passphrase: *const c_char, seed_words: *const TariSeedWords, network_str: *const c_char, + peer_seed_str: *const c_char, callback_received_transaction: unsafe extern "C" fn(*mut TariPendingInboundTransaction), callback_received_transaction_reply: unsafe extern "C" fn(*mut TariCompletedTransaction), callback_received_finalized_transaction: unsafe extern "C" fn(*mut TariCompletedTransaction), diff --git a/integration_tests/src/ffi/wallet.rs b/integration_tests/src/ffi/wallet.rs index 436761e2e9..229fb79941 100644 --- a/integration_tests/src/ffi/wallet.rs +++ b/integration_tests/src/ffi/wallet.rs @@ -178,6 +178,7 @@ impl Wallet { CString::new("kensentme").unwrap().into_raw(), seed_words_ptr, CString::new("localnet").unwrap().into_raw(), + CString::new("").unwrap().into_raw(), callback_received_transaction, callback_received_transaction_reply, callback_received_finalized_transaction, From 03192e16bb862b6f78065f20573162e371c31f84 Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Mon, 4 Mar 2024 12:38:52 +0200 Subject: [PATCH 4/4] Make dns_sec optional in ffi make address option in set _address --- .../src/automation/commands.rs | 4 +- .../src/grpc/wallet_grpc_server.rs | 2 +- .../minotari_console_wallet/src/init/mod.rs | 2 +- .../src/ui/state/app_state.rs | 6 +-- base_layer/wallet/src/wallet.rs | 40 +++++++++++------ base_layer/wallet_ffi/src/lib.rs | 43 +++++++++++-------- base_layer/wallet_ffi/wallet.h | 1 + integration_tests/src/ffi/ffi_import.rs | 1 + integration_tests/src/ffi/wallet.rs | 1 + 9 files changed, 64 insertions(+), 36 deletions(-) diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index e09e019ef1..1c400c6221 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -315,7 +315,9 @@ async fn set_base_node_peer( ) -> Result<(CommsPublicKey, Multiaddr), CommandError> { println!("Setting base node peer..."); println!("{}::{}", public_key, address); - wallet.set_base_node_peer(public_key.clone(), address.clone()).await?; + wallet + .set_base_node_peer(public_key.clone(), Some(address.clone())) + .await?; Ok((public_key, address)) } diff --git a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs index b884e7beed..e8166196b2 100644 --- a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -250,7 +250,7 @@ impl wallet_server::Wallet for WalletGrpcServer { println!("{}::{}", public_key, net_address); let mut wallet = self.wallet.clone(); wallet - .set_base_node_peer(public_key.clone(), net_address.clone()) + .set_base_node_peer(public_key.clone(), Some(net_address.clone())) .await .map_err(|e| Status::internal(format!("{:?}", e)))?; diff --git a/applications/minotari_console_wallet/src/init/mod.rs b/applications/minotari_console_wallet/src/init/mod.rs index d37acb7763..6d24fb8c28 100644 --- a/applications/minotari_console_wallet/src/init/mod.rs +++ b/applications/minotari_console_wallet/src/init/mod.rs @@ -571,7 +571,7 @@ pub async fn start_wallet( .ok_or_else(|| ExitError::new(ExitCode::ConfigError, "Configured base node has no address!"))?; wallet - .set_base_node_peer(base_node.public_key.clone(), net_address.address().clone()) + .set_base_node_peer(base_node.public_key.clone(), Some(net_address.address().clone())) .await .map_err(|e| { ExitError::new( diff --git a/applications/minotari_console_wallet/src/ui/state/app_state.rs b/applications/minotari_console_wallet/src/ui/state/app_state.rs index 2c1fd54b4a..25d05adae7 100644 --- a/applications/minotari_console_wallet/src/ui/state/app_state.rs +++ b/applications/minotari_console_wallet/src/ui/state/app_state.rs @@ -1033,7 +1033,7 @@ impl AppStateInner { self.wallet .set_base_node_peer( peer.public_key.clone(), - peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone(), + Some(peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone()), ) .await?; @@ -1058,7 +1058,7 @@ impl AppStateInner { self.wallet .set_base_node_peer( peer.public_key.clone(), - peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone(), + Some(peer.addresses.best().ok_or(UiError::NoAddress)?.address().clone()), ) .await?; @@ -1096,7 +1096,7 @@ impl AppStateInner { self.wallet .set_base_node_peer( previous.public_key.clone(), - previous.addresses.best().ok_or(UiError::NoAddress)?.address().clone(), + Some(previous.addresses.best().ok_or(UiError::NoAddress)?.address().clone()), ) .await?; diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index 28e2c3457f..998392bc8d 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -369,10 +369,10 @@ where pub async fn set_base_node_peer( &mut self, public_key: CommsPublicKey, - address: Multiaddr, + address: Option, ) -> Result<(), WalletError> { info!( - "Wallet setting base node peer, public key: {}, net address: {}.", + "Wallet setting base node peer, public key: {}, net address: {:?}.", public_key, address ); @@ -387,16 +387,19 @@ where let mut connectivity = self.comms.connectivity(); if let Some(mut current_peer) = peer_manager.find_by_public_key(&public_key).await? { // Only invalidate the identity signature if addresses are different - if current_peer.addresses.contains(&address) { - info!( - target: LOG_TARGET, - "Address for base node differs from storage. Was {}, setting to {}", - current_peer.addresses, - address - ); - - current_peer.addresses.add_address(&address, &PeerAddressSource::Config); - peer_manager.add_peer(current_peer.clone()).await?; + if address.is_some() { + let add = address.unwrap(); + if !current_peer.addresses.contains(&add) { + info!( + target: LOG_TARGET, + "Address for base node differs from storage. Was {}, setting to {}", + current_peer.addresses, + add + ); + + current_peer.addresses.add_address(&add, &PeerAddressSource::Config); + peer_manager.add_peer(current_peer.clone()).await?; + } } connectivity .add_peer_to_allow_list(current_peer.node_id.clone()) @@ -404,10 +407,21 @@ where self.wallet_connectivity.set_base_node(current_peer); } else { let node_id = NodeId::from_key(&public_key); + if address.is_none() { + debug!( + target: LOG_TARGET, + "Trying to add new peer without an address", + ); + return Err(WalletError::ArgumentError { + argument: "set_base_node_peer, address".to_string(), + value: "{Missing}".to_string(), + message: "New peers need the address filled in".to_string(), + }); + } let peer = Peer::new( public_key, node_id, - MultiaddressesWithStats::from_addresses_with_source(vec![address], &PeerAddressSource::Config), + MultiaddressesWithStats::from_addresses_with_source(vec![address.unwrap()], &PeerAddressSource::Config), PeerFlags::empty(), PeerFeatures::COMMUNICATION_NODE, Default::default(), diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 5124e89246..47b739f98c 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -5260,6 +5260,7 @@ pub unsafe extern "C" fn wallet_create( seed_words: *const TariSeedWords, network_str: *const c_char, peer_seed_str: *const c_char, + dns_sec: bool, callback_received_transaction: unsafe extern "C" fn(*mut TariPendingInboundTransaction), callback_received_transaction_reply: unsafe extern "C" fn(*mut TariCompletedTransaction), @@ -5485,7 +5486,7 @@ pub unsafe extern "C" fn wallet_create( let peer_seeds = PeerSeedsConfig { dns_seeds_name_server: DEFAULT_DNS_NAME_SERVER.parse().unwrap(), - dns_seeds_use_dnssec: true, + dns_seeds_use_dnssec: dns_sec, dns_seeds: StringList::from(vec![peer_seed.to_string()]), ..Default::default() }; @@ -6343,23 +6344,18 @@ pub unsafe extern "C" fn wallet_set_base_node_peer( return false; } - let parsed_addr; - if address.is_null() { - error = LibWalletError::from(InterfaceError::NullError("address".to_string())).code; - ptr::swap(error_out, &mut error as *mut c_int); - return false; + let parsed_addr = if address.is_null() { + None } else { match CStr::from_ptr(address).to_str() { - Ok(v) => { - parsed_addr = match Multiaddr::from_str(v) { - Ok(v) => v, - Err(_) => { - error = LibWalletError::from(InterfaceError::InvalidArgument("address is invalid".to_string())) - .code; - ptr::swap(error_out, &mut error as *mut c_int); - return false; - }, - } + Ok(v) => match Multiaddr::from_str(v) { + Ok(v) => Some(v), + Err(_) => { + error = + LibWalletError::from(InterfaceError::InvalidArgument("address is invalid".to_string())).code; + ptr::swap(error_out, &mut error as *mut c_int); + return false; + }, }, _ => { error = LibWalletError::from(InterfaceError::PointerError("address".to_string())).code; @@ -6367,7 +6363,7 @@ pub unsafe extern "C" fn wallet_set_base_node_peer( return false; }, } - } + }; if let Err(e) = (*wallet) .runtime @@ -9572,6 +9568,7 @@ mod test { ptr::null(), alice_network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9617,6 +9614,7 @@ mod test { ptr::null(), alice_network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9731,6 +9729,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -9956,6 +9955,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10021,6 +10021,7 @@ mod test { seed_words, network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10099,6 +10100,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10249,6 +10251,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10383,6 +10386,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10597,6 +10601,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -10819,6 +10824,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -11072,6 +11078,7 @@ mod test { ptr::null(), network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -11312,6 +11319,7 @@ mod test { ptr::null(), alice_network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, @@ -11374,6 +11382,7 @@ mod test { ptr::null(), bob_network_str, dns_string, + false, received_tx_callback, received_tx_reply_callback, received_tx_finalized_callback, diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index 9abd38d290..e3ac32b65b 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -2708,6 +2708,7 @@ struct TariWallet *wallet_create(TariCommsConfig *config, const struct TariSeedWords *seed_words, const char *network_str, const char *peer_seed_str, + bool dns_sec, void (*callback_received_transaction)(TariPendingInboundTransaction*), void (*callback_received_transaction_reply)(TariCompletedTransaction*), void (*callback_received_finalized_transaction)(TariCompletedTransaction*), diff --git a/integration_tests/src/ffi/ffi_import.rs b/integration_tests/src/ffi/ffi_import.rs index 7270c75905..01f7405477 100644 --- a/integration_tests/src/ffi/ffi_import.rs +++ b/integration_tests/src/ffi/ffi_import.rs @@ -387,6 +387,7 @@ extern "C" { seed_words: *const TariSeedWords, network_str: *const c_char, peer_seed_str: *const c_char, + dns_sec: bool, callback_received_transaction: unsafe extern "C" fn(*mut TariPendingInboundTransaction), callback_received_transaction_reply: unsafe extern "C" fn(*mut TariCompletedTransaction), callback_received_finalized_transaction: unsafe extern "C" fn(*mut TariCompletedTransaction), diff --git a/integration_tests/src/ffi/wallet.rs b/integration_tests/src/ffi/wallet.rs index 229fb79941..5cf63cfc8f 100644 --- a/integration_tests/src/ffi/wallet.rs +++ b/integration_tests/src/ffi/wallet.rs @@ -179,6 +179,7 @@ impl Wallet { seed_words_ptr, CString::new("localnet").unwrap().into_raw(), CString::new("").unwrap().into_raw(), + false, callback_received_transaction, callback_received_transaction_reply, callback_received_finalized_transaction,