-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51bf51a
commit eafd054
Showing
7 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
#![allow(unused_mut)] | ||
|
||
use serai_db::Db; | ||
|
||
use serai_client::Serai; | ||
|
||
mod transaction; | ||
mod substrate; | ||
|
||
#[cfg(test)] | ||
mod tests; | ||
|
||
async fn run<D: Db>(db: D, serai: Serai) { | ||
let mut last_substrate_block = 0; // TODO: Load from DB | ||
|
||
loop { | ||
match substrate::handle_new_blocks(&serai, &mut last_substrate_block).await { | ||
Ok(()) => {} | ||
Err(e) => log::error!("couldn't communicate with serai node: {e}"), | ||
} | ||
|
||
// Handle all messages from tributaries | ||
|
||
// Handle all messages from processors | ||
} | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() {} | ||
async fn main() { | ||
// Open the database | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use serai_client::{SeraiError, Block, Serai}; | ||
|
||
async fn handle_block(serai: &Serai, block: Block) -> Result<Vec<()>, SeraiError> { | ||
let hash = block.hash(); | ||
let mut actions = vec![]; | ||
|
||
// If a new validator set was activated, create tributary/inform processor to do a DKG | ||
for new_set in serai.get_new_set_events(hash).await? { | ||
todo!() | ||
} | ||
|
||
// If a key pair was confirmed, inform the processor | ||
for key_gen in serai.get_key_gen_events(hash).await? { | ||
todo!() | ||
} | ||
|
||
// If batch, tell processor of block acknowledged/burns | ||
for new_set in serai.get_batch_events(hash).await? { | ||
todo!() | ||
} | ||
|
||
Ok(actions) | ||
} | ||
|
||
pub(crate) async fn handle_new_blocks( | ||
serai: &Serai, | ||
last_substrate_block: &mut u64, | ||
) -> Result<(), SeraiError> { | ||
// Check if there's been a new Substrate block | ||
let latest = serai.get_latest_block().await?; | ||
let latest_number = latest.number(); | ||
if latest_number == *last_substrate_block { | ||
return Ok(()); | ||
} | ||
let mut latest = Some(latest); | ||
|
||
for b in (*last_substrate_block + 1) ..= latest_number { | ||
let actions = handle_block( | ||
serai, | ||
if b == latest_number { | ||
latest.take().unwrap() | ||
} else { | ||
serai.get_block_by_number(b).await?.unwrap() | ||
}, | ||
) | ||
.await?; | ||
// TODO: Handle actions, update the DB | ||
*last_substrate_block += 1; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters