From f754675aac96ac04599ec79d609e2c5b08be4561 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 21 Oct 2025 09:56:21 +0800 Subject: feat: ui --- src/ui.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/ui.rs (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs new file mode 100644 index 0000000..c820422 --- /dev/null +++ b/src/ui.rs @@ -0,0 +1,52 @@ +use std::sync::{Arc, Weak}; + +use bitcoin::{ + blocks::{Block, BlockChain}, + client::Client, + network::{Network, NetworkConfig, Request}, + transaction::Transaction, +}; +use tokio::sync::Mutex; + +pub struct Ui<'a> { + network_config: &'a mut NetworkConfig, + blockchain: Arc>, + me: &'a Client, +} + +impl<'a> Ui<'a> { + pub fn new(network_config: &'a mut NetworkConfig, blockchain: Arc>, me: &'a Client) -> Self { + Self { + network_config, + blockchain, + me, + } + } + + // TODO: typed command and result propagation + pub async fn cmd(&mut self, cmd: &str) -> Option { + let cmd: Vec<&str> = cmd + .split_whitespace() + .collect(); + if cmd[0] == "trans" { + let trans = Transaction::new( + *self.me, + Client::new( + cmd[1] + .parse() + .unwrap(), + ), + cmd[2] + .parse() + .unwrap(), + ); + return Some(Request::Block( + self.blockchain + .lock() + .await + .new_block(trans), + )); + } + None + } +} -- cgit v1.2.3