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

[feat] gva: block: add field pow_min

parent 76d96cb2
Branches
No related tags found
1 merge request!226Resolve "GVA: create skeleton & implement current Block request"
...@@ -77,6 +77,8 @@ pub trait BlockDocumentTrait { ...@@ -77,6 +77,8 @@ pub trait BlockDocumentTrait {
fn issuers_count(&self) -> usize; fn issuers_count(&self) -> usize;
/// Get block number /// Get block number
fn number(&self) -> BlockNumber; fn number(&self) -> BlockNumber;
/// Get common difficulty (PoW)
fn pow_min(&self) -> usize;
/// Get previous hash /// Get previous hash
fn previous_hash(&self) -> Option<Hash>; fn previous_hash(&self) -> Option<Hash>;
/// Get previous blockstamp /// Get previous blockstamp
...@@ -171,6 +173,12 @@ impl BlockDocumentTrait for BlockDocument { ...@@ -171,6 +173,12 @@ impl BlockDocumentTrait for BlockDocument {
} }
} }
#[inline] #[inline]
fn pow_min(&self) -> usize {
match self {
BlockDocument::V10(block) => block.pow_min(),
}
}
#[inline]
fn previous_blockstamp(&self) -> Blockstamp { fn previous_blockstamp(&self) -> Blockstamp {
match self { match self {
BlockDocument::V10(block) => block.previous_blockstamp(), BlockDocument::V10(block) => block.previous_blockstamp(),
......
...@@ -276,6 +276,9 @@ Transactions:{transactions} ...@@ -276,6 +276,9 @@ Transactions:{transactions}
fn number(&self) -> BlockNumber { fn number(&self) -> BlockNumber {
self.number self.number
} }
fn pow_min(&self) -> usize {
self.pow_min
}
fn previous_blockstamp(&self) -> Blockstamp { fn previous_blockstamp(&self) -> Blockstamp {
if self.number.0 > 0 { if self.number.0 > 0 {
Blockstamp { Blockstamp {
......
...@@ -54,4 +54,5 @@ type Block { ...@@ -54,4 +54,5 @@ type Block {
number: Int! number: Int!
hash: String!, hash: String!,
commonTime: DateTimeUtc! commonTime: DateTimeUtc!
powMin: Int!
} }
...@@ -30,6 +30,7 @@ pub struct Block { ...@@ -30,6 +30,7 @@ pub struct Block {
number: i32, number: i32,
hash: String, hash: String,
common_time: NaiveDateTime, common_time: NaiveDateTime,
pow_min: i32,
} }
impl super::super::BlockFields for Block { impl super::super::BlockFields for Block {
...@@ -56,6 +57,10 @@ impl super::super::BlockFields for Block { ...@@ -56,6 +57,10 @@ impl super::super::BlockFields for Block {
fn field_common_time(&self, _executor: &Executor<'_, Context>) -> FieldResult<&NaiveDateTime> { fn field_common_time(&self, _executor: &Executor<'_, Context>) -> FieldResult<&NaiveDateTime> {
Ok(&self.common_time) Ok(&self.common_time)
} }
fn field_pow_min(&self, _executor: &Executor<'_, Context>) -> FieldResult<&i32> {
Ok(&self.pow_min)
}
} }
impl Block { impl Block {
...@@ -71,6 +76,7 @@ impl Block { ...@@ -71,6 +76,7 @@ impl Block {
.unwrap_or_else(|| fatal_error!("DbBlock without hash.")) .unwrap_or_else(|| fatal_error!("DbBlock without hash."))
.to_string(), .to_string(),
common_time: NaiveDateTime::from_timestamp(db_block.block.common_time() as i64, 0), common_time: NaiveDateTime::from_timestamp(db_block.block.common_time() as i64, 0),
pow_min: db_block.block.pow_min() as i32,
} }
} }
} }
...@@ -72,6 +72,7 @@ mod tests { ...@@ -72,6 +72,7 @@ mod tests {
Hash::default(), Hash::default(),
); );
block.issuers = vec![pubkey('B')]; block.issuers = vec![pubkey('B')];
block.pow_min = 70;
Ok(Some(DbBlock { Ok(Some(DbBlock {
block: BlockDocument::V10(block), block: BlockDocument::V10(block),
expire_certs: None, expire_certs: None,
...@@ -96,7 +97,7 @@ mod tests { ...@@ -96,7 +97,7 @@ mod tests {
tests::test_gql_query( tests::test_gql_query(
schema, schema,
"{ block(number: 42) { commonTime, currency, hash, issuer, number, version } }", "{ block(number: 42) { commonTime, currency, hash, issuer, number, powMin, version } }",
json!({ json!({
"data": { "data": {
"block": { "block": {
...@@ -105,6 +106,7 @@ mod tests { ...@@ -105,6 +106,7 @@ mod tests {
"hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"number": 42, "number": 42,
"powMin": 70,
"version": 10 "version": 10
} }
} }
......
...@@ -60,6 +60,7 @@ mod tests { ...@@ -60,6 +60,7 @@ mod tests {
Hash::default(), Hash::default(),
); );
current_block.issuers = vec![pubkey('B')]; current_block.issuers = vec![pubkey('B')];
current_block.pow_min = 70;
Ok(Some(DbBlock { Ok(Some(DbBlock {
block: BlockDocument::V10(current_block), block: BlockDocument::V10(current_block),
expire_certs: None, expire_certs: None,
...@@ -70,7 +71,7 @@ mod tests { ...@@ -70,7 +71,7 @@ mod tests {
tests::test_gql_query( tests::test_gql_query(
schema, schema,
"{ current { commonTime, currency, hash, issuer, number, version } }", "{ current { commonTime, currency, hash, issuer, number, powMin, version } }",
json!({ json!({
"data": { "data": {
"current": { "current": {
...@@ -79,6 +80,7 @@ mod tests { ...@@ -79,6 +80,7 @@ mod tests {
"hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"number": 42, "number": 42,
"powMin": 70,
"version": 10 "version": 10
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment