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:
parent
b6d8f737ca
commit
5dd567deef
|
@ -7,7 +7,7 @@ use entry::Entry;
|
|||
use event::Event;
|
||||
use transaction::Transaction;
|
||||
use signature::{KeyPair, PublicKey, Signature};
|
||||
use genesis::Genesis;
|
||||
use mint::Mint;
|
||||
use historian::{reserve_signature, Historian};
|
||||
use std::sync::mpsc::SendError;
|
||||
use std::collections::HashMap;
|
||||
|
@ -62,8 +62,8 @@ impl Accountant {
|
|||
acc
|
||||
}
|
||||
|
||||
pub fn new(gen: &Genesis, ms_per_tick: Option<u64>) -> Self {
|
||||
Self::new_from_entries(gen.create_entries(), ms_per_tick)
|
||||
pub fn new(mint: &Mint, ms_per_tick: Option<u64>) -> Self {
|
||||
Self::new_from_entries(mint.create_entries(), ms_per_tick)
|
||||
}
|
||||
|
||||
pub fn sync(self: &mut Self) -> Hash {
|
||||
|
@ -151,7 +151,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_accountant() {
|
||||
let alice = Genesis::new(10_000);
|
||||
let alice = Mint::new(10_000);
|
||||
let bob_pubkey = KeyPair::new().pubkey();
|
||||
let mut acc = Accountant::new(&alice, Some(2));
|
||||
acc.transfer(1_000, &alice.keypair(), bob_pubkey).unwrap();
|
||||
|
@ -169,7 +169,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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 bob_pubkey = KeyPair::new().pubkey();
|
||||
acc.transfer(1_000, &alice.keypair(), bob_pubkey).unwrap();
|
||||
|
@ -191,7 +191,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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 alice_keypair = alice.keypair();
|
||||
let bob_pubkey = KeyPair::new().pubkey();
|
||||
|
|
|
@ -115,14 +115,14 @@ mod tests {
|
|||
use accountant_skel::AccountantSkel;
|
||||
use std::thread::{sleep, spawn};
|
||||
use std::time::Duration;
|
||||
use genesis::Genesis;
|
||||
use mint::Mint;
|
||||
use signature::{KeyPair, KeyPairUtil};
|
||||
|
||||
#[test]
|
||||
fn test_accountant_stub() {
|
||||
let addr = "127.0.0.1:9000";
|
||||
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 bob_pubkey = KeyPair::new().pubkey();
|
||||
spawn(move || AccountantSkel::new(acc).serve(addr).unwrap());
|
||||
|
|
|
@ -4,7 +4,7 @@ extern crate silk;
|
|||
use silk::accountant_stub::AccountantStub;
|
||||
use silk::signature::{KeyPair, KeyPairUtil};
|
||||
use silk::transaction::Transaction;
|
||||
use silk::genesis::Genesis;
|
||||
use silk::mint::Mint;
|
||||
use std::time::Instant;
|
||||
use std::net::UdpSocket;
|
||||
use std::io::stdin;
|
||||
|
@ -13,23 +13,23 @@ fn main() {
|
|||
let addr = "127.0.0.1:8000";
|
||||
let send_addr = "127.0.0.1:8001";
|
||||
|
||||
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||
let alice_keypair = gen.keypair();
|
||||
let alice_pubkey = gen.pubkey();
|
||||
let mint: Mint = serde_json::from_reader(stdin()).unwrap();
|
||||
let mint_keypair = mint.keypair();
|
||||
let mint_pubkey = mint.pubkey();
|
||||
|
||||
let socket = UdpSocket::bind(send_addr).unwrap();
|
||||
let mut acc = AccountantStub::new(addr, socket);
|
||||
let last_id = acc.get_last_id().unwrap();
|
||||
|
||||
let txs = acc.get_balance(&alice_pubkey).unwrap().unwrap();
|
||||
println!("Alice's Initial Balance {}", txs);
|
||||
let txs = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||
println!("Mint's Initial Balance {}", txs);
|
||||
|
||||
println!("Signing transactions...");
|
||||
let now = Instant::now();
|
||||
let transactions: Vec<_> = (0..txs)
|
||||
.map(|_| {
|
||||
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();
|
||||
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 tps = (txs * 1_000_000_000) as f64 / ns as f64;
|
||||
println!("Done. {} tps!", tps);
|
||||
let val = acc.get_balance(&alice_pubkey).unwrap().unwrap();
|
||||
println!("Alice's Final Balance {}", val);
|
||||
let val = acc.get_balance(&mint_pubkey).unwrap().unwrap();
|
||||
println!("Mint's Final Balance {}", val);
|
||||
assert_eq!(val, 0);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
use silk::genesis::Genesis;
|
||||
use silk::mint::Mint;
|
||||
use silk::event::Event;
|
||||
use silk::transaction::Transaction;
|
||||
use silk::log::create_entries;
|
||||
|
@ -17,10 +17,10 @@ fn main() {
|
|||
let alice = (KeyPair::new().pubkey(), 200);
|
||||
let bob = (KeyPair::new().pubkey(), 100);
|
||||
|
||||
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||
let from = gen.keypair();
|
||||
let seed = gen.seed();
|
||||
let mut events = gen.create_events();
|
||||
let mint: Mint = serde_json::from_reader(stdin()).unwrap();
|
||||
let from = mint.keypair();
|
||||
let seed = mint.seed();
|
||||
let mut events = mint.create_events();
|
||||
events.push(transfer(&from, alice, seed));
|
||||
events.push(transfer(&from, bob, seed));
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
use silk::genesis::Genesis;
|
||||
use silk::mint::Mint;
|
||||
use std::io::stdin;
|
||||
|
||||
fn main() {
|
||||
let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||
for x in gen.create_entries() {
|
||||
let mint: Mint = serde_json::from_reader(stdin()).unwrap();
|
||||
for x in mint.create_entries() {
|
||||
println!("{}", serde_json::to_string(&x).unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
use silk::genesis::Genesis;
|
||||
use silk::mint::Mint;
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
let mut input_text = String::new();
|
||||
io::stdin().read_line(&mut input_text).unwrap();
|
||||
|
||||
let trimmed = input_text.trim();
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ pub mod transaction;
|
|||
pub mod event;
|
||||
pub mod entry;
|
||||
pub mod log;
|
||||
pub mod genesis;
|
||||
pub mod mint;
|
||||
pub mod logger;
|
||||
pub mod historian;
|
||||
pub mod accountant;
|
||||
|
|
|
@ -10,16 +10,16 @@ use ring::rand::SystemRandom;
|
|||
use untrusted::Input;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Genesis {
|
||||
pub struct Mint {
|
||||
pub pkcs8: Vec<u8>,
|
||||
pub tokens: i64,
|
||||
}
|
||||
|
||||
impl Genesis {
|
||||
impl Mint {
|
||||
pub fn new(tokens: i64) -> Self {
|
||||
let rnd = SystemRandom::new();
|
||||
let pkcs8 = KeyPair::generate_pkcs8(&rnd).unwrap().to_vec();
|
||||
Genesis { pkcs8, tokens }
|
||||
Mint { pkcs8, tokens }
|
||||
}
|
||||
|
||||
pub fn seed(&self) -> Hash {
|
||||
|
@ -51,7 +51,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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);
|
||||
if let Event::Transaction(tr) = events.next().unwrap() {
|
||||
assert_eq!(tr.from, tr.to);
|
||||
|
@ -63,7 +63,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue