2018-02-28 10:07:54 -07:00
|
|
|
extern crate silk;
|
|
|
|
|
|
|
|
fn main() {
|
2018-02-28 14:16:50 -07:00
|
|
|
use silk::accountant_stub::AccountantStub;
|
2018-03-01 12:23:27 -07:00
|
|
|
use std::time::Instant;
|
|
|
|
use std::net::UdpSocket;
|
2018-02-28 14:16:50 -07:00
|
|
|
use silk::log::{generate_keypair, get_pubkey};
|
|
|
|
|
|
|
|
let addr = "127.0.0.1:8000";
|
2018-03-01 12:23:27 -07:00
|
|
|
let send_addr = "127.0.0.1:8001";
|
|
|
|
let socket = UdpSocket::bind(send_addr).unwrap();
|
|
|
|
let mut acc = AccountantStub::new(addr, socket);
|
2018-02-28 10:07:54 -07:00
|
|
|
let alice_keypair = generate_keypair();
|
|
|
|
let bob_keypair = generate_keypair();
|
2018-03-01 12:23:27 -07:00
|
|
|
let alice_pubkey = get_pubkey(&alice_keypair);
|
|
|
|
let bob_pubkey = get_pubkey(&bob_keypair);
|
2018-02-28 19:33:28 -07:00
|
|
|
let txs = 10_000;
|
|
|
|
println!("Depositing {} units in Alice's account...", txs);
|
2018-03-01 12:23:27 -07:00
|
|
|
let sig = acc.deposit(txs, &alice_keypair).unwrap();
|
|
|
|
acc.wait_on_signature(&sig).unwrap();
|
|
|
|
assert_eq!(acc.get_balance(&alice_pubkey).unwrap(), txs);
|
2018-02-28 18:04:35 -07:00
|
|
|
println!("Done.");
|
2018-02-28 10:07:54 -07:00
|
|
|
|
2018-02-28 19:33:28 -07:00
|
|
|
println!("Transferring 1 unit {} times...", txs);
|
2018-03-01 12:23:27 -07:00
|
|
|
let now = Instant::now();
|
|
|
|
let mut sig = sig;
|
|
|
|
for i in 0..txs {
|
|
|
|
sig = acc.transfer(1, &alice_keypair, bob_pubkey).unwrap();
|
|
|
|
if i % 200 == 1 {
|
|
|
|
acc.wait_on_signature(&sig).unwrap();
|
|
|
|
}
|
2018-02-28 19:33:28 -07:00
|
|
|
}
|
2018-03-01 12:23:27 -07:00
|
|
|
println!("Waiting for last transaction to be confirmed...",);
|
|
|
|
acc.wait_on_signature(&sig).unwrap();
|
2018-02-28 10:07:54 -07:00
|
|
|
|
2018-03-01 12:23:27 -07:00
|
|
|
let duration = now.elapsed();
|
|
|
|
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);
|
2018-02-28 19:33:28 -07:00
|
|
|
println!(
|
|
|
|
"Alice's Final Balance {}",
|
|
|
|
acc.get_balance(&alice_pubkey).unwrap()
|
|
|
|
);
|
|
|
|
|
|
|
|
println!(
|
|
|
|
"Bob's Final Balance {}",
|
|
|
|
acc.get_balance(&bob_pubkey).unwrap()
|
|
|
|
);
|
2018-02-28 10:07:54 -07:00
|
|
|
}
|