diff --git a/src/accountant.rs b/src/accountant.rs index a531ff005e..b993965697 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -21,8 +21,8 @@ pub enum AccountingError { pub type Result = result::Result; pub struct Accountant { - pub historian: Historian, - pub balances: HashMap, + pub historian: Historian, + pub balances: HashMap, pub first_id: Sha256Hash, pub last_id: Sha256Hash, } @@ -30,7 +30,7 @@ pub struct Accountant { impl Accountant { pub fn new_from_entries(entries: I, ms_per_tick: Option) -> Self where - I: IntoIterator>, + I: IntoIterator>, { let mut entries = entries.into_iter(); @@ -39,7 +39,7 @@ impl Accountant { let entry0 = entries.next().unwrap(); let start_hash = entry0.id; - let hist = Historian::::new(&start_hash, ms_per_tick); + let hist = Historian::::new(&start_hash, ms_per_tick); let mut acc = Accountant { historian: hist, balances: HashMap::new(), @@ -74,7 +74,7 @@ impl Accountant { allow_deposits && from == to } - pub fn process_event(self: &mut Self, event: Event) -> Result<()> { + pub fn process_event(self: &mut Self, event: Event) -> Result<()> { if !verify_event(&event) { return Err(AccountingError::InvalidEvent); } @@ -95,7 +95,7 @@ impl Accountant { fn process_verified_event( self: &mut Self, - event: &Event, + event: &Event, allow_deposits: bool, ) -> Result<()> { if !reserve_signature(&mut self.historian.signatures, event) { @@ -122,7 +122,7 @@ impl Accountant { pub fn transfer( self: &mut Self, - n: u64, + n: i64, keypair: &Ed25519KeyPair, to: PublicKey, ) -> Result { @@ -139,7 +139,7 @@ impl Accountant { self.process_event(event).map(|_| sig) } - pub fn get_balance(self: &Self, pubkey: &PublicKey) -> Option { + pub fn get_balance(self: &Self, pubkey: &PublicKey) -> Option { self.balances.get(pubkey).map(|x| *x) } } diff --git a/src/accountant_skel.rs b/src/accountant_skel.rs index 4666e97edf..069b5cd851 100644 --- a/src/accountant_skel.rs +++ b/src/accountant_skel.rs @@ -14,7 +14,7 @@ pub enum Request { Transfer { from: PublicKey, to: PublicKey, - val: u64, + val: i64, last_id: Sha256Hash, sig: Signature, }, @@ -31,8 +31,8 @@ pub enum Request { #[derive(Serialize, Deserialize, Debug)] pub enum Response { - Balance { key: PublicKey, val: Option }, - Entries { entries: Vec> }, + Balance { key: PublicKey, val: Option }, + Entries { entries: Vec> }, Id { id: Sha256Hash, is_last: bool }, } diff --git a/src/accountant_stub.rs b/src/accountant_stub.rs index 8016620a97..8e62addd36 100644 --- a/src/accountant_stub.rs +++ b/src/accountant_stub.rs @@ -29,7 +29,7 @@ impl AccountantStub { &self, from: PublicKey, to: PublicKey, - val: u64, + val: i64, last_id: Sha256Hash, sig: Signature, ) -> io::Result { @@ -46,7 +46,7 @@ impl AccountantStub { pub fn transfer( &self, - n: u64, + n: i64, keypair: &Ed25519KeyPair, to: PublicKey, last_id: &Sha256Hash, @@ -57,7 +57,7 @@ impl AccountantStub { .map(|_| sig) } - pub fn get_balance(&self, pubkey: &PublicKey) -> io::Result> { + pub fn get_balance(&self, pubkey: &PublicKey) -> io::Result> { let req = Request::GetBalance { key: *pubkey }; let data = serialize(&req).expect("serialize GetBalance"); self.socket.send_to(&data, &self.addr)?; diff --git a/src/bin/genesis-block.rs b/src/bin/genesis-block.rs index ce3e8e5898..dc620ff2e1 100644 --- a/src/bin/genesis-block.rs +++ b/src/bin/genesis-block.rs @@ -5,13 +5,13 @@ extern crate serde_json; extern crate silk; use silk::genesis::Genesis; -use silk::log::verify_slice_u64; +use silk::log::verify_slice_i64; use std::io::stdin; fn main() { let gen: Genesis = serde_json::from_reader(stdin()).unwrap(); let entries = gen.create_entries(); - verify_slice_u64(&entries, &entries[0].id); + verify_slice_i64(&entries, &entries[0].id); for x in entries { println!("{}", serde_json::to_string(&x).unwrap()); } diff --git a/src/genesis.rs b/src/genesis.rs index df331532d2..a30f35883a 100644 --- a/src/genesis.rs +++ b/src/genesis.rs @@ -9,11 +9,11 @@ use untrusted::Input; #[derive(Serialize, Deserialize, Debug)] pub struct Creator { pub pubkey: PublicKey, - pub tokens: u64, + pub tokens: i64, } impl Creator { - pub fn new(tokens: u64) -> Self { + pub fn new(tokens: i64) -> Self { Creator { pubkey: get_pubkey(&generate_keypair()), tokens, @@ -24,12 +24,12 @@ impl Creator { #[derive(Serialize, Deserialize, Debug)] pub struct Genesis { pub pkcs8: Vec, - pub tokens: u64, + pub tokens: i64, pub creators: Vec, } impl Genesis { - pub fn new(tokens: u64, creators: Vec) -> Self { + pub fn new(tokens: i64, creators: Vec) -> Self { let rnd = SystemRandom::new(); let pkcs8 = Ed25519KeyPair::generate_pkcs8(&rnd).unwrap().to_vec(); println!("{:?}", pkcs8); @@ -52,7 +52,7 @@ impl Genesis { get_pubkey(&self.get_keypair()) } - pub fn create_transaction(&self, data: u64, to: &PublicKey) -> Event { + pub fn create_transaction(&self, data: i64, to: &PublicKey) -> Event { let last_id = self.get_seed(); let from = self.get_pubkey(); let sig = sign_transaction_data(&data, &self.get_keypair(), to, &last_id); @@ -65,7 +65,7 @@ impl Genesis { } } - pub fn create_events(&self) -> Vec> { + pub fn create_events(&self) -> Vec> { let pubkey = self.get_pubkey(); let event0 = Event::Tick; let event1 = self.create_transaction(self.tokens, &pubkey); @@ -79,7 +79,7 @@ impl Genesis { events } - pub fn create_entries(&self) -> Vec> { + pub fn create_entries(&self) -> Vec> { create_entries(&self.get_seed(), self.create_events()) } } @@ -87,7 +87,7 @@ impl Genesis { #[cfg(test)] mod tests { use super::*; - use log::verify_slice_u64; + use log::verify_slice_i64; #[test] fn test_create_events() { @@ -114,12 +114,12 @@ mod tests { #[test] fn test_verify_entries() { let entries = Genesis::new(100, vec![]).create_entries(); - assert!(verify_slice_u64(&entries, &entries[0].id)); + assert!(verify_slice_i64(&entries, &entries[0].id)); } #[test] fn test_verify_entries_with_transactions() { let entries = Genesis::new(100, vec![Creator::new(42)]).create_entries(); - assert!(verify_slice_u64(&entries, &entries[0].id)); + assert!(verify_slice_i64(&entries, &entries[0].id)); } } diff --git a/src/log.rs b/src/log.rs index 3a254fd159..8d133b5b3c 100644 --- a/src/log.rs +++ b/src/log.rs @@ -130,7 +130,7 @@ pub fn verify_slice(events: &[Entry], start_hash: &Sha256Hash) -> bo } /// Verifies the hashes and counts of a slice of events are all consistent. -pub fn verify_slice_u64(events: &[Entry], start_hash: &Sha256Hash) -> bool { +pub fn verify_slice_i64(events: &[Entry], start_hash: &Sha256Hash) -> bool { let genesis = [Entry::new_tick(Default::default(), start_hash)]; let event_pairs = genesis.par_iter().chain(events).zip(events); event_pairs.all(|(x0, x1)| verify_entry(&x1, &x0.id))