zcash-sync/src/api/mempool.rs

34 lines
1.0 KiB
Rust
Raw Normal View History

2022-10-19 23:24:36 -07:00
//! Access to server mempool
2022-11-06 04:50:51 -08:00
use crate::api::sync::get_latest_height;
use anyhow::anyhow;
2022-06-08 05:48:16 -07:00
use zcash_client_backend::encoding::decode_extended_full_viewing_key;
use zcash_primitives::consensus::Parameters;
use crate::coinconfig::CoinConfig;
2022-09-04 04:19:49 -07:00
use crate::db::AccountData;
2022-06-08 05:48:16 -07:00
2022-10-19 23:24:36 -07:00
/// Scan the mempool and return the unconfirmed balance
2022-06-08 05:48:16 -07:00
pub async fn scan() -> anyhow::Result<i64> {
let c = CoinConfig::get_active();
2022-09-04 04:19:49 -07:00
let AccountData { fvk, .. } = c.db()?.get_account_info(c.id_account)?;
2022-10-19 23:24:36 -07:00
let height = get_latest_height().await?;
2022-06-08 05:48:16 -07:00
let mut mempool = c.mempool.lock().unwrap();
let current_height = c.height;
if height != current_height {
CoinConfig::set_height(height);
mempool.clear()?;
}
let fvk = decode_extended_full_viewing_key(
c.chain.network().hrp_sapling_extended_full_viewing_key(),
2022-09-04 04:19:49 -07:00
&fvk,
2022-11-06 04:50:51 -08:00
)
.map_err(|_| anyhow!("Decode error"))?;
2022-10-19 23:24:36 -07:00
let mut client = c.connect_lwd().await?;
2022-06-08 05:48:16 -07:00
mempool
.update(&mut client, height, &fvk.fvk.vk.ivk())
.await?;
Ok(mempool.get_unconfirmed_balance())
}