Skip to content

Commit

Permalink
feat: wallet ffi use dns (tari-project#6152)
Browse files Browse the repository at this point in the history
Description
---
Add the option for the wallet_ffi, to use the DNS build into it. 

Motivation and Context
---
Allow the fii to use DNS. 

How Has This Been Tested?
---
Manual
  • Loading branch information
SWvheerden authored Mar 4, 2024
1 parent aaad66e commit 464f2c3
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))?;

Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,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?;

Expand All @@ -1075,7 +1075,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?;

Expand Down Expand Up @@ -1113,7 +1113,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?;

Expand Down
40 changes: 27 additions & 13 deletions base_layer/wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ where
pub async fn set_base_node_peer(
&mut self,
public_key: CommsPublicKey,
address: Multiaddr,
address: Option<Multiaddr>,
) -> Result<(), WalletError> {
info!(
"Wallet setting base node peer, public key: {}, net address: {}.",
"Wallet setting base node peer, public key: {}, net address: {:?}.",
public_key, address
);

Expand All @@ -387,27 +387,41 @@ 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())
.await?;
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(),
Expand Down
Loading

0 comments on commit 464f2c3

Please sign in to comment.