chore: add builder with rng secret key fn (#9218)

This commit is contained in:
Matthias Seitz
2024-07-01 15:07:49 +02:00
committed by GitHub
parent db191c82a5
commit d317b4a0fb

View File

@ -88,6 +88,11 @@ impl NetworkConfig<()> {
pub fn builder(secret_key: SecretKey) -> NetworkConfigBuilder {
NetworkConfigBuilder::new(secret_key)
}
/// Convenience method for creating the corresponding builder type with a random secret key.
pub fn builder_with_rng_secret_key() -> NetworkConfigBuilder {
NetworkConfigBuilder::with_rng_secret_key()
}
}
impl<C> NetworkConfig<C> {
@ -176,6 +181,12 @@ pub struct NetworkConfigBuilder {
#[allow(missing_docs)]
impl NetworkConfigBuilder {
/// Create a new builder instance with a random secret key.
pub fn with_rng_secret_key() -> Self {
Self::new(rng_secret_key())
}
/// Create a new builder instance with the given secret key.
pub fn new(secret_key: SecretKey) -> Self {
Self {
secret_key,
@ -212,6 +223,11 @@ impl NetworkConfigBuilder {
pk2id(&self.secret_key.public_key(SECP256K1))
}
/// Returns the configured [`SecretKey`], from which the node's identity is derived.
pub const fn secret_key(&self) -> &SecretKey {
&self.secret_key
}
/// Sets the chain spec.
pub fn chain_spec(mut self, chain_spec: Arc<ChainSpec>) -> Self {
self.chain_spec = chain_spec;