-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.rs
82 lines (74 loc) · 2.41 KB
/
main.rs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2024 [Kulpreet Singh]
//
// This file is part of P2Poolv2
//
// P2Poolv2 is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// P2Poolv2 is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// P2Poolv2. If not, see <https://www.gnu.org/licenses/>.
use crate::shares::ShareBlock;
use clap::Parser;
use std::error::Error;
use tracing::{debug, info};
use tracing_subscriber::EnvFilter;
mod bitcoind_rpc;
mod command;
mod config;
mod node;
mod shares;
mod utils;
#[mockall_double::double]
use crate::node::actor::NodeHandle;
#[mockall_double::double]
use crate::shares::chain::actor::ChainHandle;
use bitcoin::PublicKey;
use tracing::error;
#[cfg(test)]
mod test_utils;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
#[arg(short, long)]
config: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
// Parse command line arguments
let args = Args::parse();
debug!("Parsed args: {:?}", args);
// Load configuration
let config = config::Config::load(&args.config)?;
let chain_handle = ChainHandle::new(config.store.path.clone());
let public_key = "02ac493f2130ca56cb5c3a559860cef9a84f90b5a85dfe4ec6e6067eeee17f4d2d"
.parse::<PublicKey>()
.unwrap();
let genesis = ShareBlock::build_genesis_for_network(public_key, config.bitcoin.network);
if chain_handle
.get_share(genesis.cached_blockhash.unwrap())
.await
.is_none()
{
if let Err(e) = chain_handle.add_share(genesis).await {
error!("Failed to create genesis block: {}", e);
std::process::exit(1);
}
}
if let Ok((_node_handle, stopping_rx)) = NodeHandle::new(config, chain_handle).await {
info!("Node started");
stopping_rx.await?;
info!("Node stopped");
} else {
error!("Failed to start node");
}
Ok(())
}