summaryrefslogtreecommitdiff
path: root/src/ui.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-10-21 09:56:21 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-10-21 09:56:28 +0800
commitf754675aac96ac04599ec79d609e2c5b08be4561 (patch)
treea92a2e4b910593d3593744dd99bae0ba28a44c37 /src/ui.rs
parentb71fae628d97ada84c533ce746d4d7980a9f6d73 (diff)
feat: ui
Diffstat (limited to 'src/ui.rs')
-rw-r--r--src/ui.rs52
1 files changed, 52 insertions, 0 deletions
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<Mutex<BlockChain>>,
+ me: &'a Client,
+}
+
+impl<'a> Ui<'a> {
+ pub fn new(network_config: &'a mut NetworkConfig, blockchain: Arc<Mutex<BlockChain>>, me: &'a Client) -> Self {
+ Self {
+ network_config,
+ blockchain,
+ me,
+ }
+ }
+
+ // TODO: typed command and result propagation
+ pub async fn cmd(&mut self, cmd: &str) -> Option<Request> {
+ 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
+ }
+}