mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Re-use bitcoin
crate Network definitions
This commit is contained in:
parent
bb4c7a667d
commit
f62601bae3
@ -1,3 +1,4 @@
|
||||
use bitcoin::network::constants::Network;
|
||||
use clap::{App, Arg};
|
||||
use dirs::home_dir;
|
||||
use std::fs;
|
||||
@ -6,7 +7,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use stderrlog;
|
||||
|
||||
use daemon::{CookieGetter, Network};
|
||||
use daemon::CookieGetter;
|
||||
|
||||
use errors::*;
|
||||
|
||||
@ -96,7 +97,7 @@ impl Config {
|
||||
|
||||
let network_name = m.value_of("network").unwrap_or("mainnet");
|
||||
let network_type = match network_name {
|
||||
"mainnet" => Network::Mainnet,
|
||||
"mainnet" => Network::Bitcoin,
|
||||
"testnet" => Network::Testnet,
|
||||
"regtest" => Network::Regtest,
|
||||
_ => panic!("unsupported Bitcoin network: {:?}", network_name),
|
||||
@ -105,17 +106,17 @@ impl Config {
|
||||
let db_path = db_dir.join(network_name);
|
||||
|
||||
let default_daemon_port = match network_type {
|
||||
Network::Mainnet => 8332,
|
||||
Network::Bitcoin => 8332,
|
||||
Network::Testnet => 18332,
|
||||
Network::Regtest => 18443,
|
||||
};
|
||||
let default_electrum_port = match network_type {
|
||||
Network::Mainnet => 50001,
|
||||
Network::Bitcoin => 50001,
|
||||
Network::Testnet => 60001,
|
||||
Network::Regtest => 60401,
|
||||
};
|
||||
let default_monitoring_port = match network_type {
|
||||
Network::Mainnet => 4224,
|
||||
Network::Bitcoin => 4224,
|
||||
Network::Testnet => 14224,
|
||||
Network::Regtest => 24224,
|
||||
};
|
||||
@ -145,7 +146,7 @@ impl Config {
|
||||
default_dir
|
||||
});
|
||||
match network_type {
|
||||
Network::Mainnet => (),
|
||||
Network::Bitcoin => (),
|
||||
Network::Testnet => daemon_dir.push("testnet3"),
|
||||
Network::Regtest => daemon_dir.push("regtest"),
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use base64;
|
||||
use bitcoin::blockdata::block::{Block, BlockHeader};
|
||||
use bitcoin::blockdata::transaction::Transaction;
|
||||
use bitcoin::network::constants::Network;
|
||||
use bitcoin::network::serialize::BitcoinHash;
|
||||
use bitcoin::network::serialize::{deserialize, serialize};
|
||||
use bitcoin::util::hash::Sha256dHash;
|
||||
@ -20,13 +21,6 @@ use util::HeaderList;
|
||||
|
||||
use errors::*;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum Network {
|
||||
Mainnet,
|
||||
Testnet,
|
||||
Regtest,
|
||||
}
|
||||
|
||||
fn parse_hash(value: &Value) -> Result<Sha256dHash> {
|
||||
Ok(Sha256dHash::from_hex(
|
||||
value
|
||||
@ -345,11 +339,7 @@ impl Daemon {
|
||||
}
|
||||
|
||||
pub fn magic(&self) -> u32 {
|
||||
match self.network {
|
||||
Network::Mainnet => 0xD9B4BEF9,
|
||||
Network::Testnet => 0x0709110B,
|
||||
Network::Regtest => 0xDAB5BFFA,
|
||||
}
|
||||
self.network.magic()
|
||||
}
|
||||
|
||||
fn call_jsonrpc(&self, method: &str, request: &Value) -> Result<Value> {
|
||||
|
Loading…
Reference in New Issue
Block a user