summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 8f8ddf245cdf869d8422fce1e67a9ed590fec0b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{io, sync::Arc};

use bitcoin::{
    blocks::BlockChain,
    network::{Network, Request},
};
use tokio::sync::Mutex;

use crate::ui::Ui;

pub mod ui;

#[tokio::main]
async fn main() {
    let bc = Arc::new(Mutex::new(BlockChain::default()));
    let network = Network::new(bc).await;

    Network::start(network.clone());

    Network::broadcast(network.clone(), Request::Ibd(None)).await;

    let me = {
        let net = network
            .lock()
            .await;
        *net.get_me()
    };

    let mut ui = Ui::new(Arc::downgrade(&network), me);

    loop {
        let mut cmd = String::new();
        io::stdin()
            .read_line(&mut cmd)
            .unwrap();

        if let Some(req) = ui
            .cmd(&cmd)
            .await
        {
            Network::broadcast(network.clone(), req).await;
        }
    }
}