-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Genesis Template cli command (#612)
* Genesis New Template cli command * PascalCase * addressing more comments * lowercase on ActorType
- Loading branch information
Showing
8 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use fil_types::genesis; | ||
use std::fs::File; | ||
use structopt::StructOpt; | ||
use uuid::Uuid; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub enum GenesisCommands { | ||
/// Creates new genesis template | ||
#[structopt(about = "Create new Genesis template")] | ||
NewTemplate { | ||
#[structopt(short, help = "Input a network name")] | ||
network_name: Option<String>, | ||
#[structopt( | ||
short, | ||
default_value = "genesis.json", | ||
help = "File path, i.e, './genesis.json'. This command WILL NOT create a directory if it does not exist." | ||
)] | ||
file_path: String, | ||
}, | ||
} | ||
|
||
impl GenesisCommands { | ||
pub async fn run(&self) { | ||
match self { | ||
Self::NewTemplate { | ||
network_name, | ||
file_path, | ||
} => { | ||
let template = genesis::Template::new( | ||
network_name | ||
.as_ref() | ||
.unwrap_or(&format!("localnet-{}", Uuid::new_v4().to_string())) | ||
.to_string(), | ||
); | ||
|
||
match &File::create(file_path) { | ||
Ok(file) => { | ||
serde_json::to_writer_pretty(file, &template).unwrap(); | ||
} | ||
Err(err) => { | ||
println!("Can not write to a file, error: {}", err); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,56 @@ | ||
// Copyright 2020 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use super::SectorSize; | ||
use address::Address; | ||
use num_bigint::bigint_ser; | ||
use serde::Serialize; | ||
use vm::TokenAmount; | ||
|
||
#[derive(Serialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum ActorType { | ||
Account, | ||
MultiSig, | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Actor { | ||
pub actor_type: ActorType, | ||
#[serde(with = "bigint_ser")] | ||
pub token_amount: TokenAmount, | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Miner { | ||
pub owner: Address, | ||
pub worker: Address, | ||
pub peer_id: Vec<u8>, | ||
|
||
#[serde(with = "bigint_ser")] | ||
pub market_balance: TokenAmount, | ||
#[serde(with = "bigint_ser")] | ||
pub power_balance: TokenAmount, | ||
pub sector_size: SectorSize, | ||
} | ||
|
||
#[derive(Serialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Template { | ||
pub accounts: Vec<Actor>, | ||
pub miners: Vec<Miner>, | ||
pub network_name: String, | ||
// timestamp: SystemTime, | ||
} | ||
|
||
impl Template { | ||
pub fn new(network_name: String) -> Template { | ||
Template { | ||
accounts: Vec::new(), | ||
miners: Vec::new(), | ||
network_name, | ||
} | ||
} | ||
} |
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