From 8309c85e303ece0110ed1f84a5748ecc82f25566 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Sat, 30 Jul 2022 12:49:26 +0200 Subject: [PATCH] commands: a module for the implementation of the API --- src/commands/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 38 insertions(+) create mode 100644 src/commands/mod.rs diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 00000000..584590d6 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,37 @@ +//! # Minisafe commands +//! +//! External interface to the Minisafe daemon. + +use crate::{DaemonControl, VERSION}; + +use miniscript::{bitcoin, descriptor}; + +impl DaemonControl { + /// Get information about the current state of the daemon + pub fn get_info(&self) -> GetInfoResult { + GetInfoResult { + version: VERSION.to_string(), + network: self.config.bitcoind_config.network, + blockheight: self.bitcoin.chain_tip().height, + sync: self.bitcoin.sync_progress(), + descriptors: GetInfoDescriptors { + main: self.config.main_descriptor.clone(), + }, + } + } +} + +#[derive(Debug, Clone)] +pub struct GetInfoDescriptors { + pub main: descriptor::Descriptor, +} + +/// Information about the daemon +#[derive(Debug, Clone)] +pub struct GetInfoResult { + pub version: String, + pub network: bitcoin::Network, + pub blockheight: i32, + pub sync: f64, + pub descriptors: GetInfoDescriptors, +} diff --git a/src/lib.rs b/src/lib.rs index 45215298..526cc377 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ mod bitcoin; +mod commands; pub mod config; #[cfg(unix)] mod daemonize;