blob: 162f8ded31301fa56b953d4b7ed9899b4e86b2eb (
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
45
46
47
48
49
50
51
52
53
|
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;
{
let net = network
.lock()
.await;
net.start();
}
Network::broadcast(network.clone(), Request::Ibd(None)).await;
let (blockchain, me) = {
let net = network
.lock()
.await;
(
net.get_blockchain()
.clone(),
*net.get_me(),
)
};
let mut ui = Ui::new(blockchain, 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;
}
}
}
|