Add a way to check if blocks completed eventualities

This commit is contained in:
Luke Parker
2023-03-22 22:45:41 -04:00
parent 11a0803ea5
commit 8447021ba1
6 changed files with 244 additions and 12 deletions

View File

@@ -15,7 +15,7 @@ use tokio::{
use crate::{
DbTxn, Db,
coins::{Output, Block, Coin},
coins::{Output, EventualitiesTracker, Block, Coin},
};
#[derive(Clone, Debug)]
@@ -172,6 +172,8 @@ pub struct Scanner<C: Coin, D: Db> {
db: ScannerDb<C, D>,
keys: Vec<<C::Curve as Ciphersuite>::G>,
eventualities: EventualitiesTracker<C::Eventuality>,
ram_scanned: HashMap<Vec<u8>, usize>,
ram_outputs: HashSet<Vec<u8>>,
@@ -198,6 +200,15 @@ impl<C: Coin, D: Db> ScannerHandle<C, D> {
res.unwrap_or(0)
}
pub async fn register_eventuality(
&self,
block_number: usize,
id: [u8; 32],
eventuality: C::Eventuality,
) {
self.scanner.write().await.eventualities.register(block_number, id, eventuality)
}
/// Rotate the key being scanned for.
///
/// If no key has been prior set, this will become the key with no further actions.
@@ -257,6 +268,8 @@ impl<C: Coin, D: Db> Scanner<C, D> {
db,
keys: keys.clone(),
eventualities: EventualitiesTracker::new(),
ram_scanned: HashMap::new(),
ram_outputs: HashSet::new(),
@@ -338,6 +351,17 @@ impl<C: Coin, D: Db> Scanner<C, D> {
txn.commit();
}
// Clone coin because we can't borrow it while also mutably borrowing the eventualities
// Thankfully, coin is written to be a cheap clone
let coin = scanner.coin.clone();
for (id, tx) in
coin.get_eventuality_completions(&mut scanner.eventualities, &block).await
{
// TODO: Fire Completed
let _ = id;
let _ = tx;
}
let outputs = match scanner.coin.get_outputs(&block, key).await {
Ok(outputs) => outputs,
Err(_) => {