2018-03-03 13:41:36 -08:00
|
|
|
//! A command-line executable for generating the chain's genesis block.
|
|
|
|
|
2018-07-12 14:42:01 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate clap;
|
2018-12-08 21:44:20 -08:00
|
|
|
use serde_json;
|
|
|
|
|
2018-07-12 14:42:01 -07:00
|
|
|
use clap::{App, Arg};
|
2018-08-03 11:06:06 -07:00
|
|
|
use solana::ledger::LedgerWriter;
|
2018-03-27 15:24:05 -07:00
|
|
|
use solana::mint::Mint;
|
2018-12-06 14:01:25 -08:00
|
|
|
use solana_sdk::signature::{read_keypair, KeypairUtil};
|
2018-07-01 08:04:41 -07:00
|
|
|
use std::error;
|
2018-11-02 14:32:05 -07:00
|
|
|
use std::fs::File;
|
|
|
|
use std::path::Path;
|
2018-03-03 13:41:36 -08:00
|
|
|
|
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
|
|
|
|
*/
|
2018-12-10 12:20:13 -08:00
|
|
|
pub const BOOTSTRAP_LEADER_TOKENS: u64 = 3;
|
2018-11-15 17:05:31 -08:00
|
|
|
|
2018-12-08 21:44:20 -08:00
|
|
|
fn main() -> Result<(), Box<dyn error::Error>> {
|
2018-07-12 14:42:01 -07:00
|
|
|
let matches = App::new("solana-genesis")
|
2018-08-06 20:51:12 -07:00
|
|
|
.version(crate_version!())
|
2018-07-12 14:42:01 -07:00
|
|
|
.arg(
|
2018-11-02 14:32:05 -07:00
|
|
|
Arg::with_name("num_tokens")
|
2018-07-12 14:42:01 -07:00
|
|
|
.short("t")
|
2018-11-02 14:32:05 -07:00
|
|
|
.long("num_tokens")
|
|
|
|
.value_name("TOKENS")
|
2018-07-12 14:42:01 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2018-11-02 14:32:05 -07:00
|
|
|
.help("Number of tokens to create in the mint"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2018-11-02 14:32:05 -07:00
|
|
|
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"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2018-12-06 14:01:25 -08:00
|
|
|
Arg::with_name("bootstrap-leader-keypair")
|
2018-11-02 14:32:05 -07:00
|
|
|
.short("b")
|
2018-12-06 14:01:25 -08:00
|
|
|
.long("bootstrap-leader-keypair")
|
|
|
|
.value_name("BOOTSTRAP LEADER KEYPAIR")
|
2018-11-02 14:32:05 -07:00
|
|
|
.takes_value(true)
|
|
|
|
.required(true)
|
2018-12-06 14:01:25 -08:00
|
|
|
.help("Path to file containing the bootstrap leader's keypair"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.arg(
|
2018-08-03 11:06:06 -07:00
|
|
|
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"),
|
2018-12-07 19:01:28 -08:00
|
|
|
)
|
|
|
|
.get_matches();
|
2018-07-12 14:42:01 -07:00
|
|
|
|
2018-12-06 14:01:25 -08: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
|
|
|
|
2018-11-02 14:32:05 -07:00
|
|
|
// Parse the input mint configuration
|
2018-11-05 08:36:22 -08:00
|
|
|
let num_tokens = value_t_or_exit!(matches, "num_tokens", u64);
|
2018-11-02 14:32:05 -07:00
|
|
|
let file = File::open(Path::new(&matches.value_of("mint").unwrap())).unwrap();
|
2018-11-12 22:34:43 -08:00
|
|
|
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
|
|
|
|
2018-11-02 14:32:05 -07:00
|
|
|
// Write the ledger entries
|
|
|
|
let ledger_path = matches.value_of("ledger").unwrap();
|
2018-08-10 17:56:08 -07:00
|
|
|
let mut ledger_writer = LedgerWriter::open(&ledger_path, true)?;
|
2018-10-23 14:42:48 -07:00
|
|
|
ledger_writer.write_entries(&mint.create_entries())?;
|
2018-08-03 11:06:06 -07:00
|
|
|
|
2018-07-01 08:04:41 -07:00
|
|
|
Ok(())
|
2018-03-03 13:41:36 -08:00
|
|
|
}
|