-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
…-monitoring Bring back tx monitoring
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod delete_identities; | ||
pub mod finalize_identities; | ||
pub mod insert_identities; | ||
pub mod monitor_txs; | ||
pub mod process_identities; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result as AnyhowResult; | ||
use tokio::sync::{mpsc, Mutex}; | ||
|
||
use crate::contracts::{IdentityManager, SharedIdentityManager}; | ||
use crate::ethereum::write::TransactionId; | ||
|
||
pub struct MonitorTxs { | ||
identity_manager: SharedIdentityManager, | ||
monitored_txs_receiver: Arc<Mutex<mpsc::Receiver<TransactionId>>>, | ||
} | ||
|
||
impl MonitorTxs { | ||
pub fn new( | ||
identity_manager: SharedIdentityManager, | ||
monitored_txs_receiver: mpsc::Receiver<TransactionId>, | ||
) -> Arc<Self> { | ||
Arc::new(Self { | ||
identity_manager, | ||
monitored_txs_receiver: Arc::new(Mutex::new(monitored_txs_receiver)), | ||
}) | ||
} | ||
|
||
pub async fn run(self: Arc<Self>) -> anyhow::Result<()> { | ||
monitor_txs_loop(&self.identity_manager, &self.monitored_txs_receiver).await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
async fn monitor_txs_loop( | ||
identity_manager: &IdentityManager, | ||
monitored_txs_receiver: &Mutex<mpsc::Receiver<TransactionId>>, | ||
) -> AnyhowResult<()> { | ||
let mut monitored_txs_receiver = monitored_txs_receiver.lock().await; | ||
|
||
while let Some(tx) = monitored_txs_receiver.recv().await { | ||
if !identity_manager.mine_transaction(tx.clone()).await? { | ||
panic!("Failed to mine transaction: {}", tx); | ||
Check warning on line 40 in src/task_monitor/tasks/monitor_txs.rs GitHub Actions / clippyvariables can be used directly in the `format!` string
Check warning on line 40 in src/task_monitor/tasks/monitor_txs.rs GitHub Actions / clippyvariables can be used directly in the `format!` string
Check warning on line 40 in src/task_monitor/tasks/monitor_txs.rs GitHub Actions / clippyvariables can be used directly in the `format!` string
|
||
} | ||
Check warning on line 41 in src/task_monitor/tasks/monitor_txs.rs GitHub Actions / clippyonly a `panic!` in `if`-then statement
Check warning on line 41 in src/task_monitor/tasks/monitor_txs.rs GitHub Actions / clippyonly a `panic!` in `if`-then statement
Check warning on line 41 in src/task_monitor/tasks/monitor_txs.rs GitHub Actions / clippyonly a `panic!` in `if`-then statement
|
||
} | ||
|
||
Ok(()) | ||
} |