这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multinode-demo/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ if $node_type_leader; then
$solana_mint <<<"$num_tokens" > "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json

echo "Creating $SOLANA_CONFIG_DIR/genesis.log"
$solana_genesis < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log
$solana_genesis --tokens "$num_tokens" < "$SOLANA_CONFIG_PRIVATE_DIR"/mint.json > "$SOLANA_CONFIG_DIR"/genesis.log

echo "Creating $SOLANA_CONFIG_DIR/leader.json"
$solana_fullnode_config "${leader_address_args[@]}" > "$SOLANA_CONFIG_DIR"/leader.json
Expand Down
23 changes: 22 additions & 1 deletion src/bin/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
//! A command-line executable for generating the chain's genesis block.

extern crate atty;
extern crate clap;
extern crate serde_json;
extern crate solana;

use atty::{is, Stream};
use clap::{App, Arg};
use solana::entry_writer::EntryWriter;
use solana::mint::Mint;
use std::error;
use std::io::{stdin, stdout, Read};
use std::process::exit;

fn main() -> Result<(), Box<error::Error>> {
let matches = App::new("solana-genesis")
.arg(
Arg::with_name("tokens")
.short("t")
.long("tokens")
.value_name("NUMBER")
.takes_value(true)
.required(true)
.help("Number of tokens with which to initialize mint"),
)
.get_matches();
let tokens: i64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy won't like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I checked the log. No complaint from clippy. It generally prefers:

let tokens = if { foo } else {bar};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine it's because of the if let construction in the following expression...?

if let Some(t) = matches.value_of("tokens") {
tokens = t.to_string().parse().expect("integer");
} else {
tokens = 0;
}

if is(Stream::Stdin) {
eprintln!("nothing found on stdin, expected a json file");
exit(1);
Expand All @@ -24,7 +44,8 @@ fn main() -> Result<(), Box<error::Error>> {
exit(1);
}

let mint: Mint = serde_json::from_str(&buffer)?;
let pkcs8: Vec<u8> = serde_json::from_str(&buffer)?;
let mint: Mint = Mint::new_from_keygen(tokens, pkcs8);
let mut writer = stdout();
EntryWriter::write_entries(&mut writer, mint.create_entries())?;
Ok(())
Expand Down
10 changes: 10 additions & 0 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ impl Mint {
tokens,
}
}
pub fn new_from_keygen(tokens: i64, pkcs8: Vec<u8>) -> Self {
let keypair = KeyPair::from_pkcs8(Input::from(&pkcs8))
.expect("keypair from_pkcs8 in mint pub fn new_from_keypair");
let pubkey = keypair.pubkey();
Mint {
pkcs8,
pubkey,
tokens,
}
}
pub fn seed(&self) -> Hash {
hash(&self.pkcs8)
}
Expand Down