mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Tributary test wait_for_tx_inclusion function
This commit is contained in:
@@ -20,7 +20,7 @@ use tokio::time::sleep;
|
||||
|
||||
use serai_db::MemDb;
|
||||
|
||||
use tributary::Tributary;
|
||||
use tributary::{Transaction as TransactionTrait, Tributary};
|
||||
|
||||
use crate::{
|
||||
P2pMessageKind, P2p, LocalP2p,
|
||||
@@ -108,6 +108,44 @@ pub async fn run_tributaries(
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn wait_for_tx_inclusion(
|
||||
tributary: &Tributary<MemDb, Transaction, LocalP2p>,
|
||||
mut last_checked: [u8; 32],
|
||||
hash: [u8; 32],
|
||||
) -> [u8; 32] {
|
||||
loop {
|
||||
let tip = tributary.tip();
|
||||
if tip == last_checked {
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut queue = vec![tributary.block(&tip).unwrap()];
|
||||
let mut block = None;
|
||||
while {
|
||||
let parent = queue.last().unwrap().parent();
|
||||
if parent == tributary.genesis() {
|
||||
false
|
||||
} else {
|
||||
block = Some(tributary.block(&parent).unwrap());
|
||||
block.as_ref().unwrap().hash() != last_checked
|
||||
}
|
||||
} {
|
||||
queue.push(block.take().unwrap());
|
||||
}
|
||||
|
||||
while let Some(block) = queue.pop() {
|
||||
for tx in &block.transactions {
|
||||
if tx.hash() == hash {
|
||||
return block.hash();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
last_checked = tip;
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn tributary_test() {
|
||||
let keys = new_keys(&mut OsRng);
|
||||
|
||||
Reference in New Issue
Block a user