diff --git a/src/api/dart_ffi.rs b/src/api/dart_ffi.rs index 97b6939..7f37518 100644 --- a/src/api/dart_ffi.rs +++ b/src/api/dart_ffi.rs @@ -107,7 +107,11 @@ pub unsafe extern "C" fn migrate_db(coin: u8, db_path: *mut c_char) -> CResult CResult { try_init_logger(); - to_cresult(crate::coinconfig::migrate_data(coin).await.and_then(|()| Ok(0u8))) + to_cresult( + crate::coinconfig::migrate_data(coin) + .await + .and_then(|()| Ok(0u8)), + ) } #[no_mangle] @@ -147,6 +151,7 @@ pub unsafe extern "C" fn reset_app() { #[no_mangle] #[tokio::main] pub async unsafe extern "C" fn mempool_run(port: i64) { + try_init_logger(); let mut mempool_runner = MEMPOOL_RUNNER.lock().unwrap(); let mempool = mempool_runner .run(move |balance: i64| { diff --git a/src/mempool.rs b/src/mempool.rs index 9f0e18a..f6159a1 100644 --- a/src/mempool.rs +++ b/src/mempool.rs @@ -135,18 +135,23 @@ pub async fn run_mempool_loop( log::info!("MEMPOOL run"); let mut active_coin = 0; let mut active_account = 0; + let mut subscribed = false; while let Some(message) = rx_mesg.recv().await { match message { MemPoolMsg::Active(coin, id_account) => { if coin != active_coin || id_account != active_account { active_coin = coin; active_account = id_account; - let _ = tx_mesg.send(MemPoolMsg::Subscribe(coin, id_account)).await; + subscribed = false; + let _ = tx_mesg.send(MemPoolMsg::Subscribe(active_coin, active_account)).await; } } MemPoolMsg::Subscribe(coin, id_account) => { - let mempool_handler = MemPoolHandler::new(coin, id_account, tx_mesg.clone()); - mempool_handler.subscribe().await?; + if !subscribed { + let mempool_handler = MemPoolHandler::new(coin, id_account, tx_mesg.clone()); + mempool_handler.subscribe().await?; + subscribed = true; + } } MemPoolMsg::Balance(coin, id_account, balance) => { if coin == active_coin && id_account == active_account { @@ -155,7 +160,10 @@ pub async fn run_mempool_loop( } MemPoolMsg::Close(coin, id_account) => { if coin == active_coin && id_account == active_account { - let _ = tx_mesg.send(MemPoolMsg::Subscribe(coin, id_account)).await; + subscribed = false; + let _ = tx_mesg + .send(MemPoolMsg::Subscribe(active_coin, active_account)) + .await; f(0); } }