Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Create JWT secret (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 authored Aug 13, 2022
1 parent e25fae8 commit 3b1b922
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion bin/akula.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ use ethereum_jsonrpc::{
};
use http::Uri;
use jsonrpsee::{core::server::rpc_module::Methods, http_server::HttpServerBuilder};
use std::{future::pending, net::SocketAddr, panic, sync::Arc, time::Duration};
use std::{
fs::OpenOptions, future::pending, io::Write, net::SocketAddr, panic, sync::Arc, time::Duration,
};
use tokio::time::sleep;
use tracing::*;
use tracing_subscriber::prelude::*;
Expand Down Expand Up @@ -109,6 +111,10 @@ pub struct Opt {
/// Enable CL engine RPC at this IP address and port.
#[clap(long, default_value = "127.0.0.1:8551")]
pub engine_listen_address: SocketAddr,

/// Path to JWT secret file.
#[clap(long)]
pub jwt_secret_path: Option<ExpandedPathBuf>,
}

#[allow(unreachable_code)]
Expand Down Expand Up @@ -172,6 +178,26 @@ fn main() -> anyhow::Result<()> {
chainspec
};

let jwt_secret_path = opt
.jwt_secret_path
.map(|v| v.0)
.unwrap_or_else(|| opt.data_dir.0.join("jwt.hex"));
if let Ok(mut file) = OpenOptions::new()
.write(true)
.create_new(true)
.open(jwt_secret_path)
{
file.write_all(
hex::encode(
std::iter::repeat_with(rand::random)
.take(32)
.collect::<Vec<_>>(),
)
.as_bytes(),
)?;
file.flush()?;
}

let consensus: Arc<dyn Consensus> = engine_factory(
Some(db.clone()),
chainspec.clone(),
Expand Down

0 comments on commit 3b1b922

Please sign in to comment.