Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dmd create miner tool fixes #128

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
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
38 changes: 35 additions & 3 deletions crates/ethcore/src/engines/hbbft/dmd/src/create_miner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ethstore::{KeyFile, SafeAccount};
use parity_crypto::publickey::{Generator, KeyPair, Random, Secret};
use std::{fs, num::NonZeroU32, path::Path};
use serde_json::Value;
use std::{fs, num::NonZeroU32, path::Path, str::FromStr};

fn write_json_for_secret(secret: Secret, filename: &str) {
let json_key: KeyFile = SafeAccount::create(
Expand All @@ -21,6 +22,37 @@ fn write_json_for_secret(secret: Secret, filename: &str) {

pub fn create_miner() {
println!("Creating dmd v4 miner...");
let mut name: String = "DPoSChain".to_string();
match fs::read_to_string("spec.json") {
Ok(s) => match serde_json::from_str(s.as_str()) {
Ok(Value::Object(map)) => {
if map.contains_key("name") {
let x = &map["name"];

match x.as_str() {
Some(n) => {
name = String::from_str(n)
.expect("could not parse chain name from spec.json");
println!("chain: {}", name);
}
None => {
println!("could not read chain name from spec.json");
}
}
}
}
_ => {
println!("unable to parse spec.json");
}
},
Err(e) => {
println!("unable to to open spec.json: {:?}", e);
}
}

//let serialized_json_key =
//serde_json::to_string(&json_key).expect("json key object serialization should succeed");

let acc = Random.generate();

// Create "data" and "network" subfolders.
Expand All @@ -31,8 +63,8 @@ pub fn create_miner() {
.expect("Unable to write the network key file");

// Create "keys" and "DPoSChain" subfolders.
let accounts_dir = Path::new("./data/keys/DPoSChain");
fs::create_dir_all(accounts_dir).expect("Could not create accounts directory");
let accounts_dir = Path::new("./data/keys/").join(name);
fs::create_dir_all(accounts_dir.clone()).expect("Could not create accounts directory");

// Write JSON account.
write_json_for_secret(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ fn to_toml(
// this makes sure that the min_gas_price wont be higher then the gas pricce the DAO decides.
mining.insert("min_gas_price".into(), Value::Integer(1000));
mining.insert("reseal_on_txs".into(), Value::String("none".into()));
mining.insert("gas_floor_target".into(), Value::String("300000000".into()));
mining.insert("reseal_min_period".into(), Value::Integer(0));

if let Some(tx_queue_per_sender_) = tx_queue_per_sender {
Expand Down
Loading