Fix mempool
This commit is contained in:
parent
cc17413e9c
commit
8af53fde09
|
@ -107,7 +107,11 @@ pub unsafe extern "C" fn migrate_db(coin: u8, db_path: *mut c_char) -> CResult<u
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async unsafe extern "C" fn migrate_data_db(coin: u8) -> CResult<u8> {
|
pub async unsafe extern "C" fn migrate_data_db(coin: u8) -> CResult<u8> {
|
||||||
try_init_logger();
|
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]
|
#[no_mangle]
|
||||||
|
@ -147,6 +151,7 @@ pub unsafe extern "C" fn reset_app() {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async unsafe extern "C" fn mempool_run(port: i64) {
|
pub async unsafe extern "C" fn mempool_run(port: i64) {
|
||||||
|
try_init_logger();
|
||||||
let mut mempool_runner = MEMPOOL_RUNNER.lock().unwrap();
|
let mut mempool_runner = MEMPOOL_RUNNER.lock().unwrap();
|
||||||
let mempool = mempool_runner
|
let mempool = mempool_runner
|
||||||
.run(move |balance: i64| {
|
.run(move |balance: i64| {
|
||||||
|
|
|
@ -135,18 +135,23 @@ pub async fn run_mempool_loop<F: Fn(i64) + Send + Sync + 'static>(
|
||||||
log::info!("MEMPOOL run");
|
log::info!("MEMPOOL run");
|
||||||
let mut active_coin = 0;
|
let mut active_coin = 0;
|
||||||
let mut active_account = 0;
|
let mut active_account = 0;
|
||||||
|
let mut subscribed = false;
|
||||||
while let Some(message) = rx_mesg.recv().await {
|
while let Some(message) = rx_mesg.recv().await {
|
||||||
match message {
|
match message {
|
||||||
MemPoolMsg::Active(coin, id_account) => {
|
MemPoolMsg::Active(coin, id_account) => {
|
||||||
if coin != active_coin || id_account != active_account {
|
if coin != active_coin || id_account != active_account {
|
||||||
active_coin = coin;
|
active_coin = coin;
|
||||||
active_account = id_account;
|
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) => {
|
MemPoolMsg::Subscribe(coin, id_account) => {
|
||||||
let mempool_handler = MemPoolHandler::new(coin, id_account, tx_mesg.clone());
|
if !subscribed {
|
||||||
mempool_handler.subscribe().await?;
|
let mempool_handler = MemPoolHandler::new(coin, id_account, tx_mesg.clone());
|
||||||
|
mempool_handler.subscribe().await?;
|
||||||
|
subscribed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MemPoolMsg::Balance(coin, id_account, balance) => {
|
MemPoolMsg::Balance(coin, id_account, balance) => {
|
||||||
if coin == active_coin && id_account == active_account {
|
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) => {
|
MemPoolMsg::Close(coin, id_account) => {
|
||||||
if coin == active_coin && id_account == active_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);
|
f(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue