mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-25 10:23:20 -05:00
feat(monero): Remote node load balancing (#420)
This commit is contained in:
parent
a201c13b5d
commit
ff5e1c02bc
55 changed files with 4537 additions and 154 deletions
|
|
@ -141,7 +141,8 @@ fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
// We need to set a value for the Tauri state right at the start
|
||||
// If we don't do this, Tauri commands will panic at runtime if no value is present
|
||||
app_handle.manage::<RwLock<State>>(RwLock::new(State::new()));
|
||||
let state = RwLock::new(State::new());
|
||||
app_handle.manage::<RwLock<State>>(state);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -192,7 +193,7 @@ pub fn run() {
|
|||
get_data_dir,
|
||||
resolve_approval_request,
|
||||
redact,
|
||||
save_txt_files
|
||||
save_txt_files,
|
||||
])
|
||||
.setup(setup)
|
||||
.build(tauri::generate_context!())
|
||||
|
|
@ -366,6 +367,48 @@ async fn initialize_context(
|
|||
.context("Context is already being initialized")
|
||||
.to_string_result()?;
|
||||
|
||||
// Determine which Monero node to use:
|
||||
// - If using RPC pool, start and use the local RPC pool
|
||||
// - Otherwise, use the provided node URL directly (even if empty)
|
||||
let monero_node_url = if settings.use_monero_rpc_pool {
|
||||
// Start RPC pool and use it
|
||||
let data_dir = data::data_dir_from(None, testnet).to_string_result()?;
|
||||
match monero_rpc_pool::start_server_with_random_port(
|
||||
monero_rpc_pool::config::Config::new_random_port(
|
||||
"127.0.0.1".to_string(),
|
||||
data_dir.join("monero-rpc-pool"),
|
||||
),
|
||||
match testnet {
|
||||
true => swap::monero::Network::Stagenet,
|
||||
false => swap::monero::Network::Mainnet,
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok((server_info, mut status_receiver, _task_manager)) => {
|
||||
let rpc_url = format!("http://{}:{}", server_info.host, server_info.port);
|
||||
tracing::info!("Monero RPC Pool started on {}", rpc_url);
|
||||
|
||||
// Start listening for pool status updates and forward them to frontend
|
||||
let pool_tauri_handle = TauriHandle::new(app_handle.clone());
|
||||
tauri::async_runtime::spawn(async move {
|
||||
while let Ok(status) = status_receiver.recv().await {
|
||||
pool_tauri_handle.emit_pool_status_update(status);
|
||||
}
|
||||
});
|
||||
|
||||
rpc_url.parse().ok()
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to start Monero RPC Pool: {}", e);
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Use the provided node URL directly without checking availability
|
||||
settings.monero_node_url.clone()
|
||||
};
|
||||
|
||||
// Get app handle and create a Tauri handle
|
||||
let tauri_handle = TauriHandle::new(app_handle.clone());
|
||||
|
||||
|
|
@ -378,7 +421,7 @@ async fn initialize_context(
|
|||
bitcoin_target_block: None,
|
||||
})
|
||||
.with_monero(Monero {
|
||||
monero_node_address: settings.monero_node_url.clone(),
|
||||
monero_node_address: monero_node_url,
|
||||
})
|
||||
.with_json(false)
|
||||
.with_debug(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue