use std::net::SocketAddr;
use stratum_apps::{
config_helpers::CoinbaseRewardScript,
key_utils::{Secp256k1PublicKey, Secp256k1SecretKey},
};
#[derive(Clone, Debug, serde::Deserialize)]
pub struct JDSPartialConfig {
listen_address: SocketAddr,
#[serde(default)]
supported_extensions: Vec<u16>,
#[serde(default)]
required_extensions: Vec<u16>,
}
#[derive(Clone, Debug)]
pub struct JDSConfig {
listen_address: SocketAddr,
authority_public_key: Secp256k1PublicKey,
authority_secret_key: Secp256k1SecretKey,
cert_validity_sec: u64,
coinbase_reward_script: CoinbaseRewardScript,
supported_extensions: Vec<u16>,
required_extensions: Vec<u16>,
}
impl JDSPartialConfig {
pub fn new(listen_address: SocketAddr) -> Self {
Self {
listen_address,
supported_extensions: Vec::new(),
required_extensions: Vec::new(),
}
}
}
#[cfg_attr(not(test), hotpath::measure_all)]
impl JDSConfig {
#[allow(clippy::too_many_arguments)]
pub fn new(
listen_address: SocketAddr,
authority_public_key: Secp256k1PublicKey,
authority_secret_key: Secp256k1SecretKey,
cert_validity_sec: u64,
coinbase_reward_script: CoinbaseRewardScript,
supported_extensions: Vec<u16>,
required_extensions: Vec<u16>,
) -> Self {
Self {
listen_address,
authority_public_key,
authority_secret_key,
cert_validity_sec,
coinbase_reward_script,
supported_extensions,
required_extensions,
}
}
#[allow(clippy::too_many_arguments)]
pub fn from_partial(
partial: JDSPartialConfig,
authority_public_key: Secp256k1PublicKey,
authority_secret_key: Secp256k1SecretKey,
cert_validity_sec: u64,
coinbase_reward_script: CoinbaseRewardScript,
) -> Self {
Self {
listen_address: partial.listen_address,
authority_public_key,
authority_secret_key,
cert_validity_sec,
coinbase_reward_script,
supported_extensions: partial.supported_extensions,
required_extensions: partial.required_extensions,
}
}
pub fn listen_address(&self) -> &SocketAddr {
&self.listen_address
}
pub fn authority_public_key(&self) -> &Secp256k1PublicKey {
&self.authority_public_key
}
pub fn authority_secret_key(&self) -> &Secp256k1SecretKey {
&self.authority_secret_key
}
pub fn cert_validity_sec(&self) -> u64 {
self.cert_validity_sec
}
pub fn coinbase_reward_script(&self) -> &CoinbaseRewardScript {
&self.coinbase_reward_script
}
pub fn supported_extensions(&self) -> &[u16] {
&self.supported_extensions
}
pub fn required_extensions(&self) -> &[u16] {
&self.required_extensions
}
}