mirror of
https://github.com/romanz/electrs.git
synced 2025-02-23 22:56:55 +01:00
Merge pull request #762 from Sosthene00/feature/custom_signet
WIP: Feature/custom signet
This commit is contained in:
commit
e6cdd62c3c
4 changed files with 20 additions and 2 deletions
|
@ -131,3 +131,8 @@ default = "concat!(\"Welcome to electrs \", env!(\"CARGO_PKG_VERSION\"), \" (Ele
|
|||
name = "log_filters"
|
||||
type = "String"
|
||||
doc = "Logging filters, overriding `RUST_LOG` environment variable (see https://docs.rs/env_logger/ for details)"
|
||||
|
||||
[[param]]
|
||||
name = "signet_magic"
|
||||
type = "u32"
|
||||
doc = "network magic for custom signet network (signet only)"
|
||||
|
|
|
@ -144,6 +144,7 @@ pub struct Config {
|
|||
pub sync_once: bool,
|
||||
pub disable_electrum_rpc: bool,
|
||||
pub server_banner: String,
|
||||
pub signet_magic: u32,
|
||||
pub args: Vec<String>,
|
||||
}
|
||||
|
||||
|
@ -231,6 +232,15 @@ impl Config {
|
|||
Network::Signet => 34224,
|
||||
};
|
||||
|
||||
let magic = match (config.network, config.signet_magic) {
|
||||
(Network::Signet, Some(magic)) => magic,
|
||||
(network, None) => network.magic(),
|
||||
(_, Some(_)) => {
|
||||
eprintln!("Error: signet magic only available on signet");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let daemon_rpc_addr: SocketAddr = config.daemon_rpc_addr.map_or(
|
||||
(DEFAULT_SERVER_ADDRESS, default_daemon_rpc_port).into(),
|
||||
ResolvAddr::resolve_or_exit,
|
||||
|
@ -323,6 +333,7 @@ impl Config {
|
|||
sync_once: config.sync_once,
|
||||
disable_electrum_rpc: config.disable_electrum_rpc,
|
||||
server_banner: config.server_banner,
|
||||
signet_magic: magic,
|
||||
args: args.map(|a| a.into_string().unwrap()).collect(),
|
||||
};
|
||||
eprintln!(
|
||||
|
|
|
@ -137,6 +137,7 @@ impl Daemon {
|
|||
config.network,
|
||||
config.daemon_p2p_addr,
|
||||
metrics,
|
||||
config.signet_magic,
|
||||
)?);
|
||||
Ok(Self { p2p, rpc })
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ impl Connection {
|
|||
network: Network,
|
||||
address: SocketAddr,
|
||||
metrics: &Metrics,
|
||||
magic: u32,
|
||||
) -> Result<Self> {
|
||||
let conn = Arc::new(
|
||||
TcpStream::connect(address)
|
||||
|
@ -187,7 +188,7 @@ impl Connection {
|
|||
send_duration.observe_duration("send", || {
|
||||
trace!("send: {:?}", msg);
|
||||
let raw_msg = message::RawNetworkMessage {
|
||||
magic: network.magic(),
|
||||
magic,
|
||||
payload: msg,
|
||||
};
|
||||
(&*stream)
|
||||
|
@ -213,7 +214,7 @@ impl Connection {
|
|||
}
|
||||
let raw_msg = match raw_msg {
|
||||
Ok(raw_msg) => {
|
||||
assert_eq!(raw_msg.magic, network.magic());
|
||||
assert_eq!(raw_msg.magic, magic);
|
||||
recv_size.observe(raw_msg.cmd.as_ref(), raw_msg.raw.len() as f64);
|
||||
raw_msg
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue