mirror of
https://github.com/romanz/electrs.git
synced 2024-11-19 09:54:09 +01:00
Merge branch 'regtest_mode'
This commit is contained in:
commit
2a3678e392
@ -64,20 +64,21 @@ impl Config {
|
|||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("testnet")
|
Arg::with_name("network")
|
||||||
.long("testnet")
|
.long("network")
|
||||||
.help("Connect to a testnet bitcoind instance"),
|
.help("Select Bitcoin network type ('mainnet', 'testnet' or 'regtest')")
|
||||||
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("electrum_rpc_addr")
|
Arg::with_name("electrum_rpc_addr")
|
||||||
.long("electrum-rpc-addr")
|
.long("electrum-rpc-addr")
|
||||||
.help("Electrum server JSONRPC 'addr:port' to listen on (default: '127.0.0.1:50001' for mainnet and '127.0.0.1:60001' for testnet)")
|
.help("Electrum server JSONRPC 'addr:port' to listen on (default: '127.0.0.1:50001' for mainnet, '127.0.0.1:60001' for testnet and '127.0.0.1:60401' for regtest)")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("daemon_rpc_addr")
|
Arg::with_name("daemon_rpc_addr")
|
||||||
.long("daemon-rpc-addr")
|
.long("daemon-rpc-addr")
|
||||||
.help("Bitcoin daemon JSONRPC 'addr:port' to connect (default: 127.0.0.1:8332 for mainnet and 127.0.0.1:18332 for testnet)")
|
.help("Bitcoin daemon JSONRPC 'addr:port' to connect (default: 127.0.0.1:8332 for mainnet, 127.0.0.1:18332 for testnet and 127.0.0.1:18443 for regtest)")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@ -88,22 +89,25 @@ impl Config {
|
|||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
|
let network_name = m.value_of("network").unwrap_or("mainnet");
|
||||||
|
let network_type = match network_name {
|
||||||
|
"mainnet" => Network::Mainnet,
|
||||||
|
"testnet" => Network::Testnet,
|
||||||
|
"regtest" => Network::Regtest,
|
||||||
|
_ => panic!("unsupported Bitcoin network: {:?}", network_name),
|
||||||
|
};
|
||||||
let db_dir = Path::new(m.value_of("db_dir").unwrap_or("./db"));
|
let db_dir = Path::new(m.value_of("db_dir").unwrap_or("./db"));
|
||||||
let network_type = match m.is_present("testnet") {
|
let db_path = db_dir.join(network_name);
|
||||||
false => Network::Mainnet,
|
|
||||||
true => Network::Testnet,
|
|
||||||
};
|
|
||||||
let db_path = match network_type {
|
|
||||||
Network::Mainnet => db_dir.join("mainnet"),
|
|
||||||
Network::Testnet => db_dir.join("testnet"),
|
|
||||||
};
|
|
||||||
let default_daemon_port = match network_type {
|
let default_daemon_port = match network_type {
|
||||||
Network::Mainnet => 8332,
|
Network::Mainnet => 8332,
|
||||||
Network::Testnet => 18332,
|
Network::Testnet => 18332,
|
||||||
|
Network::Regtest => 18443,
|
||||||
};
|
};
|
||||||
let default_electrum_port = match network_type {
|
let default_electrum_port = match network_type {
|
||||||
Network::Mainnet => 50001,
|
Network::Mainnet => 50001,
|
||||||
Network::Testnet => 60001,
|
Network::Testnet => 60001,
|
||||||
|
Network::Regtest => 60401,
|
||||||
};
|
};
|
||||||
|
|
||||||
let daemon_rpc_addr: SocketAddr = m.value_of("daemon_rpc_addr")
|
let daemon_rpc_addr: SocketAddr = m.value_of("daemon_rpc_addr")
|
||||||
@ -126,8 +130,10 @@ impl Config {
|
|||||||
default_dir.push(".bitcoin");
|
default_dir.push(".bitcoin");
|
||||||
default_dir
|
default_dir
|
||||||
});
|
});
|
||||||
if let Network::Testnet = network_type {
|
match network_type {
|
||||||
daemon_dir.push("testnet3");
|
Network::Mainnet => (),
|
||||||
|
Network::Testnet => daemon_dir.push("testnet3"),
|
||||||
|
Network::Regtest => daemon_dir.push("regtest"),
|
||||||
}
|
}
|
||||||
let cookie = m.value_of("cookie")
|
let cookie = m.value_of("cookie")
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
|
@ -22,6 +22,7 @@ use errors::*;
|
|||||||
pub enum Network {
|
pub enum Network {
|
||||||
Mainnet,
|
Mainnet,
|
||||||
Testnet,
|
Testnet,
|
||||||
|
Regtest,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_hash(value: &Value) -> Result<Sha256dHash> {
|
fn parse_hash(value: &Value) -> Result<Sha256dHash> {
|
||||||
@ -242,6 +243,7 @@ impl Daemon {
|
|||||||
match self.network {
|
match self.network {
|
||||||
Network::Mainnet => 0xD9B4BEF9,
|
Network::Mainnet => 0xD9B4BEF9,
|
||||||
Network::Testnet => 0x0709110B,
|
Network::Testnet => 0x0709110B,
|
||||||
|
Network::Regtest => 0xDAB5BFFA,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user