2023-04-15 21:38:47 +00:00
|
|
|
#![allow(unused_variables)]
|
|
|
|
|
2023-04-16 04:51:56 +00:00
|
|
|
use serai_db::{Db, MemDb};
|
2023-04-15 21:38:47 +00:00
|
|
|
|
|
|
|
use serai_client::Serai;
|
|
|
|
|
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 04:51:56 +00:00
|
|
|
async fn run<D: Db, P: P2p>(db: D, p2p: P, serai: Serai) {
|
|
|
|
let mut db = MainDb::new(db);
|
|
|
|
|
2023-04-15 21:38:47 +00:00
|
|
|
let mut last_substrate_block = 0; // TODO: Load from DB
|
|
|
|
|
|
|
|
loop {
|
2023-04-16 04:51:56 +00:00
|
|
|
match substrate::handle_new_blocks(&mut db, &p2p, &serai, &mut last_substrate_block).await {
|
2023-04-15 21:38:47 +00:00
|
|
|
Ok(()) => {}
|
|
|
|
Err(e) => log::error!("couldn't communicate with serai node: {e}"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle all messages from tributaries
|
|
|
|
|
|
|
|
// Handle all messages from processors
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
run(db, p2p, serai().await).await
|
2023-04-15 21:38:47 +00:00
|
|
|
}
|