diff --git a/lib/dubp/block-doc/src/block.rs b/lib/dubp/block-doc/src/block.rs index 22ae22a0f745a3cb867c8a7f3ca285eabc8c907b..443d4a5c63345209ce189c5ca1f884caeba802c5 100644 --- a/lib/dubp/block-doc/src/block.rs +++ b/lib/dubp/block-doc/src/block.rs @@ -49,6 +49,8 @@ pub enum VerifyBlockHashError { pub trait BlockDocumentTrait { /// Common time in block (also known as 'blockchain time') fn common_time(&self) -> u64; + /// Human time + fn human_time(&self) -> u64; /// Compute hash fn compute_hash(&self) -> BlockHash; /// Compute inner hash @@ -175,6 +177,12 @@ impl BlockDocumentTrait for BlockDocument { } } #[inline] + fn human_time(&self) -> u64 { + match self { + BlockDocument::V10(block) => block.human_time(), + } + } + #[inline] fn number(&self) -> BlockNumber { match self { BlockDocument::V10(block) => block.number(), diff --git a/lib/dubp/block-doc/src/block/v10.rs b/lib/dubp/block-doc/src/block/v10.rs index 807a34de443d707d4917cd4fb7df335d2339d13c..13e7438162998e1fb06454e6868b387eb5d69382 100644 --- a/lib/dubp/block-doc/src/block/v10.rs +++ b/lib/dubp/block-doc/src/block/v10.rs @@ -107,6 +107,13 @@ impl BlockDocumentTrait for BlockDocumentV10 { fn common_time(&self) -> u64 { self.median_time } + fn human_time(&self) -> u64 { + if let Some(parameters) = self.parameters { + self.median_time + parameters.median_time_blocks as u64 * parameters.avg_gen_time / 2 + } else { + 0 + } + } fn compute_hash(&self) -> BlockHash { BlockHash(Hash::compute_str(&self.compute_will_hashed_string())) } diff --git a/lib/modules/gva/resources/schema.gql b/lib/modules/gva/resources/schema.gql index 5779e610cf12bb9516fe9658f03245faa36dbce9..6d2ef3a36f59b59e50fc6970c22dc6646dd738f6 100644 --- a/lib/modules/gva/resources/schema.gql +++ b/lib/modules/gva/resources/schema.gql @@ -87,6 +87,7 @@ type Block { number: Int! hash: String!, blockchainTime: DateTimeUtc! + humanTime: DateTimeUtc! powMin: Int! } diff --git a/lib/modules/gva/src/schema/entities/block.rs b/lib/modules/gva/src/schema/entities/block.rs index a0e3aeed47129ee01d50f37eaf92ad0e06f9ba1e..8301e43862256abeec8a322923b802974f87bd1f 100644 --- a/lib/modules/gva/src/schema/entities/block.rs +++ b/lib/modules/gva/src/schema/entities/block.rs @@ -36,6 +36,7 @@ pub struct Block { number: i32, hash: String, blockchain_time: NaiveDateTime, + human_time: NaiveDateTime, pow_min: i32, } @@ -68,6 +69,7 @@ impl Block { .unwrap_or_else(|| fatal_error!("BlockDb without hash.")) .to_string(), blockchain_time: NaiveDateTime::from_timestamp(block_db.block.common_time() as i64, 0), + human_time: NaiveDateTime::from_timestamp(block_db.block.human_time() as i64, 0), pow_min: block_db.block.pow_min() as i32, }) } @@ -109,6 +111,13 @@ impl super::super::BlockFields for Block { Ok(&self.blockchain_time) } #[inline] + fn field_human_time( + &self, + _executor: &Executor<'_, QueryContext>, + ) -> FieldResult<&NaiveDateTime> { + Ok(&self.human_time) + } + #[inline] fn field_pow_min(&self, _executor: &Executor<'_, QueryContext>) -> FieldResult<&i32> { Ok(&self.pow_min) }