Skip to content
Snippets Groups Projects
Commit 6cea4ab1 authored by jm's avatar jm
Browse files

wip [feat] gva: add humanTime field

parent c70030bc
No related tags found
No related merge requests found
......@@ -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(),
......
......@@ -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()))
}
......
......@@ -87,6 +87,7 @@ type Block {
number: Int!
hash: String!,
blockchainTime: DateTimeUtc!
humanTime: DateTimeUtc!
powMin: Int!
}
......
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment