mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-08-10 03:50:03 +00:00
use tokio::spawn for monitoring function to make it run concurrent in a correct way
This commit is contained in:
@ -193,9 +193,9 @@ async fn poll_final_payout(
|
||||
panic!("implement")
|
||||
}
|
||||
|
||||
pub async fn api_server(coordinator: Coordinator) -> Result<()> {
|
||||
let database = coordinator.coordinator_db;
|
||||
let wallet = coordinator.coordinator_wallet;
|
||||
pub async fn api_server(coordinator: Arc<Coordinator>) -> Result<()> {
|
||||
let database = Arc::clone(&coordinator.coordinator_db);
|
||||
let wallet = Arc::clone(&coordinator.coordinator_wallet);
|
||||
|
||||
let app = Router::new()
|
||||
.route("/create-offer", post(receive_order))
|
||||
|
@ -35,9 +35,9 @@ async fn punish_trader(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn monitor_bonds(coordinator: &Coordinator) -> Result<()> {
|
||||
let coordinator_db = &coordinator.coordinator_db;
|
||||
let coordinator_wallet = &coordinator.coordinator_wallet;
|
||||
pub async fn monitor_bonds(coordinator: Arc<Coordinator>) -> Result<()> {
|
||||
let coordinator_db = Arc::clone(&coordinator.coordinator_db);
|
||||
let coordinator_wallet = Arc::clone(&coordinator.coordinator_wallet);
|
||||
|
||||
loop {
|
||||
// fetch all bonds
|
||||
@ -55,7 +55,7 @@ pub async fn monitor_bonds(coordinator: &Coordinator) -> Result<()> {
|
||||
{
|
||||
"1" => {
|
||||
dbg!("Punishing trader for bond violation: {:?}", e);
|
||||
punish_trader(coordinator, bond.0, bond.1).await?;
|
||||
punish_trader(&coordinator, bond.0, bond.1).await?;
|
||||
}
|
||||
"0" => {
|
||||
dbg!("Punishment disabled, ignoring bond violation: {:?}", e);
|
||||
|
@ -15,8 +15,8 @@ use tokio::sync::Mutex;
|
||||
use wallet::*;
|
||||
|
||||
pub struct Coordinator {
|
||||
pub coordinator_db: CoordinatorDB,
|
||||
pub coordinator_wallet: CoordinatorWallet,
|
||||
pub coordinator_db: Arc<CoordinatorDB>,
|
||||
pub coordinator_wallet: Arc<CoordinatorWallet>,
|
||||
}
|
||||
|
||||
// populate .env with values before starting
|
||||
@ -25,13 +25,13 @@ async fn main() -> Result<()> {
|
||||
dotenv().ok();
|
||||
|
||||
// Initialize the database pool
|
||||
let coordinator = Coordinator {
|
||||
coordinator_db: CoordinatorDB::init().await?,
|
||||
coordinator_wallet: CoordinatorWallet::init()?,
|
||||
};
|
||||
let coordinator = Arc::new(Coordinator {
|
||||
coordinator_db: Arc::new(CoordinatorDB::init().await?),
|
||||
coordinator_wallet: Arc::new(CoordinatorWallet::init()?),
|
||||
});
|
||||
|
||||
// begin monitoring bonds
|
||||
monitor_bonds(&coordinator).await?;
|
||||
tokio::spawn(monitor_bonds(Arc::clone(&coordinator)));
|
||||
|
||||
// Start the API server
|
||||
api_server(coordinator).await?;
|
||||
|
Reference in New Issue
Block a user