Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 8d17aed

Browse files
committed
Process timestamps as they are added
1 parent 7ef8d5d commit 8d17aed

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "silk"
33
description = "A silky smooth implementation of the Loom architecture"
4-
version = "0.3.1"
4+
version = "0.3.2"
55
documentation = "https://docs.rs/silk"
66
homepage = "http://loomprotocol.com/"
77
repository = "https://github.com/loomprotocol/silk"

src/accountant.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ impl Accountant {
119119
}
120120
}
121121

122+
// TODO: Move this to transaction.rs
123+
fn all_satisfied(&self, conds: &[Condition]) -> bool {
124+
let mut satisfied = true;
125+
for cond in conds {
126+
if let &Condition::Timestamp(dt) = cond {
127+
if dt > self.last_time {
128+
satisfied = false;
129+
}
130+
} else {
131+
satisfied = false;
132+
}
133+
}
134+
satisfied
135+
}
136+
122137
fn process_verified_transaction(
123138
self: &mut Self,
124139
tr: &Transaction<i64>,
@@ -138,7 +153,7 @@ impl Accountant {
138153
}
139154
}
140155

141-
if !tr.if_all.is_empty() {
156+
if !self.all_satisfied(&tr.if_all) {
142157
self.pending.insert(tr.sig, tr.clone());
143158
return Ok(());
144159
}
@@ -349,6 +364,23 @@ mod tests {
349364
assert_ne!(acc.get_balance(&bob_pubkey), Some(2));
350365
}
351366

367+
#[test]
368+
fn test_transfer_after_date() {
369+
let alice = Mint::new(1);
370+
let mut acc = Accountant::new(&alice, Some(2));
371+
let alice_keypair = alice.keypair();
372+
let bob_pubkey = KeyPair::new().pubkey();
373+
let dt = Utc::now();
374+
acc.process_verified_timestamp(alice.pubkey(), dt).unwrap();
375+
376+
// It's now past now, so this transfer should be processed immediately.
377+
acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt)
378+
.unwrap();
379+
380+
assert_eq!(acc.get_balance(&alice.pubkey()), Some(0));
381+
assert_eq!(acc.get_balance(&bob_pubkey), Some(1));
382+
}
383+
352384
#[test]
353385
fn test_cancel_transfer() {
354386
let alice = Mint::new(1);

0 commit comments

Comments
 (0)