solana/genesis/src/main.rs

89 lines
3.1 KiB
Rust
Raw Normal View History

//! A command-line executable for generating the chain's genesis block.
2018-12-14 20:39:10 -08:00
use clap::{crate_version, value_t_or_exit, App, Arg};
use serde_json;
use solana::db_ledger::genesis;
2018-03-27 15:24:05 -07:00
use solana::mint::Mint;
use solana_sdk::signature::{read_keypair, KeypairUtil};
2018-07-01 08:04:41 -07:00
use std::error;
use std::fs::File;
use std::path::Path;
2018-11-15 17:05:31 -08:00
/**
* Bootstrap leader gets two tokens:
* - one token to create an instance of the vote_program with
2018-12-10 12:20:13 -08:00
* - one token for the transaction fee
2018-11-15 17:05:31 -08:00
* - one second token to keep the node identity public key valid
*/
//pub const BOOTSTRAP_LEADER_TOKENS: u64 = 3;
// TODO: Until https://github.com/solana-labs/solana/issues/2355 is resolved the bootstrap leader
// needs N tokens as its vote account gets re-created on every node restart, costing it tokens
pub const BOOTSTRAP_LEADER_TOKENS: u64 = 1_000_000;
2018-11-15 17:05:31 -08:00
fn main() -> Result<(), Box<dyn error::Error>> {
2018-07-12 14:42:01 -07:00
let matches = App::new("solana-genesis")
.version(crate_version!())
2018-07-12 14:42:01 -07:00
.arg(
Arg::with_name("num_tokens")
2018-07-12 14:42:01 -07:00
.short("t")
.long("num_tokens")
.value_name("TOKENS")
2018-07-12 14:42:01 -07:00
.takes_value(true)
.required(true)
.help("Number of tokens to create in the mint"),
)
.arg(
Arg::with_name("mint")
.short("m")
.long("mint")
.value_name("MINT")
.takes_value(true)
.required(true)
.help("Path to file containing keys of the mint"),
)
.arg(
Arg::with_name("bootstrap-leader-keypair")
.short("b")
.long("bootstrap-leader-keypair")
.value_name("BOOTSTRAP LEADER KEYPAIR")
.takes_value(true)
.required(true)
.help("Path to file containing the bootstrap leader's keypair"),
)
.arg(
Arg::with_name("ledger")
.short("l")
.long("ledger")
.value_name("DIR")
.takes_value(true)
.required(true)
2018-09-14 15:32:57 -07:00
.help("Use directory as persistent ledger location"),
)
.get_matches();
2018-07-12 14:42:01 -07:00
// Load the bootstreap leader keypair
// TODO: Only the public key is really needed, genesis should not have access to the leader's
// secret key.
let leader_keypair = read_keypair(matches.value_of("bootstrap-leader-keypair").unwrap())
.expect("failed to read bootstrap leader keypair");
2018-04-21 06:12:57 -07:00
// Parse the input mint configuration
let num_tokens = value_t_or_exit!(matches, "num_tokens", u64);
let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap();
let pkcs8: Vec<u8> = serde_json::from_reader(&file)?;
2018-11-15 17:05:31 -08:00
let mint = Mint::new_with_pkcs8(
num_tokens,
pkcs8,
leader_keypair.pubkey(),
BOOTSTRAP_LEADER_TOKENS,
);
2018-07-12 14:42:01 -07:00
// Write the ledger entries
let entries = mint.create_entries();
let ledger_path = matches.value_of("ledger").unwrap();
genesis(&ledger_path, &leader_keypair, &entries)?;
2018-07-01 08:04:41 -07:00
Ok(())
}