1
0
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:
Roman Zeyde 2018-08-29 21:53:01 +03:00
parent bb4c7a667d
commit f62601bae3
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 9 additions and 18 deletions

View File

@ -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"),
}

View File

@ -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> {