Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions substrate/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub mod chain_ops;
use std::io;
use std::net::SocketAddr;
use std::sync::Arc;
use std::fmt::Write;
use futures::prelude::*;
use keystore::Store as Keystore;
use client::BlockchainEvents;
Expand Down Expand Up @@ -125,10 +126,17 @@ impl<Components> Service<Components>
keystore.generate_from_seed(seed)?;
}

if keystore.contents()?.is_empty() {
let key = keystore.generate("")?;
info!("Generated a new keypair: {:?}", key.public());
}
// Keep the public key for telemetry
let public_key = match keystore.contents()?.get(0) {
Some(public_key) => public_key.clone(),
None => {
let key = keystore.generate("")?;
let public_key = key.public();
info!("Generated a new keypair: {:?}", public_key);

public_key
}
};

let (client, on_demand) = Components::build_client(&config, executor)?;
let best_header = client.best_block_header()?;
Expand Down Expand Up @@ -218,6 +226,12 @@ impl<Components> Service<Components>
// Telemetry
let telemetry = match config.telemetry_url {
Some(url) => {
let mut pubkey = String::new();

for ch in public_key.as_slice() {
write!(pubkey, "{:02x}", ch).expect("Cannot fail on u8 slices; qed");
}

let name = config.name.clone();
let impl_name = config.impl_name.to_owned();
let version = version.clone();
Expand All @@ -231,6 +245,7 @@ impl<Components> Service<Components>
"version" => version.clone(),
"config" => "",
"chain" => chain_name.clone(),
"pubkey" => &pubkey,
);
}),
}))
Expand Down