Rename Genesis to Mint

Genesis is a story of creation. We should only use that term to
for the event log that bootstraps the system.
This commit is contained in:
Greg Fitzgerald
2018-03-07 17:08:12 -07:00
parent b6d8f737ca
commit 5dd567deef
8 changed files with 35 additions and 35 deletions

View File

@ -7,7 +7,7 @@ use entry::Entry;
use event::Event; use event::Event;
use transaction::Transaction; use transaction::Transaction;
use signature::{KeyPair, PublicKey, Signature}; use signature::{KeyPair, PublicKey, Signature};
use genesis::Genesis; use mint::Mint;
use historian::{reserve_signature, Historian}; use historian::{reserve_signature, Historian};
use std::sync::mpsc::SendError; use std::sync::mpsc::SendError;
use std::collections::HashMap; use std::collections::HashMap;
@ -62,8 +62,8 @@ impl Accountant {
acc acc
} }
pub fn new(gen: &Genesis, ms_per_tick: Option<u64>) -> Self { pub fn new(mint: &Mint, ms_per_tick: Option<u64>) -> Self {
Self::new_from_entries(gen.create_entries(), ms_per_tick) Self::new_from_entries(mint.create_entries(), ms_per_tick)
} }
pub fn sync(self: &mut Self) -> Hash { pub fn sync(self: &mut Self) -> Hash {
@ -151,7 +151,7 @@ mod tests {
#[test] #[test]
fn test_accountant() { fn test_accountant() {
let alice = Genesis::new(10_000); let alice = Mint::new(10_000);
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
let mut acc = Accountant::new(&alice, Some(2)); let mut acc = Accountant::new(&alice, Some(2));
acc.transfer(1_000, &alice.keypair(), bob_pubkey).unwrap(); acc.transfer(1_000, &alice.keypair(), bob_pubkey).unwrap();
@ -169,7 +169,7 @@ mod tests {
#[test] #[test]
fn test_invalid_transfer() { fn test_invalid_transfer() {
let alice = Genesis::new(11_000); let alice = Mint::new(11_000);
let mut acc = Accountant::new(&alice, Some(2)); let mut acc = Accountant::new(&alice, Some(2));
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
acc.transfer(1_000, &alice.keypair(), bob_pubkey).unwrap(); acc.transfer(1_000, &alice.keypair(), bob_pubkey).unwrap();
@ -191,7 +191,7 @@ mod tests {
#[test] #[test]
fn test_transfer_to_newb() { fn test_transfer_to_newb() {
let alice = Genesis::new(10_000); let alice = Mint::new(10_000);
let mut acc = Accountant::new(&alice, Some(2)); let mut acc = Accountant::new(&alice, Some(2));
let alice_keypair = alice.keypair(); let alice_keypair = alice.keypair();
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();

View File

@ -115,14 +115,14 @@ mod tests {
use accountant_skel::AccountantSkel; use accountant_skel::AccountantSkel;
use std::thread::{sleep, spawn}; use std::thread::{sleep, spawn};
use std::time::Duration; use std::time::Duration;
use genesis::Genesis; use mint::Mint;
use signature::{KeyPair, KeyPairUtil}; use signature::{KeyPair, KeyPairUtil};
#[test] #[test]
fn test_accountant_stub() { fn test_accountant_stub() {
let addr = "127.0.0.1:9000"; let addr = "127.0.0.1:9000";
let send_addr = "127.0.0.1:9001"; let send_addr = "127.0.0.1:9001";
let alice = Genesis::new(10_000); let alice = Mint::new(10_000);
let acc = Accountant::new(&alice, None); let acc = Accountant::new(&alice, None);
let bob_pubkey = KeyPair::new().pubkey(); let bob_pubkey = KeyPair::new().pubkey();
spawn(move || AccountantSkel::new(acc).serve(addr).unwrap()); spawn(move || AccountantSkel::new(acc).serve(addr).unwrap());

View File

@ -4,7 +4,7 @@ extern crate silk;
use silk::accountant_stub::AccountantStub; use silk::accountant_stub::AccountantStub;
use silk::signature::{KeyPair, KeyPairUtil}; use silk::signature::{KeyPair, KeyPairUtil};
use silk::transaction::Transaction; use silk::transaction::Transaction;
use silk::genesis::Genesis; use silk::mint::Mint;
use std::time::Instant; use std::time::Instant;
use std::net::UdpSocket; use std::net::UdpSocket;
use std::io::stdin; use std::io::stdin;
@ -13,23 +13,23 @@ fn main() {
let addr = "127.0.0.1:8000"; let addr = "127.0.0.1:8000";
let send_addr = "127.0.0.1:8001"; let send_addr = "127.0.0.1:8001";
let gen: Genesis = serde_json::from_reader(stdin()).unwrap(); let mint: Mint = serde_json::from_reader(stdin()).unwrap();
let alice_keypair = gen.keypair(); let mint_keypair = mint.keypair();
let alice_pubkey = gen.pubkey(); let mint_pubkey = mint.pubkey();
let socket = UdpSocket::bind(send_addr).unwrap(); let socket = UdpSocket::bind(send_addr).unwrap();
let mut acc = AccountantStub::new(addr, socket); let mut acc = AccountantStub::new(addr, socket);
let last_id = acc.get_last_id().unwrap(); let last_id = acc.get_last_id().unwrap();
let txs = acc.get_balance(&alice_pubkey).unwrap().unwrap(); let txs = acc.get_balance(&mint_pubkey).unwrap().unwrap();
println!("Alice's Initial Balance {}", txs); println!("Mint's Initial Balance {}", txs);
println!("Signing transactions..."); println!("Signing transactions...");
let now = Instant::now(); let now = Instant::now();
let transactions: Vec<_> = (0..txs) let transactions: Vec<_> = (0..txs)
.map(|_| { .map(|_| {
let rando_pubkey = KeyPair::new().pubkey(); let rando_pubkey = KeyPair::new().pubkey();
Transaction::new(&alice_keypair, rando_pubkey, 1, last_id) Transaction::new(&mint_keypair, rando_pubkey, 1, last_id)
}) })
.collect(); .collect();
let duration = now.elapsed(); let duration = now.elapsed();
@ -71,7 +71,7 @@ fn main() {
let ns = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64; let ns = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
let tps = (txs * 1_000_000_000) as f64 / ns as f64; let tps = (txs * 1_000_000_000) as f64 / ns as f64;
println!("Done. {} tps!", tps); println!("Done. {} tps!", tps);
let val = acc.get_balance(&alice_pubkey).unwrap().unwrap(); let val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
println!("Alice's Final Balance {}", val); println!("Mint's Final Balance {}", val);
assert_eq!(val, 0); assert_eq!(val, 0);
} }

View File

@ -1,7 +1,7 @@
extern crate serde_json; extern crate serde_json;
extern crate silk; extern crate silk;
use silk::genesis::Genesis; use silk::mint::Mint;
use silk::event::Event; use silk::event::Event;
use silk::transaction::Transaction; use silk::transaction::Transaction;
use silk::log::create_entries; use silk::log::create_entries;
@ -17,10 +17,10 @@ fn main() {
let alice = (KeyPair::new().pubkey(), 200); let alice = (KeyPair::new().pubkey(), 200);
let bob = (KeyPair::new().pubkey(), 100); let bob = (KeyPair::new().pubkey(), 100);
let gen: Genesis = serde_json::from_reader(stdin()).unwrap(); let mint: Mint = serde_json::from_reader(stdin()).unwrap();
let from = gen.keypair(); let from = mint.keypair();
let seed = gen.seed(); let seed = mint.seed();
let mut events = gen.create_events(); let mut events = mint.create_events();
events.push(transfer(&from, alice, seed)); events.push(transfer(&from, alice, seed));
events.push(transfer(&from, bob, seed)); events.push(transfer(&from, bob, seed));

View File

@ -3,12 +3,12 @@
extern crate serde_json; extern crate serde_json;
extern crate silk; extern crate silk;
use silk::genesis::Genesis; use silk::mint::Mint;
use std::io::stdin; use std::io::stdin;
fn main() { fn main() {
let gen: Genesis = serde_json::from_reader(stdin()).unwrap(); let mint: Mint = serde_json::from_reader(stdin()).unwrap();
for x in gen.create_entries() { for x in mint.create_entries() {
println!("{}", serde_json::to_string(&x).unwrap()); println!("{}", serde_json::to_string(&x).unwrap());
} }
} }

View File

@ -1,15 +1,15 @@
extern crate serde_json; extern crate serde_json;
extern crate silk; extern crate silk;
use silk::genesis::Genesis; use silk::mint::Mint;
use std::io; use std::io;
fn main() { fn main() {
let mut input_text = String::new(); let mut input_text = String::new();
io::stdin().read_line(&mut input_text).unwrap(); io::stdin().read_line(&mut input_text).unwrap();
let trimmed = input_text.trim(); let trimmed = input_text.trim();
let tokens = trimmed.parse::<i64>().unwrap(); let tokens = trimmed.parse::<i64>().unwrap();
let gen = Genesis::new(tokens);
println!("{}", serde_json::to_string(&gen).unwrap()); let mint = Mint::new(tokens);
println!("{}", serde_json::to_string(&mint).unwrap());
} }

View File

@ -5,7 +5,7 @@ pub mod transaction;
pub mod event; pub mod event;
pub mod entry; pub mod entry;
pub mod log; pub mod log;
pub mod genesis; pub mod mint;
pub mod logger; pub mod logger;
pub mod historian; pub mod historian;
pub mod accountant; pub mod accountant;

View File

@ -10,16 +10,16 @@ use ring::rand::SystemRandom;
use untrusted::Input; use untrusted::Input;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Genesis { pub struct Mint {
pub pkcs8: Vec<u8>, pub pkcs8: Vec<u8>,
pub tokens: i64, pub tokens: i64,
} }
impl Genesis { impl Mint {
pub fn new(tokens: i64) -> Self { pub fn new(tokens: i64) -> Self {
let rnd = SystemRandom::new(); let rnd = SystemRandom::new();
let pkcs8 = KeyPair::generate_pkcs8(&rnd).unwrap().to_vec(); let pkcs8 = KeyPair::generate_pkcs8(&rnd).unwrap().to_vec();
Genesis { pkcs8, tokens } Mint { pkcs8, tokens }
} }
pub fn seed(&self) -> Hash { pub fn seed(&self) -> Hash {
@ -51,7 +51,7 @@ mod tests {
#[test] #[test]
fn test_create_events() { fn test_create_events() {
let mut events = Genesis::new(100).create_events().into_iter(); let mut events = Mint::new(100).create_events().into_iter();
assert_eq!(events.next().unwrap(), Event::Tick); assert_eq!(events.next().unwrap(), Event::Tick);
if let Event::Transaction(tr) = events.next().unwrap() { if let Event::Transaction(tr) = events.next().unwrap() {
assert_eq!(tr.from, tr.to); assert_eq!(tr.from, tr.to);
@ -63,7 +63,7 @@ mod tests {
#[test] #[test]
fn test_verify_entries() { fn test_verify_entries() {
let entries = Genesis::new(100).create_entries(); let entries = Mint::new(100).create_entries();
assert!(verify_slice(&entries, &entries[0].id)); assert!(verify_slice(&entries, &entries[0].id));
} }
} }