From a8c88aa925ff6f0b84528eb660990f05f8fcb41d Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Fri, 6 Mar 2020 14:00:59 +0100 Subject: [PATCH] [feat] gva: block: add field monetaryMass --- lib/dubp/block-doc/src/block.rs | 8 ++++++++ lib/dubp/block-doc/src/block/v10.rs | 3 +++ lib/modules/gva/resources/schema.gql | 1 + lib/modules/gva/src/schema/entities/block.rs | 6 ++++++ lib/modules/gva/src/schema/queries/block.rs | 4 +++- 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/dubp/block-doc/src/block.rs b/lib/dubp/block-doc/src/block.rs index 136f8ada..8771259c 100644 --- a/lib/dubp/block-doc/src/block.rs +++ b/lib/dubp/block-doc/src/block.rs @@ -78,6 +78,8 @@ pub trait BlockDocumentTrait { fn issuers_count(&self) -> UsizeSer32; /// Get number of members in wot fn members_count(&self) -> UsizeSer32; + /// Get amount of monetary mass + fn monetary_mass(&self) -> u64; /// Get block number fn number(&self) -> BlockNumber; /// Get common difficulty (PoW) @@ -170,6 +172,12 @@ impl BlockDocumentTrait for BlockDocument { } } #[inline] + fn monetary_mass(&self) -> u64 { + match self { + BlockDocument::V10(block) => block.monetary_mass(), + } + } + #[inline] fn common_time(&self) -> u64 { match self { BlockDocument::V10(block) => block.common_time(), diff --git a/lib/dubp/block-doc/src/block/v10.rs b/lib/dubp/block-doc/src/block/v10.rs index 024f1df2..4441db2f 100644 --- a/lib/dubp/block-doc/src/block/v10.rs +++ b/lib/dubp/block-doc/src/block/v10.rs @@ -278,6 +278,9 @@ Transactions:{transactions} fn members_count(&self) -> UsizeSer32 { self.members_count } + fn monetary_mass(&self) -> u64 { + self.monetary_mass + } fn number(&self) -> BlockNumber { self.number } diff --git a/lib/modules/gva/resources/schema.gql b/lib/modules/gva/resources/schema.gql index 5779e610..d2b5bb62 100644 --- a/lib/modules/gva/resources/schema.gql +++ b/lib/modules/gva/resources/schema.gql @@ -84,6 +84,7 @@ type Block { issuerName: String, issuersCount: Int! membersCount: Int! + monetaryMass: Int!, number: Int! hash: String!, blockchainTime: DateTimeUtc! diff --git a/lib/modules/gva/src/schema/entities/block.rs b/lib/modules/gva/src/schema/entities/block.rs index 71c40e8d..3d6a2fd6 100644 --- a/lib/modules/gva/src/schema/entities/block.rs +++ b/lib/modules/gva/src/schema/entities/block.rs @@ -33,6 +33,7 @@ pub struct Block { issuer_name: Option<String>, issuers_count: i32, members_count: i32, + monetary_mass: i32, number: i32, hash: String, blockchain_time: NaiveDateTime, @@ -61,6 +62,7 @@ impl Block { }, issuers_count: block_db.block.issuers_count().into(), members_count: block_db.block.members_count().into(), + monetary_mass: block_db.block.monetary_mass() as i32, number: block_db.block.number().0 as i32, hash: block_db .block @@ -120,4 +122,8 @@ impl super::super::BlockFields for Block { fn field_members_count(&self, _executor: &Executor<'_, QueryContext>) -> FieldResult<&i32> { Ok(&self.members_count) } + #[inline] + fn field_monetary_mass(&self, _executor: &Executor<'_, QueryContext>) -> FieldResult<&i32> { + Ok(&self.monetary_mass) + } } diff --git a/lib/modules/gva/src/schema/queries/block.rs b/lib/modules/gva/src/schema/queries/block.rs index 3a85d335..71260c99 100644 --- a/lib/modules/gva/src/schema/queries/block.rs +++ b/lib/modules/gva/src/schema/queries/block.rs @@ -71,6 +71,7 @@ mod tests { ); block.issuers = vec![pubkey('B')]; block.issuers_count = UsizeSer32(3); + block.monetary_mass = 5900; block.pow_min = UsizeSer32(70); Ok(Some(BlockDb { block: BlockDocument::V10(block), @@ -101,7 +102,7 @@ mod tests { tests::test_gql_query( schema, - "{ block(number: 42) { blockchainTime, currency, hash, issuer, issuerName, issuersCount, number, powMin, version } }", + "{ block(number: 42) { blockchainTime, currency, hash, issuer, issuerName, issuersCount, monetaryMass, number, powMin, version } }", json!({ "data": { "block": { @@ -111,6 +112,7 @@ mod tests { "issuer": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "issuerName": "issuerName", "issuersCount": 3, + "monetaryMass": 5900, "number": 42, "powMin": 70, "version": 10 -- GitLab