|
@ -13,7 +13,8 @@ use daemon::{ |
|
|
}; |
|
|
}; |
|
|
use futures::StreamExt; |
|
|
use futures::StreamExt; |
|
|
use rocket::fairing::AdHoc; |
|
|
use rocket::fairing::AdHoc; |
|
|
use rocket_db_pools::Database; |
|
|
use sqlx::sqlite::SqliteConnectOptions; |
|
|
|
|
|
use sqlx::SqlitePool; |
|
|
use std::collections::HashMap; |
|
|
use std::collections::HashMap; |
|
|
use std::net::SocketAddr; |
|
|
use std::net::SocketAddr; |
|
|
use std::path::PathBuf; |
|
|
use std::path::PathBuf; |
|
@ -31,10 +32,6 @@ mod routes_taker; |
|
|
|
|
|
|
|
|
const CONNECTION_RETRY_INTERVAL: Duration = Duration::from_secs(5); |
|
|
const CONNECTION_RETRY_INTERVAL: Duration = Duration::from_secs(5); |
|
|
|
|
|
|
|
|
#[derive(Database)] |
|
|
|
|
|
#[database("taker")] |
|
|
|
|
|
pub struct Db(sqlx::SqlitePool); |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clap)] |
|
|
#[derive(Clap)] |
|
|
struct Opts { |
|
|
struct Opts { |
|
|
/// The IP address of the other party (i.e. the maker).
|
|
|
/// The IP address of the other party (i.e. the maker).
|
|
@ -164,36 +161,36 @@ async fn main() -> Result<()> { |
|
|
tokio::spawn(task); |
|
|
tokio::spawn(task); |
|
|
|
|
|
|
|
|
let figment = rocket::Config::figment() |
|
|
let figment = rocket::Config::figment() |
|
|
.merge(("databases.taker.url", data_dir.join("taker.sqlite"))) |
|
|
|
|
|
.merge(("address", opts.http_address.ip())) |
|
|
.merge(("address", opts.http_address.ip())) |
|
|
.merge(("port", opts.http_address.port())); |
|
|
.merge(("port", opts.http_address.port())); |
|
|
|
|
|
|
|
|
|
|
|
let db = SqlitePool::connect_with( |
|
|
|
|
|
SqliteConnectOptions::new() |
|
|
|
|
|
.create_if_missing(true) |
|
|
|
|
|
.filename(data_dir.join("taker.sqlite")), |
|
|
|
|
|
) |
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
rocket::custom(figment) |
|
|
rocket::custom(figment) |
|
|
.manage(order_feed_receiver) |
|
|
.manage(order_feed_receiver) |
|
|
.manage(wallet_feed_receiver) |
|
|
.manage(wallet_feed_receiver) |
|
|
.manage(update_feed_receiver) |
|
|
.manage(update_feed_receiver) |
|
|
.manage(quote_updates) |
|
|
.manage(quote_updates) |
|
|
.manage(bitcoin_network) |
|
|
.manage(bitcoin_network) |
|
|
.attach(Db::init()) |
|
|
.attach(AdHoc::try_on_ignite("SQL migrations", { |
|
|
.attach(AdHoc::try_on_ignite( |
|
|
let db = db.clone(); |
|
|
"SQL migrations", |
|
|
|
|
|
|rocket| async move { |
|
|
move |rocket| async move { |
|
|
match Db::fetch(&rocket) { |
|
|
match db::run_migrations(&db).await { |
|
|
Some(db) => match db::run_migrations(&**db).await { |
|
|
|
|
|
Ok(_) => Ok(rocket), |
|
|
Ok(_) => Ok(rocket), |
|
|
Err(_) => Err(rocket), |
|
|
Err(_) => Err(rocket), |
|
|
}, |
|
|
|
|
|
None => Err(rocket), |
|
|
|
|
|
} |
|
|
} |
|
|
}, |
|
|
} |
|
|
)) |
|
|
})) |
|
|
.attach(AdHoc::try_on_ignite( |
|
|
.attach(AdHoc::try_on_ignite("Create actors", { |
|
|
"Create actors", |
|
|
let db = db.clone(); |
|
|
|
|
|
|
|
|
move |rocket| async move { |
|
|
move |rocket| async move { |
|
|
let db = match Db::fetch(&rocket) { |
|
|
|
|
|
Some(db) => (**db).clone(), |
|
|
|
|
|
None => return Err(rocket), |
|
|
|
|
|
}; |
|
|
|
|
|
let mut conn = db.acquire().await.unwrap(); |
|
|
let mut conn = db.acquire().await.unwrap(); |
|
|
|
|
|
|
|
|
housekeeping::transition_non_continue_cfds_to_setup_failed(&mut conn) |
|
|
housekeeping::transition_non_continue_cfds_to_setup_failed(&mut conn) |
|
@ -212,8 +209,6 @@ async fn main() -> Result<()> { |
|
|
let (monitor_actor_address, mut monitor_actor_context) = xtra::Context::new(None); |
|
|
let (monitor_actor_address, mut monitor_actor_context) = xtra::Context::new(None); |
|
|
let (oracle_actor_address, mut oracle_actor_context) = xtra::Context::new(None); |
|
|
let (oracle_actor_address, mut oracle_actor_context) = xtra::Context::new(None); |
|
|
|
|
|
|
|
|
let mut conn = db.acquire().await.unwrap(); |
|
|
|
|
|
let cfds = load_all_cfds(&mut conn).await.unwrap(); |
|
|
|
|
|
let cfd_actor_inbox = taker_cfd::Actor::new( |
|
|
let cfd_actor_inbox = taker_cfd::Actor::new( |
|
|
db.clone(), |
|
|
db.clone(), |
|
|
wallet.clone(), |
|
|
wallet.clone(), |
|
@ -273,8 +268,8 @@ async fn main() -> Result<()> { |
|
|
.manage(take_offer_channel) |
|
|
.manage(take_offer_channel) |
|
|
.manage(cfd_action_channel) |
|
|
.manage(cfd_action_channel) |
|
|
.manage(cfd_feed_receiver)) |
|
|
.manage(cfd_feed_receiver)) |
|
|
}, |
|
|
} |
|
|
)) |
|
|
})) |
|
|
.mount( |
|
|
.mount( |
|
|
"/api", |
|
|
"/api", |
|
|
rocket::routes![ |
|
|
rocket::routes![ |
|
@ -292,5 +287,7 @@ async fn main() -> Result<()> { |
|
|
.launch() |
|
|
.launch() |
|
|
.await?; |
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
db.close().await; |
|
|
|
|
|
|
|
|
Ok(()) |
|
|
Ok(()) |
|
|
} |
|
|
} |
|
|