-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add init commands to node and faucet binaries (#392)
- Loading branch information
Showing
17 changed files
with
301 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::{fs::File, io::Write, path::PathBuf}; | ||
|
||
use anyhow::{anyhow, Result}; | ||
|
||
use crate::{commands::genesis::GenesisInput, config::NodeConfig}; | ||
|
||
// INIT | ||
// =================================================================================================== | ||
|
||
pub fn init_config_files(config_file_path: PathBuf, genesis_file_path: PathBuf) -> Result<()> { | ||
let config = NodeConfig::default(); | ||
let config_as_toml_string = toml::to_string(&config) | ||
.map_err(|err| anyhow!("Failed to serialize default config: {}", err))?; | ||
|
||
write_string_in_file(config_as_toml_string, &config_file_path)?; | ||
|
||
println!("Config file successfully created at: {:?}", config_file_path); | ||
|
||
let genesis = GenesisInput::default(); | ||
let genesis_as_toml_string = toml::to_string(&genesis) | ||
.map_err(|err| anyhow!("Failed to serialize default config: {}", err))?; | ||
|
||
write_string_in_file(genesis_as_toml_string, &genesis_file_path)?; | ||
|
||
println!("Genesis config file successfully created at: {:?}", genesis_file_path); | ||
|
||
Ok(()) | ||
} | ||
|
||
fn write_string_in_file(content: String, path: &PathBuf) -> Result<()> { | ||
let mut file_handle = File::options() | ||
.write(true) | ||
.create_new(true) | ||
.open(path) | ||
.map_err(|err| anyhow!("Error opening the file: {err}"))?; | ||
|
||
file_handle | ||
.write(content.as_bytes()) | ||
.map_err(|err| anyhow!("Error writing to file: {err}"))?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.