Add a demo app to generate the genesis file
This commit is contained in:
parent
572475ce14
commit
9b26892bae
|
@ -27,6 +27,10 @@ path = "src/bin/testnode.rs"
|
|||
name = "silk-genesis-block"
|
||||
path = "src/bin/genesis-block.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "silk-genesis-file-demo"
|
||||
path = "src/bin/genesis-file-demo.rs"
|
||||
|
||||
[badges]
|
||||
codecov = { repository = "loomprotocol/silk", branch = "master", service = "github" }
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_accountant() {
|
||||
let bob = Creator::new("Bob", 1_000);
|
||||
let bob = Creator::new(1_000);
|
||||
let bob_pubkey = bob.pubkey;
|
||||
let alice = Genesis::new(10_000, vec![bob]);
|
||||
let mut acc = Accountant::new(&alice, Some(2));
|
||||
|
@ -182,7 +182,7 @@ mod tests {
|
|||
fn test_invalid_transfer() {
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
let bob = Creator::new("Bob", 1_000);
|
||||
let bob = Creator::new(1_000);
|
||||
let bob_pubkey = bob.pubkey;
|
||||
let alice = Genesis::new(11_000, vec![bob]);
|
||||
let mut acc = Accountant::new(&alice, Some(2));
|
||||
|
|
|
@ -88,7 +88,7 @@ mod tests {
|
|||
fn test_accountant_stub() {
|
||||
let addr = "127.0.0.1:9000";
|
||||
let send_addr = "127.0.0.1:9001";
|
||||
let bob = Creator::new("Bob", 1_000);
|
||||
let bob = Creator::new(1_000);
|
||||
let bob_pubkey = bob.pubkey;
|
||||
let alice = Genesis::new(10_000, vec![bob]);
|
||||
let acc = Accountant::new(&alice, None);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
//extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
//use std::io::stdin;
|
||||
|
||||
fn main() {
|
||||
use silk::accountant_stub::AccountantStub;
|
||||
use silk::accountant_skel::AccountantSkel;
|
||||
|
@ -15,8 +18,12 @@ fn main() {
|
|||
let send_addr = "127.0.0.1:8001";
|
||||
|
||||
let txs = 200;
|
||||
|
||||
let gen = Genesis::new(txs, vec![]);
|
||||
let alice_keypair = generate_keypair();
|
||||
//let gen: Genesis = serde_json::from_reader(stdin()).unwrap();
|
||||
//let alice_keypair = gen.get_keypair();
|
||||
|
||||
let acc = Accountant::new(&gen, None);
|
||||
spawn(move || AccountantSkel::new(acc).serve(addr).unwrap());
|
||||
sleep(Duration::from_millis(30));
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
extern crate serde_json;
|
||||
extern crate silk;
|
||||
|
||||
use silk::genesis::{Creator, Genesis};
|
||||
use silk::event::{generate_keypair, get_pubkey};
|
||||
|
||||
fn main() {
|
||||
let alice = Creator {
|
||||
tokens: 200,
|
||||
pubkey: get_pubkey(&generate_keypair()),
|
||||
};
|
||||
let bob = Creator {
|
||||
tokens: 100,
|
||||
pubkey: get_pubkey(&generate_keypair()),
|
||||
};
|
||||
let creators = vec![alice, bob];
|
||||
let gen = Genesis::new(300, creators);
|
||||
println!("{}", serde_json::to_string(&gen).unwrap());
|
||||
}
|
|
@ -7,15 +7,13 @@ use untrusted::Input;
|
|||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Creator {
|
||||
pub name: String,
|
||||
pub pubkey: PublicKey,
|
||||
pub tokens: u64,
|
||||
}
|
||||
|
||||
impl Creator {
|
||||
pub fn new(name: &str, tokens: u64) -> Self {
|
||||
pub fn new(tokens: u64) -> Self {
|
||||
Creator {
|
||||
name: name.to_string(),
|
||||
pubkey: get_pubkey(&generate_keypair()),
|
||||
tokens,
|
||||
}
|
||||
|
@ -93,7 +91,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_create_creator() {
|
||||
assert_eq!(
|
||||
Genesis::new(100, vec![Creator::new("Satoshi", 42)])
|
||||
Genesis::new(100, vec![Creator::new(42)])
|
||||
.create_events()
|
||||
.len(),
|
||||
3
|
||||
|
|
|
@ -154,7 +154,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_genesis() {
|
||||
let entries = run_genesis(Genesis::new(100, vec![Creator::new("Satoshi", 42)]));
|
||||
let entries = run_genesis(Genesis::new(100, vec![Creator::new(42)]));
|
||||
assert!(verify_slice_u64(&entries, &entries[0].end_hash));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue