Fix mempool

This commit is contained in:
Hanh 2022-11-21 12:42:07 +08:00
parent cc17413e9c
commit 8af53fde09
2 changed files with 18 additions and 5 deletions

View File

@ -107,7 +107,11 @@ pub unsafe extern "C" fn migrate_db(coin: u8, db_path: *mut c_char) -> CResult<u
#[tokio::main]
pub async unsafe extern "C" fn migrate_data_db(coin: u8) -> CResult<u8> {
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| {

View File

@ -135,18 +135,23 @@ pub async fn run_mempool_loop<F: Fn(i64) + Send + Sync + 'static>(
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<F: Fn(i64) + Send + Sync + 'static>(
}
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);
}
}