Skip to content

Commit

Permalink
chore: add builder with rng secret key fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jul 1, 2024
1 parent 068bf57 commit e6510ac
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 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;
Expand Down

0 comments on commit e6510ac

Please sign in to comment.