This commit is contained in:
2026-01-29 13:36:06 -04:00
parent dcaab2ed6d
commit 8e322ca441
2 changed files with 126 additions and 5 deletions

View File

@@ -71,7 +71,7 @@ struct MyConfig {
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Info {
pub struct InfoResponse{
pub address: String,
pub base_fee: u64,
pub chain: String,
@@ -79,7 +79,7 @@ pub struct Info {
pub version: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Stats {
pub struct StatsResponse {
pub report_date: String,
pub chain: String,
pub totals:i64,
@@ -156,7 +156,7 @@ async fn echo_stats(
missed_profit,
unique_inputs FROM tbl_stats where chain = '{}'
", netconfig.name);
let mut stats:Vec<Stats>=vec![];
let mut stats:Vec<StatsResponse>=vec![];
let db = sqlite::open(&cfg.db_file).unwrap();
db.iterate(&sql,|pairs|{
let row: HashMap<_, _> = pairs.into_iter().map(|(k,v)| (k.to_string(), v.map(|s| s))).collect();
@@ -164,7 +164,7 @@ async fn echo_stats(
println!("row report date {}",row["report_date"].clone().unwrap());
dbg!(&row);
stats.push(Stats{
stats.push(StatsResponse{
report_date: row["report_date"].clone().unwrap().to_string(),
chain: row["chain"].clone().unwrap().to_string(),
totals: row["totals"].clone().unwrap().parse::<i64>().unwrap(),
@@ -227,7 +227,7 @@ async fn echo_info(
}
}
};
let info = Info {
let info = InfoResponse {
address,
base_fee: netconfig.fixed_fee,
chain: netconfig.network.to_string(),
@@ -324,6 +324,7 @@ async fn echo_push(
param: &str,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
//let whole_body = req.collect().await?.to_bytes();
trace!("echo_push");
let strbody = std::str::from_utf8(whole_body).unwrap();
let mut response = Response::new(full("Bad data received".to_owned()));
let mut response_not_enable = Response::new(full("Network not enabled".to_owned()));
@@ -331,6 +332,7 @@ async fn echo_push(
*response_not_enable.status_mut() = StatusCode::BAD_REQUEST;
let netconfig = MyConfig::get_net_config(cfg, param);
if !netconfig.enabled {
trace!("network not enabled {}",&netconfig.name);
return Ok(response_not_enable);
}
let req_time = Utc::now().timestamp_nanos_opt().unwrap(); // Returns i64