1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::prelude::StateMutationResult;
use holo_hash::AgentPubKey;
use holochain_sqlite::rusqlite::OptionalExtension;
use holochain_sqlite::rusqlite::{named_params, Transaction};
use holochain_zome_types::Timestamp;
pub fn is_chain_locked(
txn: &Transaction,
lock: &[u8],
author: &AgentPubKey,
) -> StateMutationResult<bool> {
let mut lock = lock.to_vec();
lock.extend(author.get_raw_39());
match txn
.query_row(
"
SELECT 1
FROM ChainLock
WHERE expires_at_timestamp >= :now
AND lock != :lock
AND author = :author
LIMIT 1
",
named_params! {
":lock": lock,
":author": author,
":now": holochain_zome_types::Timestamp::now()
},
|row| row.get::<_, u32>(0),
)
.optional()?
{
Some(_) => Ok(true),
None => Ok(false),
}
}
pub fn is_lock_expired(
txn: &Transaction,
lock: &[u8],
author: &AgentPubKey,
) -> StateMutationResult<bool> {
let mut lock = lock.to_vec();
lock.extend(author.get_raw_39());
let r = txn
.query_row(
"
SELECT expires_at_timestamp
FROM ChainLock
WHERE
lock = :lock
",
named_params! {
":lock": lock,
},
|row| {
Ok(row.get::<_, Timestamp>("expires_at_timestamp")?
< holochain_zome_types::Timestamp::now())
},
)
.optional()?;
Ok(r.unwrap_or(true))
}