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: wallet ffi use dns #6152

Merged
merged 4 commits into from
Mar 4, 2024
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
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 @@ -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?;

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

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

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
Loading