Skip to content
Snippets Groups Projects
Commit fe6c615f authored by Éloïs's avatar Éloïs
Browse files

[ref] gva: move op get bc time into DbReader

parent 60f20c44
No related branches found
No related tags found
1 merge request!1337Ref/isolate gva
...@@ -75,4 +75,15 @@ impl DbsReader { ...@@ -75,4 +75,15 @@ impl DbsReader {
.uds_reval() .uds_reval()
.iter(.., |it| it.reverse().values().map_ok(|v| v.0).next_res()) .iter(.., |it| it.reverse().values().map_ok(|v| v.0).next_res())
} }
pub fn get_blockchain_time<GvaDb: GvaV1DbReadable>(
&self,
gva_db: &GvaDb,
block_number: BlockNumber,
) -> anyhow::Result<u64> {
Ok(gva_db
.blockchain_time()
.get(&U32BE(block_number.0))?
.unwrap_or_else(|| unreachable!()))
}
} }
...@@ -355,6 +355,13 @@ mod tests { ...@@ -355,6 +355,13 @@ mod tests {
&self, &self,
bc_db: &BcDb, bc_db: &BcDb,
) -> KvResult<Option<SourceAmount>>; ) -> KvResult<Option<SourceAmount>>;
fn get_blockchain_time<
GvaDb: 'static + GvaV1DbReadable,
>(
&self,
gva_db: &GvaDb,
block_number: BlockNumber,
) -> anyhow::Result<u64>;
} }
} }
pub type DbsReader = duniter_dbs::kv_typed::prelude::Arc<MockDbsReader>; pub type DbsReader = duniter_dbs::kv_typed::prelude::Arc<MockDbsReader>;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
use crate::*; use crate::*;
use async_graphql::connection::*; use async_graphql::connection::*;
use duniter_dbs::{bc_v2::BcV2DbReadable, GvaV1DbReadable}; use duniter_dbs::bc_v2::BcV2DbReadable;
use duniter_gva_dbs_reader::{uds_of_pubkey::UdsWithSum, PagedData}; use duniter_gva_dbs_reader::{uds_of_pubkey::UdsWithSum, PagedData};
#[derive(Default)] #[derive(Default)]
...@@ -54,7 +54,7 @@ impl UdsQuery { ...@@ -54,7 +54,7 @@ impl UdsQuery {
let pubkey = PublicKey::from_base58(&pubkey)?; let pubkey = PublicKey::from_base58(&pubkey)?;
let data = ctx.data::<SchemaData>()?; let data = ctx.data::<SchemaData>()?;
//let dbs_reader = data.dbs_reader(); let dbs_reader = data.dbs_reader();
let ( let (
PagedData { PagedData {
...@@ -88,14 +88,10 @@ impl UdsQuery { ...@@ -88,14 +88,10 @@ impl UdsQuery {
) )
} }
}?; }?;
let mut times = Vec::with_capacity(paged_data.data.uds.len()); let mut times = Vec::with_capacity(paged_data.data.uds.len());
for (bn, _sa) in &paged_data.data.uds { for (bn, _sa) in &paged_data.data.uds {
times.push( times.push(dbs_reader.get_blockchain_time(&dbs.gva_db, *bn)?);
dbs.gva_db
.blockchain_time()
.get(&U32BE(bn.0))?
.unwrap_or_else(|| unreachable!()),
);
} }
Ok::<_, anyhow::Error>((paged_data, times)) Ok::<_, anyhow::Error>((paged_data, times))
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment