Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/floresta-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ use clap::Subcommand;
use floresta_cli::reqwest_client::ReqwestClient;
use floresta_cli::rpc::FlorestaRPC;

mod reqwest_client;
mod rpc;
mod rpc_types;

fn main() -> anyhow::Result<()> {
let cli = Cli::parse();

Expand Down
12 changes: 12 additions & 0 deletions florestad/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::command;
use clap::Parser;
use clap::Subcommand;
use clap::ValueEnum;
use florestad::Network as FlorestaNetwork;

#[derive(Clone, Debug, ValueEnum, Default)]
pub enum Network {
Expand All @@ -13,6 +14,17 @@ pub enum Network {
Regtest,
}

impl From<Network> for FlorestaNetwork {
fn from(network: Network) -> Self {
match network {
Network::Bitcoin => FlorestaNetwork::Bitcoin,
Network::Signet => FlorestaNetwork::Signet,
Network::Testnet => FlorestaNetwork::Testnet,
Network::Regtest => FlorestaNetwork::Regtest,
}
}
}

impl From<Network> for floresta_chain::Network {
fn from(network: Network) -> Self {
match network {
Expand Down
49 changes: 26 additions & 23 deletions florestad/src/florestad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ use log::debug;
use log::error;
use log::info;
use log::Record;
#[cfg(feature = "zmq-server")]
use zmq::ZMQServer;

use crate::cli;
use crate::config_file::ConfigFile;
#[cfg(feature = "json-rpc")]
use crate::json_rpc;
use crate::wallet_input::InitialWalletSetup;
#[cfg(feature = "zmq-server")]
use crate::zmq::ZMQServer;

#[derive(Default, Clone)]
/// General configuration for the floresta daemon.
Expand Down Expand Up @@ -100,7 +99,7 @@ pub struct Config {
/// will be made through this one, except dns seed connections.
pub proxy: Option<String>,
/// The network we are running in, it may be one of: bitcoin, signet, regtest or testnet.
pub network: cli::Network,
pub network: crate::Network,
/// Whther we should build and store compact block filters
///
/// Those filters are used for rescanning our wallet for historical transactions. If you don't
Expand Down Expand Up @@ -201,10 +200,10 @@ impl Florestad {
.unwrap_or("floresta".into());

let data_dir = match self.config.network {
cli::Network::Bitcoin => data_dir,
cli::Network::Signet => data_dir + "/signet/",
cli::Network::Testnet => data_dir + "/testnet3/",
cli::Network::Regtest => data_dir + "/regtest/",
crate::Network::Bitcoin => data_dir,
crate::Network::Signet => data_dir + "/signet/",
crate::Network::Testnet => data_dir + "/testnet3/",
crate::Network::Regtest => data_dir + "/regtest/",
};

// create the data directory if it doesn't exist
Expand Down Expand Up @@ -245,7 +244,7 @@ impl Florestad {
),
Self::get_both_vec(config_file.wallet.addresses.clone(), None),
&mut wallet,
self.config.network.clone(),
self.config.network,
);

if let Err(e) = result {
Expand Down Expand Up @@ -301,16 +300,16 @@ impl Florestad {

// For now we only have compatible bridges on signet
let pow_fraud_proofs = match self.config.network {
cli::Network::Bitcoin => false,
cli::Network::Signet => true,
cli::Network::Testnet => false,
cli::Network::Regtest => false,
crate::Network::Bitcoin => false,
crate::Network::Signet => true,
crate::Network::Testnet => false,
crate::Network::Regtest => false,
};

// If this network already allows pow fraud proofs, we should use it instead of assumeutreexo
let assume_utreexo = match (pow_fraud_proofs, self.config.assume_utreexo) {
(false, true) => Some(floresta_chain::ChainParams::get_assumeutreexo_value(
self.config.network.clone().into(),
Self::get_net(&self.config.network).into(),
)),
_ => None,
};
Expand Down Expand Up @@ -345,9 +344,13 @@ impl Florestad {
#[cfg(feature = "zmq-server")]
{
info!("Starting ZMQ server");
if let Ok(zserver) =
ZMQServer::new(&ctx.zmq_address.unwrap_or("tcp://127.0.0.1:5150".into()))
{
if let Ok(zserver) = ZMQServer::new(
&self
.config
.zmq_address
.as_ref()
.unwrap_or(&"tcp://127.0.0.1:5150".to_string()),
) {
blockchain_state.subscribe(Arc::new(zserver));
info!("Done!");
} else {
Expand Down Expand Up @@ -549,12 +552,12 @@ impl Florestad {
AddressCache::new(database)
}

fn get_net(net: &cli::Network) -> bitcoin::Network {
fn get_net(net: &crate::Network) -> bitcoin::Network {
match net {
cli::Network::Bitcoin => bitcoin::Network::Bitcoin,
cli::Network::Signet => bitcoin::Network::Signet,
cli::Network::Testnet => bitcoin::Network::Testnet,
cli::Network::Regtest => bitcoin::Network::Regtest,
crate::Network::Bitcoin => bitcoin::Network::Bitcoin,
crate::Network::Signet => bitcoin::Network::Signet,
crate::Network::Testnet => bitcoin::Network::Testnet,
crate::Network::Regtest => bitcoin::Network::Regtest,
}
}

Expand All @@ -563,7 +566,7 @@ impl Florestad {
descriptors: Vec<String>,
addresses: Vec<String>,
wallet: &mut AddressCache<D>,
network: cli::Network,
network: crate::Network,
) -> anyhow::Result<()> {
if let Some(key) = Self::get_key_from_env() {
xpubs.push(key);
Expand Down
2 changes: 1 addition & 1 deletion florestad/src/json_rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ impl Rpc for RpcImpl {
.get_block_hash(height + 1)
.ok()
.map(|h| h.to_string()),
#[allow(deprecated)]
strippedsize: block.strippedsize(),
};

return Ok(serde_json::to_value(block).unwrap());
}
return Ok(json!(serialize(&block).to_vec()));
Expand Down
21 changes: 19 additions & 2 deletions florestad/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
mod cli;
mod config_file;
mod error;
mod florestad;
#[cfg(feature = "json-rpc")]
mod json_rpc;
mod slip132;
mod wallet_input;
#[cfg(feature = "zmq-server")]
mod zmq;

#[derive(Debug, Default, Clone, Copy)]
/// Which network should we use
///
/// Use this to select one of the supported networks. They are either Bitcoin mainnet or some form
/// of test network, like testnet or regtest. The default is Bitcoin mainnet.
pub enum Network {
#[default]
/// Mainnet (default)
Bitcoin,
/// Testnet 3
Testnet,
/// Signet
Signet,
/// Regtest
Regtest,
}

pub use cli::Network;
pub use florestad::Config;
pub use florestad::Florestad;
15 changes: 2 additions & 13 deletions florestad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
#![deny(non_upper_case_globals)]

mod cli;
mod config_file;
mod error;
mod florestad;
#[cfg(feature = "json-rpc")]
mod json_rpc;
mod slip132;
mod wallet_input;
#[cfg(feature = "zmq-server")]
mod zmq;

use std::time::Duration;

Expand All @@ -35,8 +26,6 @@ use cli::Cli;
use cli::Commands;
use florestad::Config;
use florestad::Florestad;
#[cfg(feature = "zmq-server")]
use zmq::ZMQServer;

#[async_std::main]
async fn main() {
Expand Down Expand Up @@ -65,7 +54,7 @@ async fn main() {
rescan,
proxy,
config_file: params.config_file,
network: params.network,
network: params.network.into(),
cfilters,
#[cfg(feature = "zmq-server")]
zmq_address: _zmq_address,
Expand All @@ -82,7 +71,7 @@ async fn main() {
None => Config {
debug: params.debug,
config_file: params.config_file,
network: params.network,
network: params.network.into(),
cfilters: true,
log_to_file: false,
log_to_stdout: true,
Expand Down