mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-23 03:03:18 +00:00
created webserver
This commit is contained in:
@ -8,3 +8,4 @@ axum = "0.7.5"
|
|||||||
bdk = "0.29.0"
|
bdk = "0.29.0"
|
||||||
clap = { version = "4.5.4", features = ["derive", "cargo"] }
|
clap = { version = "4.5.4", features = ["derive", "cargo"] }
|
||||||
frost-secp256k1 = "1.0.0"
|
frost-secp256k1 = "1.0.0"
|
||||||
|
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
|
@ -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 {
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
"Hello, world!"
|
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<OrderRequest>) {
|
||||||
|
// 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]
|
#[tokio::main]
|
||||||
pub fn webserver() -> Rocket<build> {
|
pub async fn webserver() {
|
||||||
rocket::build().mount("/", routes![index])
|
// 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
|
// // use axum
|
||||||
// https://github.com/tokio-rs/axum
|
|
||||||
|
// #[get("/")]
|
||||||
|
// fn index() -> &'static str {
|
||||||
|
// "Hello, world!"
|
||||||
|
// }
|
||||||
|
|
||||||
|
// #[launch]
|
||||||
|
// pub fn webserver() -> Rocket<build> {
|
||||||
|
// 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
|
@ -13,3 +13,4 @@ pub struct OrderRequest {
|
|||||||
pub order_type: String, // buy or sell
|
pub order_type: String, // buy or sell
|
||||||
pub bond_ratio: u8 // [2, 50]
|
pub bond_ratio: u8 // [2, 50]
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user