diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-10-21 22:23:52 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-10-21 22:48:29 +0800 |
| commit | db71798db2ba7ede27f2ad7f2428cffbf8f1e98c (patch) | |
| tree | e6e2895b6f6d59dff5759ae6f54144e5328411ec /src/ui.rs | |
| parent | a2d6e450fd488cb737474f0ff9810c2d1f9108cf (diff) | |
feat: peer cmd
refactor: Ui now takes network
Diffstat (limited to 'src/ui.rs')
| -rw-r--r-- | src/ui.rs | 41 |
1 files changed, 34 insertions, 7 deletions
@@ -1,17 +1,22 @@ -use std::sync::Arc; +use std::sync::{Arc, Weak}; -use bitcoin::{blocks::BlockChain, client::Client, network::Request, transaction::Transaction}; +use bitcoin::{ + blocks::BlockChain, + client::Client, + network::{Network, Request}, + transaction::Transaction, +}; use tokio::sync::Mutex; pub struct Ui { - blockchain: Arc<Mutex<BlockChain>>, + network: Weak<Mutex<Network>>, me: Client, } impl Ui { - pub fn new(blockchain: Arc<Mutex<BlockChain>>, me: Client) -> Self { + pub fn new(network: Weak<Mutex<Network>>, me: Client) -> Self { Self { - blockchain, + network, me, } } @@ -34,7 +39,12 @@ impl Ui { .unwrap(), ); return Some(Request::Block( - self.blockchain + self.network + .upgrade() + .unwrap() + .lock() + .await + .get_blockchain() .lock() .await .new_block(trans), @@ -44,11 +54,28 @@ impl Ui { if cmd[0] == "bc" { println!( "{:#?}", - self.blockchain + self.network + .upgrade() + .unwrap() + .lock() + .await + .get_blockchain() .lock() .await ); } + + if cmd[0] == "peer" { + if cmd[1] == "add" { + Network::try_peer( + self.network + .clone(), + cmd[2], + ) + .await; + } + } + None } } |
