2023-04-15 21:38:47 +00:00
|
|
|
#![allow(unused_variables)]
|
2023-04-16 07:16:53 +00:00
|
|
|
#![allow(unreachable_code)]
|
|
|
|
#![allow(clippy::diverging_sub_expression)]
|
2023-04-15 21:38:47 +00:00
|
|
|
|
2023-04-17 04:50:56 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2023-04-16 07:16:53 +00:00
|
|
|
use zeroize::Zeroizing;
|
|
|
|
|
|
|
|
use ciphersuite::{group::ff::Field, Ciphersuite, Ristretto};
|
2023-04-15 21:38:47 +00:00
|
|
|
|
2023-04-16 07:16:53 +00:00
|
|
|
use serai_db::{Db, MemDb};
|
2023-04-15 21:38:47 +00:00
|
|
|
use serai_client::Serai;
|
|
|
|
|
2023-04-17 04:50:56 +00:00
|
|
|
use tokio::time::sleep;
|
|
|
|
|
2023-04-16 04:51:56 +00:00
|
|
|
mod db;
|
|
|
|
pub use db::*;
|
|
|
|
|
2023-04-11 23:04:53 +00:00
|
|
|
mod transaction;
|
2023-04-16 04:51:56 +00:00
|
|
|
pub use transaction::Transaction as TributaryTransaction;
|
|
|
|
|
|
|
|
mod p2p;
|
|
|
|
pub use p2p::*;
|
|
|
|
|
2023-04-15 21:38:47 +00:00
|
|
|
mod substrate;
|
2023-04-11 23:04:53 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2023-04-16 07:16:53 +00:00
|
|
|
async fn run<D: Db, P: P2p>(
|
|
|
|
db: D,
|
|
|
|
key: Zeroizing<<Ristretto as Ciphersuite>::F>,
|
|
|
|
p2p: P,
|
|
|
|
serai: Serai,
|
|
|
|
) {
|
2023-04-16 04:51:56 +00:00
|
|
|
let mut db = MainDb::new(db);
|
|
|
|
|
2023-04-16 07:16:53 +00:00
|
|
|
let mut last_substrate_block = db.last_substrate_block();
|
2023-04-15 21:38:47 +00:00
|
|
|
|
2023-04-17 04:50:56 +00:00
|
|
|
tokio::spawn(async move {
|
|
|
|
loop {
|
|
|
|
match substrate::handle_new_blocks(&mut db, &key, &p2p, &serai, &mut last_substrate_block)
|
|
|
|
.await
|
|
|
|
{
|
|
|
|
Ok(()) => {}
|
|
|
|
Err(e) => {
|
|
|
|
log::error!("couldn't communicate with serai node: {e}");
|
|
|
|
sleep(Duration::from_secs(5)).await;
|
|
|
|
}
|
|
|
|
}
|
2023-04-15 21:38:47 +00:00
|
|
|
}
|
2023-04-17 04:50:56 +00:00
|
|
|
});
|
2023-04-15 21:38:47 +00:00
|
|
|
|
2023-04-17 04:50:56 +00:00
|
|
|
loop {
|
2023-04-15 21:38:47 +00:00
|
|
|
// Handle all messages from tributaries
|
|
|
|
|
|
|
|
// Handle all messages from processors
|
2023-04-17 04:50:56 +00:00
|
|
|
|
|
|
|
todo!()
|
2023-04-15 21:38:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-11 13:21:35 +00:00
|
|
|
#[tokio::main]
|
2023-04-15 21:38:47 +00:00
|
|
|
async fn main() {
|
2023-04-16 04:51:56 +00:00
|
|
|
let db = MemDb::new(); // TODO
|
2023-04-16 07:16:53 +00:00
|
|
|
let key = Zeroizing::new(<Ristretto as Ciphersuite>::F::ZERO); // TODO
|
2023-04-16 04:51:56 +00:00
|
|
|
let p2p = LocalP2p {}; // TODO
|
|
|
|
let serai = || async {
|
|
|
|
loop {
|
|
|
|
let Ok(serai) = Serai::new("ws://127.0.0.1:9944").await else {
|
|
|
|
log::error!("couldn't connect to the Serai node");
|
|
|
|
continue
|
|
|
|
};
|
|
|
|
return serai;
|
|
|
|
}
|
|
|
|
};
|
2023-04-16 07:16:53 +00:00
|
|
|
run(db, key, p2p, serai().await).await
|
2023-04-15 21:38:47 +00:00
|
|
|
}
|