diff --git a/Cargo.lock b/Cargo.lock index 41cceb93e..6676830bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,7 @@ dependencies = [ [[package]] name = "silk" -version = "0.3.1" +version = "0.3.2" dependencies = [ "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 6c0911ab1..f5d6b216d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "silk" description = "A silky smooth implementation of the Loom architecture" -version = "0.3.1" +version = "0.3.2" documentation = "https://docs.rs/silk" homepage = "http://loomprotocol.com/" repository = "https://github.com/loomprotocol/silk" diff --git a/src/accountant.rs b/src/accountant.rs index 97985645e..d63672adf 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -119,6 +119,21 @@ impl Accountant { } } + // TODO: Move this to transaction.rs + fn all_satisfied(&self, conds: &[Condition]) -> bool { + let mut satisfied = true; + for cond in conds { + if let &Condition::Timestamp(dt) = cond { + if dt > self.last_time { + satisfied = false; + } + } else { + satisfied = false; + } + } + satisfied + } + fn process_verified_transaction( self: &mut Self, tr: &Transaction, @@ -138,7 +153,7 @@ impl Accountant { } } - if !tr.if_all.is_empty() { + if !self.all_satisfied(&tr.if_all) { self.pending.insert(tr.sig, tr.clone()); return Ok(()); } @@ -349,6 +364,23 @@ mod tests { assert_ne!(acc.get_balance(&bob_pubkey), Some(2)); } + #[test] + fn test_transfer_after_date() { + let alice = Mint::new(1); + let mut acc = Accountant::new(&alice, Some(2)); + let alice_keypair = alice.keypair(); + let bob_pubkey = KeyPair::new().pubkey(); + let dt = Utc::now(); + acc.process_verified_timestamp(alice.pubkey(), dt).unwrap(); + + // It's now past now, so this transfer should be processed immediately. + acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt) + .unwrap(); + + assert_eq!(acc.get_balance(&alice.pubkey()), Some(0)); + assert_eq!(acc.get_balance(&bob_pubkey), Some(1)); + } + #[test] fn test_cancel_transfer() { let alice = Mint::new(1);