Add `with_admin_signer` to network
Add a `with_admin_signer` method to `Network` that can be used to set
the admin signer for default nodes. If the `with_admin_signer`
function is not used a new signer will be created and set as the
admin signer when the default nodes are built.
use std::collections::HashMap;
use std::fs::File;
-use cylinder::{secp256k1::Secp256k1Context, Context};
+use cylinder::{secp256k1::Secp256k1Context, Context, Signer};
use splinter::error::{InternalError, InvalidArgumentError};
use splinter::registry::Node as RegistryNode;
use splinter::threading::lifecycle::ShutdownHandle;
@@ -36,6 +36,7 @@ pub struct Network {
num_of_keys: usize,
cylinder_auth: bool,
permission_config: Option<Vec<PermissionConfig>>,
+ admin_signer: Option<Box<dyn Signer>>,
}
pub enum NetworkNode {
@@ -53,6 +54,7 @@ impl Network {
num_of_keys: 1,
cylinder_auth: true,
permission_config: None,
+ admin_signer: None,
}
}
@@ -70,7 +72,10 @@ impl Network {
let mut registry_info = vec![];
let context = Secp256k1Context::new();
for _ in 0..count {
- let admin_signer = context.new_signer(context.new_random_private_key());
+ let admin_signer = match self.admin_signer {
+ Some(ref signer) => signer.clone_box(),
+ None => context.new_signer(context.new_random_private_key()),
+ };
let public_key = admin_signer
.public_key()
.map_err(|e| InternalError::from_source(Box::new(e)))?;
@@ -168,6 +173,11 @@ impl Network {
self
}
+ pub fn with_admin_signer(mut self, signer: Box<dyn Signer>) -> Self {
+ self.admin_signer = Some(signer);
+ self
+ }
+
pub fn node(&self, n: usize) -> Result<&Node, InvalidArgumentError> {
match self.nodes.get(n) {
Some(network_node) => match network_node {
