Return peers and processes list in init message

This commit is contained in:
NicolasCantu 2025-01-02 14:23:24 +01:00
parent 21c0882a34
commit 4a72fd3129

View File

@ -14,8 +14,8 @@ use bitcoincore_rpc::json::{self as bitcoin_json};
use futures_util::{future, pin_mut, stream::TryStreamExt, FutureExt, StreamExt};
use log::{debug, error, warn};
use message::{broadcast_message, process_message, BroadcastType, MessageCache, MESSAGECACHE};
use scan::compute_partial_tweak_to_transaction;
use sdk_common::{process::CACHEDPROCESSES, sp_client::{bitcoin::{
use scan::{check_transaction_alone, compute_partial_tweak_to_transaction};
use sdk_common::{network::InitMessage, process::CACHEDPROCESSES, sp_client::{bitcoin::{
consensus::deserialize,
hex::{DisplayHex, FromHex},
Amount, Network, Transaction,
@ -66,6 +66,14 @@ pub fn lock_freezed_utxos() -> Result<MutexGuard<'static, HashSet<OutPoint>>, Er
.lock_anyhow()
}
#[derive(Debug, Default)]
pub struct PublicLists {
pub peers_list: Option<String>,
pub processes_list: Option<String>,
}
pub static LISTS: OnceLock<Mutex<PublicLists>> = OnceLock::new();
#[derive(Debug)]
struct WalletFile {
path: PathBuf,
@ -179,9 +187,25 @@ async fn handle_connection(raw_stream: TcpStream, addr: SocketAddr, our_sp_addre
}
};
let public_lists = LISTS.get().expect("Public Lists are not initialized");
let (peers_list, processes_list) = match public_lists.lock_anyhow() {
Ok(lists) => (lists.peers_list.clone(), lists.processes_list.clone()),
Err(e) => {
log::error!("{}", e);
panic!();
}
};
let init_msg = InitMessage::new(
our_sp_address.to_string(),
peers_list,
processes_list,
);
if let Err(e) = broadcast_message(
AnkFlag::Init,
format!("{}", our_sp_address.to_string()),
format!("{}", init_msg.to_string()),
BroadcastType::Sender(addr)
)
{