use super::*;
use serde_json::json;
#[derive(Parser, Debug)]
#[group(id = "advance_args")]
pub struct Advance {
#[clap(help = "The number of blocks to advance the ledger by", default_value = "1")]
pub num_blocks: u32,
#[clap(long, help = "devnode REST API server address", default_value = "127.0.0.1:3030")]
pub(crate) socket_addr: String,
}
impl Command for Advance {
type Input = ();
type Output = ();
fn log_span(&self) -> Span {
tracing::span!(tracing::Level::INFO, "Leo")
}
fn prelude(&self, _context: Context) -> Result<Self::Input> {
Ok(())
}
fn apply(self, _context: Context, _: Self::Input) -> Result<Self::Output> {
tracing::info!("Advancing the Devnode ledger by {} block(s)", self.num_blocks);
let client = reqwest::blocking::Client::new();
let payload = json!({
"num_blocks": self.num_blocks,
});
let _response = client
.post(format!("http://{}/testnet/block/create", self.socket_addr))
.header("Content-Type", "application/json")
.json(&payload)
.send();
Ok(())
}
}