use super::super::inner::sync_queries::{self, ArcBounds};
use crate::handles::DbRead;
use crate::kind::Dht;
use crate::models::dht::{
DumpChainOpRow, K2ChainOpForWireRow, K2OpHashRow, K2OpIdSinceRow, K2OpPresentRow,
K2WarrantForWireRow,
};
use holo_hash::AgentPubKey;
#[cfg(any(test, feature = "inspection"))]
use holo_hash::{AnyLinkableHash, DhtOpHash};
impl DbRead<Dht> {
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
}
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
}
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
}
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
}
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
}
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
}
pub async fn count_integrated_ops(&self) -> sqlx::Result<u64> {
Ok(sync_queries::count_integrated_ops(self.pool()).await? as u64)
}
pub async fn limbo_state_counts(&self) -> sqlx::Result<(i64, i64, i64)> {
sync_queries::limbo_state_counts(self.pool()).await
}
#[cfg(any(test, feature = "inspection"))]
pub async fn count_valid_integrated_ops(&self) -> sqlx::Result<u64> {
Ok(sync_queries::count_valid_integrated_ops(self.pool()).await? as u64)
}
#[cfg(any(test, feature = "inspection"))]
pub async fn count_valid_not_integrated_ops(&self) -> sqlx::Result<u64> {
Ok(sync_queries::count_valid_not_integrated_ops(self.pool()).await? as u64)
}
#[cfg(any(test, feature = "inspection"))]
pub async fn count_pending_ops_for_author(&self, author: &AgentPubKey) -> sqlx::Result<u64> {
Ok(sync_queries::count_pending_ops_for_author(self.pool(), author).await? as u64)
}
#[cfg(any(test, feature = "inspection"))]
pub async fn rejected_integrated_op_hashes(&self) -> sqlx::Result<Vec<DhtOpHash>> {
Ok(sync_queries::rejected_integrated_op_hashes(self.pool())
.await?
.into_iter()
.map(DhtOpHash::from_raw_36)
.collect())
}
#[cfg(any(test, feature = "inspection"))]
pub async fn count_all_ops(&self) -> sqlx::Result<u64> {
Ok(sync_queries::count_all_ops(self.pool()).await? as u64)
}
#[cfg(any(test, feature = "inspection"))]
pub async fn op_requires_receipt(&self, op_hash: &DhtOpHash) -> sqlx::Result<bool> {
sync_queries::op_requires_receipt(self.pool(), op_hash).await
}
#[cfg(any(test, feature = "inspection"))]
pub async fn limbo_op_exists(&self, op_hash: &DhtOpHash) -> sqlx::Result<bool> {
sync_queries::limbo_op_exists(self.pool(), op_hash).await
}
#[cfg(any(test, feature = "inspection"))]
pub async fn limbo_op_hashes_requiring_receipt(&self) -> sqlx::Result<Vec<DhtOpHash>> {
Ok(sync_queries::limbo_op_hashes_requiring_receipt(self.pool())
.await?
.into_iter()
.map(DhtOpHash::from_raw_36)
.collect())
}
#[cfg(any(test, feature = "inspection"))]
pub async fn get_ops_at_basis(&self, basis: &AnyLinkableHash) -> sqlx::Result<Vec<DhtOpHash>> {
Ok(sync_queries::get_ops_at_basis(self.pool(), basis)
.await?
.into_iter()
.map(DhtOpHash::from_raw_36)
.collect())
}
#[cfg(any(test, feature = "inspection"))]
pub async fn count_entries(&self) -> sqlx::Result<u64> {
Ok(sync_queries::count_entries(self.pool()).await? as u64)
}
pub async fn integrated_chain_ops_for_dump(
&self,
after: Option<(i64, &[u8])>,
) -> sqlx::Result<Vec<DumpChainOpRow>> {
sync_queries::integrated_chain_ops_for_dump(self.pool(), after).await
}
pub async fn limbo_chain_ops_for_dump(
&self,
ready: bool,
) -> sqlx::Result<Vec<K2ChainOpForWireRow>> {
sync_queries::limbo_chain_ops_for_dump(self.pool(), ready).await
}
pub async fn ops_to_publish_for_wire(
&self,
author: &AgentPubKey,
) -> sqlx::Result<Vec<K2ChainOpForWireRow>> {
sync_queries::ops_to_publish_for_wire(self.pool(), author).await
}
pub async fn integrated_warrants_for_dump(&self) -> sqlx::Result<Vec<K2WarrantForWireRow>> {
sync_queries::integrated_warrants_for_dump(self.pool()).await
}
}