diff --git a/taptrade-cli-demo/coordinator/Cargo.toml b/taptrade-cli-demo/coordinator/Cargo.toml index 389c68d..6e306f8 100644 --- a/taptrade-cli-demo/coordinator/Cargo.toml +++ b/taptrade-cli-demo/coordinator/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" axum = "0.7.5" bdk = "0.29.0" clap = { version = "4.5.4", features = ["derive", "cargo"] } -frost-secp256k1 = "1.0.0" \ No newline at end of file +frost-secp256k1 = "1.0.0" +reqwest = { version = "0.12.4", features = ["blocking", "json"] } \ No newline at end of file diff --git a/taptrade-cli-demo/coordinator/src/communication/mod.rs b/taptrade-cli-demo/coordinator/src/communication/mod.rs index f4e907c..9d5fb2a 100755 --- a/taptrade-cli-demo/coordinator/src/communication/mod.rs +++ b/taptrade-cli-demo/coordinator/src/communication/mod.rs @@ -1,15 +1,77 @@ -// use axum +use axum::{ + routing::post, + Json, Router, +}; +use serde::{Deserialize, Serialize}; +use std::net::SocketAddr; +use tokio::net::TcpListener; -#[get("/")] -fn index() -> &'static str { - "Hello, world!" + +#[derive(Deserialize, Serialize, Debug)] +struct OrderRequest { + robohash_base91: String, + amount_satoshi: u64, + order_type: String, + bond_ratio: f64, +} +// Handler function to process the received data +async fn receive_order(Json(order): Json) { + // Print the received data to the console + println!("Received order: {:?}", order); + + // Access individual fields + let robohash = &order.robohash_base91; + let amount = order.amount_satoshi; + let order_type = &order.order_type; + let bond_ratio = order.bond_ratio; + + // Process the data as needed + // For example, you can log the data, save it to a database, etc. + println!("Robohash: {}", robohash); + println!("Amount (satoshi): {}", amount); + println!("Order type: {}", order_type); + println!("Bond ratio: {}", bond_ratio); + + // Example of further processing + if order_type == "buy" { + println!("Processing a buy order..."); + // Add your buy order logic here + } else if order_type == "sell" { + println!("Processing a sell order..."); + // Add your sell order logic here + } } -#[launch] -pub fn webserver() -> Rocket { - rocket::build().mount("/", routes![index]) +#[tokio::main] +pub async fn webserver() { + // Build our application with a single route + let app = Router::new().route("/receive-order", post(receive_order)); + + // Run the server on localhost:3000 + let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); + println!("Listening on {}", addr); + // axum::Server::bind(&addr) + // .serve(app.into_make_service()) + // .await + // .unwrap(); + let tcp = TcpListener::bind(&addr).await.unwrap(); + axum::serve(tcp, app).await.unwrap(); + } -// serde to parse json -// https://www.youtube.com/watch?v=md-ecvXBGzI BDK + Webserver video -// https://github.com/tokio-rs/axum \ No newline at end of file + +// // use axum + +// #[get("/")] +// fn index() -> &'static str { +// "Hello, world!" +// } + +// #[launch] +// pub fn webserver() -> Rocket { +// rocket::build().mount("/", routes![index]) +// } + +// // serde to parse json +// // https://www.youtube.com/watch?v=md-ecvXBGzI BDK + Webserver video +// // https://github.com/tokio-rs/axum \ No newline at end of file diff --git a/taptrade-cli-demo/trader/src/communication/api.rs b/taptrade-cli-demo/trader/src/communication/api.rs index 2fcd797..3c86662 100644 --- a/taptrade-cli-demo/trader/src/communication/api.rs +++ b/taptrade-cli-demo/trader/src/communication/api.rs @@ -13,3 +13,4 @@ pub struct OrderRequest { pub order_type: String, // buy or sell pub bond_ratio: u8 // [2, 50] } + \ No newline at end of file