diff --git a/lib/dubp/block-doc/src/block.rs b/lib/dubp/block-doc/src/block.rs index 0364e45138ed949b30964f0a5e190066bf74f6b0..7ca98b4a46ef0d0be5cda7c3f063f5c270c84793 100644 --- a/lib/dubp/block-doc/src/block.rs +++ b/lib/dubp/block-doc/src/block.rs @@ -77,6 +77,8 @@ pub trait BlockDocumentTrait { fn issuers_count(&self) -> usize; /// Get block number fn number(&self) -> BlockNumber; + /// Get common difficulty (PoW) + fn pow_min(&self) -> usize; /// Get previous hash fn previous_hash(&self) -> Option<Hash>; /// Get previous blockstamp @@ -171,6 +173,12 @@ impl BlockDocumentTrait for BlockDocument { } } #[inline] + fn pow_min(&self) -> usize { + match self { + BlockDocument::V10(block) => block.pow_min(), + } + } + #[inline] fn previous_blockstamp(&self) -> Blockstamp { match self { BlockDocument::V10(block) => block.previous_blockstamp(), diff --git a/lib/dubp/block-doc/src/block/v10.rs b/lib/dubp/block-doc/src/block/v10.rs index cbf00fbfd867a79e0e7aac104d2755b1fe61a6de..893807ce6059b5b2f7a67d86f87ac39fc274d08f 100644 --- a/lib/dubp/block-doc/src/block/v10.rs +++ b/lib/dubp/block-doc/src/block/v10.rs @@ -276,6 +276,9 @@ Transactions:{transactions} fn number(&self) -> BlockNumber { self.number } + fn pow_min(&self) -> usize { + self.pow_min + } fn previous_blockstamp(&self) -> Blockstamp { if self.number.0 > 0 { Blockstamp { diff --git a/lib/modules/gva/resources/schema.gql b/lib/modules/gva/resources/schema.gql index f3808c35e9be23189c30f66fac0d7952322a4f7c..163060c7192ce045a879c8cb5da0f7ec363394ef 100644 --- a/lib/modules/gva/resources/schema.gql +++ b/lib/modules/gva/resources/schema.gql @@ -54,4 +54,5 @@ type Block { number: Int! hash: String!, commonTime: DateTimeUtc! + powMin: Int! } diff --git a/lib/modules/gva/src/schema/entities/block.rs b/lib/modules/gva/src/schema/entities/block.rs index 3a2900a3b542538ff5bd724b75d52dae5549fecf..fee7d2480f536c147701c151a51549e82d1f8bd0 100644 --- a/lib/modules/gva/src/schema/entities/block.rs +++ b/lib/modules/gva/src/schema/entities/block.rs @@ -30,6 +30,7 @@ pub struct Block { number: i32, hash: String, common_time: NaiveDateTime, + pow_min: i32, } 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> { Ok(&self.common_time) } + + fn field_pow_min(&self, _executor: &Executor<'_, Context>) -> FieldResult<&i32> { + Ok(&self.pow_min) + } } impl Block { @@ -71,6 +76,7 @@ impl Block { .unwrap_or_else(|| fatal_error!("DbBlock without hash.")) .to_string(), common_time: NaiveDateTime::from_timestamp(db_block.block.common_time() as i64, 0), + pow_min: db_block.block.pow_min() as i32, } } } diff --git a/lib/modules/gva/src/schema/queries/block.rs b/lib/modules/gva/src/schema/queries/block.rs index 73547478d374d493dd978374d0b5d1a655ff1161..4ad02dd83c33cefd98b8e0167b711fad5fb3c525 100644 --- a/lib/modules/gva/src/schema/queries/block.rs +++ b/lib/modules/gva/src/schema/queries/block.rs @@ -72,6 +72,7 @@ mod tests { Hash::default(), ); block.issuers = vec![pubkey('B')]; + block.pow_min = 70; Ok(Some(DbBlock { block: BlockDocument::V10(block), expire_certs: None, @@ -96,7 +97,7 @@ mod tests { tests::test_gql_query( schema, - "{ block(number: 42) { commonTime, currency, hash, issuer, number, version } }", + "{ block(number: 42) { commonTime, currency, hash, issuer, number, powMin, version } }", json!({ "data": { "block": { @@ -105,6 +106,7 @@ mod tests { "hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "number": 42, + "powMin": 70, "version": 10 } } diff --git a/lib/modules/gva/src/schema/queries/current.rs b/lib/modules/gva/src/schema/queries/current.rs index 309bc56df99fbf5abf9e999e842d2f87f4e36ba2..771e750ed61351dd8cc89cfd5a277d24eb2b60d0 100644 --- a/lib/modules/gva/src/schema/queries/current.rs +++ b/lib/modules/gva/src/schema/queries/current.rs @@ -60,6 +60,7 @@ mod tests { Hash::default(), ); current_block.issuers = vec![pubkey('B')]; + current_block.pow_min = 70; Ok(Some(DbBlock { block: BlockDocument::V10(current_block), expire_certs: None, @@ -70,7 +71,7 @@ mod tests { tests::test_gql_query( schema, - "{ current { commonTime, currency, hash, issuer, number, version } }", + "{ current { commonTime, currency, hash, issuer, number, powMin, version } }", json!({ "data": { "current": { @@ -79,6 +80,7 @@ mod tests { "hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "number": 42, + "powMin": 70, "version": 10 } }