forked from bitcoinafterlife/bal-server
formatting code
This commit is contained in:
@@ -71,7 +71,7 @@ struct MyConfig {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct InfoResponse{
|
||||
pub struct InfoResponse {
|
||||
pub address: String,
|
||||
pub base_fee: u64,
|
||||
pub chain: String,
|
||||
@@ -82,14 +82,14 @@ pub struct InfoResponse{
|
||||
pub struct StatsResponse {
|
||||
pub report_date: String,
|
||||
pub chain: String,
|
||||
pub totals:i64,
|
||||
pub waiting:i64,
|
||||
pub sent:i64,
|
||||
pub failed:i64,
|
||||
pub waiting_profit:i64,
|
||||
pub sent_profit:i64,
|
||||
pub missed_profit:i64,
|
||||
pub unique_inputs:i64,
|
||||
pub totals: i64,
|
||||
pub waiting: i64,
|
||||
pub sent: i64,
|
||||
pub failed: i64,
|
||||
pub waiting_profit: i64,
|
||||
pub sent_profit: i64,
|
||||
pub missed_profit: i64,
|
||||
pub unique_inputs: i64,
|
||||
}
|
||||
|
||||
impl Default for MyConfig {
|
||||
@@ -104,7 +104,10 @@ impl Default for MyConfig {
|
||||
db_file: "bal.db".to_string(),
|
||||
info: "Will Executor Server".to_string(),
|
||||
pub_key_path: "public_key.pem".to_string(),
|
||||
expose_stats:env::var("BAL_SERVER_EXPOSE_STATS").unwrap_or("false".to_string()).parse::<bool>().unwrap(),
|
||||
expose_stats: env::var("BAL_SERVER_EXPOSE_STATS")
|
||||
.unwrap_or("false".to_string())
|
||||
.parse::<bool>()
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,15 +139,15 @@ async fn echo_pub_key(
|
||||
async fn echo_stats(
|
||||
param: &str,
|
||||
cfg: &MyConfig,
|
||||
remote_addr: &String,
|
||||
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
|
||||
info!("echo stats!!! {} - {}", param,cfg.expose_stats);
|
||||
info!("echo stats!!! {} - {}", param, cfg.expose_stats);
|
||||
let netconfig = MyConfig::get_net_config(cfg, param);
|
||||
if !netconfig.enabled {
|
||||
debug!("network disabled {}", param);
|
||||
return Ok(Response::new(full("network disabled")));
|
||||
}
|
||||
let sql = format!("SELECT
|
||||
let sql = format!(
|
||||
"SELECT
|
||||
report_date,
|
||||
chain,
|
||||
totals,
|
||||
@@ -155,26 +158,43 @@ async fn echo_stats(
|
||||
sent_profit,
|
||||
missed_profit,
|
||||
unique_inputs FROM tbl_stats where chain = '{}'
|
||||
", netconfig.name);
|
||||
let mut stats:Vec<StatsResponse>=vec![];
|
||||
",
|
||||
netconfig.name
|
||||
);
|
||||
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();
|
||||
let _ = db.iterate(&sql, |pairs| {
|
||||
let row: HashMap<_, _> = pairs
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k.to_string(), v.map(|s| s)))
|
||||
.collect();
|
||||
//let row:HashMap<_,_>= pairs.into_iter().collect();
|
||||
println!("row report date {}",row["report_date"].clone().unwrap());
|
||||
|
||||
println!("row report date {}", row["report_date"].clone().unwrap());
|
||||
|
||||
dbg!(&row);
|
||||
stats.push(StatsResponse{
|
||||
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(),
|
||||
waiting: row["waiting"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
sent: row["sent"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
failed: row["failed"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
waiting_profit: row["waiting_profit"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
waiting_profit: row["waiting_profit"]
|
||||
.clone()
|
||||
.unwrap()
|
||||
.parse::<i64>()
|
||||
.unwrap(),
|
||||
sent_profit: row["sent_profit"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
missed_profit:row["missed_profit"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
unique_inputs: row["unique_inputs"].clone().unwrap().parse::<i64>().unwrap(),
|
||||
missed_profit: row["missed_profit"]
|
||||
.clone()
|
||||
.unwrap()
|
||||
.parse::<i64>()
|
||||
.unwrap(),
|
||||
unique_inputs: row["unique_inputs"]
|
||||
.clone()
|
||||
.unwrap()
|
||||
.parse::<i64>()
|
||||
.unwrap(),
|
||||
});
|
||||
true
|
||||
});
|
||||
@@ -185,8 +205,7 @@ async fn echo_stats(
|
||||
}
|
||||
Err(err) => Ok(Response::new(full(format!("error:{}", err)))),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async fn echo_info(
|
||||
param: &str,
|
||||
@@ -332,7 +351,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);
|
||||
trace!("network not enabled {}", &netconfig.name);
|
||||
return Ok(response_not_enable);
|
||||
}
|
||||
let req_time = Utc::now().timestamp_nanos_opt().unwrap(); // Returns i64
|
||||
@@ -438,7 +457,7 @@ async fn echo_push(
|
||||
}
|
||||
if address == our_address && amount.to_sat() >= netconfig.fixed_fee {
|
||||
our_fees = amount.to_sat();
|
||||
our_address = netconfig.address.to_string();
|
||||
//our_address = netconfig.address.to_string();
|
||||
found = true;
|
||||
trace!("address and fees are correct {}: {}", our_address, our_fees);
|
||||
}
|
||||
@@ -541,7 +560,7 @@ async fn echo(
|
||||
}
|
||||
Method::GET => {
|
||||
if let Some(param) = match_uri(r"^?/?(?P<param>[^/]?+)?/stats$", uri.as_str()) {
|
||||
ret = echo_stats(param, cfg, &remote_addr).await;
|
||||
ret = echo_stats(param, cfg).await;
|
||||
}
|
||||
if let Some(param) = match_uri(r"^?/?(?P<param>[^/]?+)?/info$", uri.as_str()) {
|
||||
ret = echo_info(param, cfg, &remote_addr).await;
|
||||
|
||||
Reference in New Issue
Block a user