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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! `DbRead<Dht>` API for the DHT-sync cross-table reads.
use super::super::inner::sync_queries::{self, ArcBounds};
use crate::handles::DbRead;
use crate::kind::Dht;
use crate::models::dht::{
K2ChainOpForWireRow, K2OpHashRow, K2OpIdSinceRow, K2OpPresentRow, K2WarrantForWireRow,
};
impl DbRead<Dht> {
/// `(hash, basis, size)` for every integrated, locally-validated op
/// whose authored timestamp falls in `[t_start_micros, t_end_micros)`.
pub async fn op_hashes_in_time_slice(
&self,
arc_start: u32,
arc_end: u32,
t_start_micros: i64,
t_end_micros: i64,
) -> sqlx::Result<Vec<K2OpHashRow>> {
sync_queries::op_hashes_in_time_slice(
self.pool(),
ArcBounds {
start: arc_start,
end: arc_end,
},
t_start_micros,
t_end_micros,
)
.await
}
/// Up to `limit` ops with `when_integrated >= t_min_micros`, ordered by
/// integration time ascending. K2 gossip "since" cursor.
pub async fn op_ids_since_time_batch(
&self,
arc_start: u32,
arc_end: u32,
t_min_micros: i64,
limit: u32,
) -> sqlx::Result<Vec<K2OpIdSinceRow>> {
sync_queries::op_ids_since_time_batch(
self.pool(),
ArcBounds {
start: arc_start,
end: arc_end,
},
t_min_micros,
limit,
)
.await
}
/// Subset of `op_hashes` we hold in limbo or as locally-validated
/// integrated ops (cache-only copies excluded), with their basis hashes.
pub async fn check_op_hashes_present(
&self,
op_hashes: &[Vec<u8>],
) -> sqlx::Result<Vec<K2OpPresentRow>> {
sync_queries::check_op_hashes_present(self.pool(), op_hashes).await
}
/// Full chain-op rows (joined with `Action` and optional `Entry`) for
/// the given op hashes, filtered to `locally_validated = 1`.
pub async fn get_chain_ops_for_wire(
&self,
op_hashes: &[Vec<u8>],
) -> sqlx::Result<Vec<K2ChainOpForWireRow>> {
sync_queries::get_chain_ops_for_wire(self.pool(), op_hashes).await
}
/// Full warrant rows for the given op hashes.
pub async fn get_warrants_for_wire(
&self,
op_hashes: &[Vec<u8>],
) -> sqlx::Result<Vec<K2WarrantForWireRow>> {
sync_queries::get_warrants_for_wire(self.pool(), op_hashes).await
}
/// Earliest authored timestamp across both tables within the arc, or
/// `None` if no rows match.
pub async fn earliest_authored_timestamp_in_arc(
&self,
arc_start: u32,
arc_end: u32,
) -> sqlx::Result<Option<i64>> {
sync_queries::earliest_authored_timestamp_in_arc(
self.pool(),
ArcBounds {
start: arc_start,
end: arc_end,
},
)
.await
}
/// Total count of every integrated op + warrant (no `locally_validated`
/// filter).
pub async fn count_integrated_ops(&self) -> sqlx::Result<i64> {
sync_queries::count_integrated_ops(self.pool()).await
}
}