-
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.
- Loading branch information
Showing
8 changed files
with
109 additions
and
0 deletions.
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,40 @@ | ||
use std::fs::{File, create_dir_all}; | ||
use std::path::Path; | ||
use std::error::Error as StdError; | ||
use structopt::StructOpt; | ||
use fil_types::genesis; | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub enum GenesisCommands { | ||
/// Creates new genesis template | ||
#[structopt(about = "Create new Genesis template")] | ||
GenesisNewTemplate { | ||
#[structopt(short, help = "Input a network name")] | ||
network_name: 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::GenesisNewTemplate { network_name, file_path } => { | ||
genesis_new_template(network_name.to_string(), file_path.to_string()); | ||
}, | ||
} | ||
} | ||
} | ||
|
||
fn genesis_new_template(network_name: String, file_path: String) { | ||
let template = genesis::Template::new(network_name); | ||
|
||
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,53 @@ | ||
use address::Address; | ||
use super::SectorSize; | ||
use vm::TokenAmount; | ||
use serde::Serialize; | ||
use num_bigint::bigint_ser; | ||
use std::time::SystemTime; | ||
|
||
#[derive(Serialize)] | ||
enum ActorType { | ||
Account, | ||
MultiSig, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct Actor { | ||
actor_type: ActorType, | ||
#[serde(with = "bigint_ser")] | ||
token_amount: TokenAmount, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct Miner { | ||
owner: Address, | ||
worker: Address, | ||
peer_id: Vec<u8>, | ||
|
||
#[serde(with = "bigint_ser")] | ||
market_balance: TokenAmount, | ||
#[serde(with = "bigint_ser")] | ||
power_balance: TokenAmount, | ||
sector_size: SectorSize, | ||
} | ||
|
||
#[derive(Serialize)] | ||
pub struct Template { | ||
accounts: Vec<Actor>, | ||
miners: Vec<Miner>, | ||
network_name: String, | ||
|
||
#[serde(skip_serializing)] | ||
timestamp: SystemTime, | ||
} | ||
|
||
impl Template { | ||
pub fn new(network_name: String) -> Template { | ||
Template{ | ||
accounts: Vec::new(), | ||
miners: Vec::new(), | ||
network_name, | ||
timestamp: SystemTime::now(), | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
mod piece; | ||
pub mod sector; | ||
pub mod genesis; | ||
|
||
pub use self::piece::*; | ||
pub use self::sector::*; | ||
|