From bf0c895719d4188abed15a2357fb4e8882485c4b Mon Sep 17 00:00:00 2001
From: librelois <c@elo.tf>
Date: Thu, 10 Dec 2020 02:11:19 +0100
Subject: [PATCH 1/2] [deps] upgrade dubp-rs-libs to 0.33.0

---
 Cargo.lock                                    | 28 +++++++++----------
 Cargo.toml                                    |  2 --
 neon/native/Cargo.toml                        |  2 +-
 neon/native/src/transaction.rs                |  4 +--
 rust-bins/duniter-dbex/Cargo.toml             |  2 +-
 rust-libs/duniter-conf/Cargo.toml             |  2 +-
 rust-libs/duniter-dbs-read-ops/Cargo.toml     |  2 +-
 rust-libs/duniter-dbs-write-ops/Cargo.toml    |  2 +-
 rust-libs/duniter-dbs/Cargo.toml              |  2 +-
 rust-libs/duniter-mempools/Cargo.toml         |  2 +-
 rust-libs/duniter-module/Cargo.toml           |  2 +-
 rust-libs/duniter-server/Cargo.toml           |  2 +-
 rust-libs/modules/gva/Cargo.toml              |  2 +-
 rust-libs/modules/gva/db-writer/Cargo.toml    |  2 +-
 rust-libs/modules/gva/dbs-reader/Cargo.toml   |  2 +-
 rust-libs/modules/gva/src/mutations.rs        |  4 +--
 .../duniter-integration-tests/Cargo.toml      |  2 +-
 17 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 858903e22..221be3944 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -958,9 +958,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
 
 [[package]]
 name = "dubp"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc9edc056137805e63c68584a3066ff3ad83e00e434a2bfcbac8b5160decc5ac"
+checksum = "f2a6192b0248f4b198e9193a59ee73e26ee2feba9b7c4995e628d11d2c19448a"
 dependencies = [
  "dubp-block",
  "dubp-common",
@@ -972,9 +972,9 @@ dependencies = [
 
 [[package]]
 name = "dubp-block"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9bad4399d077e9d85c6dba2d8f69b7b0088ca3b52564ccc9593ccf8b34f1878"
+checksum = "4f59b0253ba66aee87741603f20bab7d67e2ebe11f2bbff58bbc08486b132bb2"
 dependencies = [
  "dubp-documents",
  "dubp-documents-parser",
@@ -987,9 +987,9 @@ dependencies = [
 
 [[package]]
 name = "dubp-common"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5e5079ffa4de9355caa45f098d6a8f92c9dc3df595ba1460a0ceca73b950f626"
+checksum = "a927b5f18b8d5f04b6d1ca179a5678f5f559140844268f78c6872d20fd6f6178"
 dependencies = [
  "dup-crypto",
  "serde",
@@ -1000,9 +1000,9 @@ dependencies = [
 
 [[package]]
 name = "dubp-documents"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "03f03022e76dc830f125ec2983ec8e580c6f46dd005473f182ae71b2cd905af5"
+checksum = "7ccce9aabcb92de2befbbd4360fc73d806df63dce414274bef427de2a7acb725"
 dependencies = [
  "beef",
  "dubp-wallet",
@@ -1014,9 +1014,9 @@ dependencies = [
 
 [[package]]
 name = "dubp-documents-parser"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "54c812d14ad4df502f96d0f32e7459588314791dd2d04640c4102793f2844c04"
+checksum = "abaa735586c05cc4cd1f240eb9531a9762d97e0f55a335e6e11658f4b10f29af"
 dependencies = [
  "dubp-documents",
  "json-pest-parser",
@@ -1028,9 +1028,9 @@ dependencies = [
 
 [[package]]
 name = "dubp-wallet"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5b03ead2777d7845c0e1fc9aa8b5f71c71a31e90e37189c4b515bd21635acf64"
+checksum = "0b73e3ae439e2eba8048ca9830a821cd6cbb51010e0049efc72e201433e6a61d"
 dependencies = [
  "byteorder",
  "dubp-common",
@@ -1292,9 +1292,9 @@ dependencies = [
 
 [[package]]
 name = "dup-crypto"
-version = "0.32.3"
+version = "0.33.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "64160d6011423b13588070b6cd58325536eec930c816ebc367e662bfbd4e23d2"
+checksum = "3e577ae936c53b85818749d1eefedf1d1afd6e0a8286b88543cb068396c16069"
 dependencies = [
  "base64",
  "bs58",
diff --git a/Cargo.toml b/Cargo.toml
index 01a141218..382b77291 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -50,9 +50,7 @@ members = [
 
 [patch.crates-io]
 #dubp = { git = "https://git.duniter.org/libs/dubp-rs-libs" }
-#dubp-common = { git = "https://git.duniter.org/libs/dubp-rs-libs" }
 
 #dubp = { path = "../dubp-rs-libs" }
-#dubp-common = { path = "../dubp-rs-libs/common" }
 
 #leveldb_minimal = { path = "../../../../rust/leveldb_minimal" }
diff --git a/neon/native/Cargo.toml b/neon/native/Cargo.toml
index 3d6cb41f1..569c57566 100644
--- a/neon/native/Cargo.toml
+++ b/neon/native/Cargo.toml
@@ -17,7 +17,7 @@ neon-build = "0.4.0"
 [dependencies]
 bincode = "1.2.1"
 bs58 = "0.3.0"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 dubp-wot = { path = "../../rust-libs/dubp-wot" }
 duniter-server = { path = "../../rust-libs/duniter-server" }
 flate2 = "1.0.16"
diff --git a/neon/native/src/transaction.rs b/neon/native/src/transaction.rs
index 628b32199..5206c3491 100644
--- a/neon/native/src/transaction.rs
+++ b/neon/native/src/transaction.rs
@@ -34,7 +34,7 @@ pub fn raw_tx_parse_and_verify(mut cx: FunctionContext) -> JsResult<JsValue> {
 
     match TransactionDocumentV10::parse_from_raw_text(&raw_tx) {
         Ok(tx) => {
-            if let Err(e) = tx.verify(currency_opt) {
+            if let Err(e) = tx.verify(currency_opt.as_deref()) {
                 cx.throw_error(format!("{}", e))
             } else {
                 let tx_stringified = tx.to_string_object();
@@ -57,7 +57,7 @@ pub fn tx_verify(mut cx: FunctionContext) -> JsResult<JsUndefined> {
         neon_serde::from_value(&mut cx, tx_obj)?;
     match TransactionDocumentV10::from_string_object(&tx_stringified) {
         Ok(tx) => {
-            if let Err(e) = tx.verify(currency_opt) {
+            if let Err(e) = tx.verify(currency_opt.as_deref()) {
                 cx.throw_error(format!("{}", e))
             } else {
                 Ok(cx.undefined())
diff --git a/rust-bins/duniter-dbex/Cargo.toml b/rust-bins/duniter-dbex/Cargo.toml
index 4ca70ed24..ec9a94084 100644
--- a/rust-bins/duniter-dbex/Cargo.toml
+++ b/rust-bins/duniter-dbex/Cargo.toml
@@ -22,7 +22,7 @@ anyhow = "1.0.33"
 arrayvec = "0.5.1"
 comfy-table = "1.0.0"
 dirs = "3.0.1"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-dbs = { path = "../../rust-libs/duniter-dbs", default-features = false, features = ["explorer", "leveldb_backend", "sled_backend"] }
 duniter-dbs-write-ops = { path = "../../rust-libs/duniter-dbs-write-ops", default-features = false, features = ["explorer", "leveldb_backend", "sled_backend"] }
 duniter-gva = { path = "../../rust-libs/modules/gva" }
diff --git a/rust-libs/duniter-conf/Cargo.toml b/rust-libs/duniter-conf/Cargo.toml
index 350c3b2df..86b76c3a5 100644
--- a/rust-libs/duniter-conf/Cargo.toml
+++ b/rust-libs/duniter-conf/Cargo.toml
@@ -6,5 +6,5 @@ license = "AGPL-3.0"
 edition = "2018"
 
 [dependencies]
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 serde = { version = "1.0.105", features = ["derive"] }
diff --git a/rust-libs/duniter-dbs-read-ops/Cargo.toml b/rust-libs/duniter-dbs-read-ops/Cargo.toml
index 68ce948f3..908c5339c 100644
--- a/rust-libs/duniter-dbs-read-ops/Cargo.toml
+++ b/rust-libs/duniter-dbs-read-ops/Cargo.toml
@@ -14,7 +14,7 @@ path = "src/lib.rs"
 [dependencies]
 anyhow = "1.0.34"
 duniter-dbs = { path = "../duniter-dbs" }
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 resiter = "0.4.0"
 
 [dev-dependencies]
diff --git a/rust-libs/duniter-dbs-write-ops/Cargo.toml b/rust-libs/duniter-dbs-write-ops/Cargo.toml
index 6d448f290..387bc8c97 100644
--- a/rust-libs/duniter-dbs-write-ops/Cargo.toml
+++ b/rust-libs/duniter-dbs-write-ops/Cargo.toml
@@ -13,7 +13,7 @@ path = "src/lib.rs"
 
 [dependencies]
 chrono = "0.4.19"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-dbs = { path = "../duniter-dbs" }
 fast-threadpool = "0.2.2"
 log = "0.4.11"
diff --git a/rust-libs/duniter-dbs/Cargo.toml b/rust-libs/duniter-dbs/Cargo.toml
index eaefccf0f..813fd38fd 100644
--- a/rust-libs/duniter-dbs/Cargo.toml
+++ b/rust-libs/duniter-dbs/Cargo.toml
@@ -16,7 +16,7 @@ arrayvec = "0.5.1"
 bincode = "1.2.1"
 byteorder = "1.3.4"
 chrono = { version = "0.4.15", optional = true }
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 kv_typed = { path = "../tools/kv_typed", default-features = false }
 log = "0.4.8"
 mockall = { version = "0.8.0", optional = true }
diff --git a/rust-libs/duniter-mempools/Cargo.toml b/rust-libs/duniter-mempools/Cargo.toml
index 9f1d70838..c5bacfe95 100644
--- a/rust-libs/duniter-mempools/Cargo.toml
+++ b/rust-libs/duniter-mempools/Cargo.toml
@@ -12,7 +12,7 @@ edition = "2018"
 path = "src/lib.rs"
 
 [dependencies]
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-dbs = { path = "../duniter-dbs" }
 duniter-dbs-read-ops = { path = "../duniter-dbs-read-ops" }
 duniter-dbs-write-ops = { path = "../duniter-dbs-write-ops" }
diff --git a/rust-libs/duniter-module/Cargo.toml b/rust-libs/duniter-module/Cargo.toml
index bfb85b0a4..a664eada8 100644
--- a/rust-libs/duniter-module/Cargo.toml
+++ b/rust-libs/duniter-module/Cargo.toml
@@ -8,7 +8,7 @@ edition = "2018"
 [dependencies]
 anyhow = "1.0.34"
 async-trait = "0.1.41"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-conf = { path = "../duniter-conf" }
 duniter-dbs = { path = "../duniter-dbs" }
 duniter-mempools = { path = "../duniter-mempools" }
diff --git a/rust-libs/duniter-server/Cargo.toml b/rust-libs/duniter-server/Cargo.toml
index 6a608039f..408ceeb1a 100644
--- a/rust-libs/duniter-server/Cargo.toml
+++ b/rust-libs/duniter-server/Cargo.toml
@@ -8,7 +8,7 @@ edition = "2018"
 [dependencies]
 anyhow = "1.0.34"
 cfg-if = "1.0.0"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-conf = { path = "../duniter-conf" }
 duniter-dbs = { path = "../duniter-dbs" }
 duniter-dbs-read-ops = { path = "../duniter-dbs-read-ops" }
diff --git a/rust-libs/modules/gva/Cargo.toml b/rust-libs/modules/gva/Cargo.toml
index 27bcee0d8..965bf4c17 100644
--- a/rust-libs/modules/gva/Cargo.toml
+++ b/rust-libs/modules/gva/Cargo.toml
@@ -11,7 +11,7 @@ arrayvec = "0.5.1"
 async-graphql = "2.0.0"
 async-mutex = "1.4.0"
 async-trait = "0.1.41"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-conf = { path = "../../duniter-conf" }
 duniter-dbs = { path = "../../duniter-dbs" }
 duniter-dbs-read-ops = { path = "../../duniter-dbs-read-ops" }
diff --git a/rust-libs/modules/gva/db-writer/Cargo.toml b/rust-libs/modules/gva/db-writer/Cargo.toml
index ed15d1068..424ae6146 100644
--- a/rust-libs/modules/gva/db-writer/Cargo.toml
+++ b/rust-libs/modules/gva/db-writer/Cargo.toml
@@ -14,7 +14,7 @@ path = "src/lib.rs"
 [dependencies]
 anyhow = "1.0.34"
 duniter-dbs = { path = "../../../duniter-dbs" }
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 resiter = "0.4.0"
 
 [dev-dependencies]
diff --git a/rust-libs/modules/gva/dbs-reader/Cargo.toml b/rust-libs/modules/gva/dbs-reader/Cargo.toml
index 50594d857..78d4956b2 100644
--- a/rust-libs/modules/gva/dbs-reader/Cargo.toml
+++ b/rust-libs/modules/gva/dbs-reader/Cargo.toml
@@ -14,7 +14,7 @@ path = "src/lib.rs"
 [dependencies]
 anyhow = "1.0.34"
 duniter-dbs = { path = "../../../duniter-dbs" }
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 resiter = "0.4.0"
 
 [dev-dependencies]
diff --git a/rust-libs/modules/gva/src/mutations.rs b/rust-libs/modules/gva/src/mutations.rs
index e98e3133d..ce2f1e1c9 100644
--- a/rust-libs/modules/gva/src/mutations.rs
+++ b/rust-libs/modules/gva/src/mutations.rs
@@ -32,7 +32,7 @@ impl MutationRoot {
         let data = ctx.data::<SchemaData>()?;
         let expected_currency = data.server_meta_data.currency.clone();
 
-        tx.verify(Some(expected_currency))?;
+        tx.verify(Some(&expected_currency))?;
 
         let server_pubkey = data.server_meta_data.self_pubkey;
         let txs_mempool = data.txs_mempool;
@@ -69,7 +69,7 @@ impl MutationRoot {
 
         let mut processed_txs = Vec::with_capacity(txs.len());
         for tx in txs {
-            tx.verify(Some(expected_currency.clone()))?;
+            tx.verify(Some(&expected_currency))?;
             let tx = data
                 .dbs_pool
                 .execute(move |dbs| {
diff --git a/rust-libs/tests/duniter-integration-tests/Cargo.toml b/rust-libs/tests/duniter-integration-tests/Cargo.toml
index cf913bcb6..355a6a7aa 100644
--- a/rust-libs/tests/duniter-integration-tests/Cargo.toml
+++ b/rust-libs/tests/duniter-integration-tests/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2018"
 
 [dependencies]
 anyhow = "1.0.34"
-dubp = { version = "0.32.3" }
+dubp = { version = "0.33.0" }
 duniter-conf = { path = "../../duniter-conf" }
 duniter-dbs = { path = "../../duniter-dbs" }
 duniter-dbs-read-ops = { path = "../../duniter-dbs-read-ops" }
-- 
GitLab


From c9193834ca3b420269d6df53e76920972ead6f86 Mon Sep 17 00:00:00 2001
From: librelois <c@elo.tf>
Date: Thu, 10 Dec 2020 02:09:10 +0100
Subject: [PATCH 2/2] [feat] gva: add query currentFrame

---
 rust-libs/duniter-dbs-write-ops/src/bc.rs     | 10 ++-
 .../gva/dbs-reader/src/current_frame.rs       | 36 ++++++++++
 rust-libs/modules/gva/dbs-reader/src/lib.rs   | 23 ++++--
 rust-libs/modules/gva/src/entities.rs         |  1 +
 .../modules/gva/src/entities/block_gva.rs     | 61 ++++++++++++++++
 rust-libs/modules/gva/src/lib.rs              |  5 ++
 rust-libs/modules/gva/src/queries.rs          |  2 +
 .../modules/gva/src/queries/current_frame.rs  | 71 +++++++++++++++++++
 8 files changed, 202 insertions(+), 7 deletions(-)
 create mode 100644 rust-libs/modules/gva/dbs-reader/src/current_frame.rs
 create mode 100644 rust-libs/modules/gva/src/entities/block_gva.rs
 create mode 100644 rust-libs/modules/gva/src/queries/current_frame.rs

diff --git a/rust-libs/duniter-dbs-write-ops/src/bc.rs b/rust-libs/duniter-dbs-write-ops/src/bc.rs
index 6ab6ca807..013700b96 100644
--- a/rust-libs/duniter-dbs-write-ops/src/bc.rs
+++ b/rust-libs/duniter-dbs-write-ops/src/bc.rs
@@ -18,6 +18,7 @@ mod txs;
 mod uds;
 
 use crate::*;
+use dubp::crypto::keys::ed25519::PublicKey;
 use duniter_dbs::databases::bc_v2::BcV2DbWritable;
 
 pub fn apply_block<B: Backend>(
@@ -29,17 +30,22 @@ pub fn apply_block<B: Backend>(
         version: 10,
         number: block.number().0,
         hash: block.hash().0,
-        issuer: block.issuer(),
         signature: block.signature(),
         inner_hash: block.inner_hash(),
         previous_hash: block.previous_hash(),
+        issuer: block.issuer(),
+        previous_issuer: PublicKey::default(),
+        time: block.local_time(),
         pow_min: block.pow_min() as u32,
         members_count: block.members_count() as u64,
         issuers_count: block.issuers_count() as u32,
+        issuers_frame: block.issuers_frame() as u64,
+        issuers_frame_var: 0,
         median_time: block.common_time(),
+        nonce: block.nonce(),
+        monetary_mass: block.monetary_mass(),
         dividend: block.dividend(),
         unit_base: block.unit_base() as u32,
-        ..Default::default()
     };
 
     (
diff --git a/rust-libs/modules/gva/dbs-reader/src/current_frame.rs b/rust-libs/modules/gva/dbs-reader/src/current_frame.rs
new file mode 100644
index 000000000..de50777da
--- /dev/null
+++ b/rust-libs/modules/gva/dbs-reader/src/current_frame.rs
@@ -0,0 +1,36 @@
+//  Copyright (C) 2020 Éloïs SANCHEZ.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+use duniter_dbs::BlockMetaV2;
+
+use crate::*;
+
+impl DbsReader {
+    pub fn get_current_frame<BcDb: BcV2DbReadable>(
+        &self,
+        bc_db: &BcDb,
+    ) -> anyhow::Result<Vec<BlockMetaV2>> {
+        if let Some(current_block) = self.get_current_block(bc_db)? {
+            let issuers_frame = current_block.issuers_frame;
+            let start = U32BE(current_block.number + 1 - issuers_frame as u32);
+            bc_db
+                .blocks_meta()
+                .iter_rev(start.., |it| it.values().collect::<KvResult<_>>())
+                .map_err(Into::into)
+        } else {
+            Ok(Vec::with_capacity(0))
+        }
+    }
+}
diff --git a/rust-libs/modules/gva/dbs-reader/src/lib.rs b/rust-libs/modules/gva/dbs-reader/src/lib.rs
index 820de44e0..499f78042 100644
--- a/rust-libs/modules/gva/dbs-reader/src/lib.rs
+++ b/rust-libs/modules/gva/dbs-reader/src/lib.rs
@@ -22,6 +22,7 @@
     unused_import_braces
 )]
 
+pub mod current_frame;
 pub mod find_inputs;
 pub mod pagination;
 pub mod txs_history;
@@ -35,12 +36,15 @@ use dubp::common::crypto::hashs::Hash;
 use dubp::common::crypto::keys::ed25519::PublicKey;
 use dubp::documents::transaction::TransactionDocumentV10;
 use dubp::{common::prelude::BlockNumber, wallet::prelude::*};
-use duniter_dbs::databases::{
-    bc_v2::{BcV2DbReadable, BcV2DbRo},
-    gva_v1::{GvaV1DbReadable, GvaV1DbRo},
-    txs_mp_v2::TxsMpV2DbReadable,
-};
 use duniter_dbs::FileBackend;
+use duniter_dbs::{
+    databases::{
+        bc_v2::{BcV2DbReadable, BcV2DbRo},
+        gva_v1::{GvaV1DbReadable, GvaV1DbRo},
+        txs_mp_v2::TxsMpV2DbReadable,
+    },
+    BlockMetaV2,
+};
 use duniter_dbs::{
     kv_typed::prelude::*, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, UtxoIdDbV2,
 };
@@ -70,6 +74,15 @@ impl DbsReader {
             .get(duniter_dbs::WalletConditionsV2::from_ref(account_script))
     }
 
+    pub fn get_current_block<BcDb: BcV2DbReadable>(
+        &self,
+        bc_db: &BcDb,
+    ) -> KvResult<Option<BlockMetaV2>> {
+        bc_db
+            .blocks_meta()
+            .iter_rev(.., |it| it.values().next_res())
+    }
+
     pub fn get_current_ud<BcDb: BcV2DbReadable>(
         &self,
         bc_db: &BcDb,
diff --git a/rust-libs/modules/gva/src/entities.rs b/rust-libs/modules/gva/src/entities.rs
index 7eda554e3..5fe069ae0 100644
--- a/rust-libs/modules/gva/src/entities.rs
+++ b/rust-libs/modules/gva/src/entities.rs
@@ -13,6 +13,7 @@
 // You should have received a copy of the GNU Affero General Public License
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+pub mod block_gva;
 pub mod tx_gva;
 pub mod ud_gva;
 
diff --git a/rust-libs/modules/gva/src/entities/block_gva.rs b/rust-libs/modules/gva/src/entities/block_gva.rs
new file mode 100644
index 000000000..28db7e94d
--- /dev/null
+++ b/rust-libs/modules/gva/src/entities/block_gva.rs
@@ -0,0 +1,61 @@
+//  Copyright (C) 2020 Éloïs SANCHEZ.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+use duniter_dbs::BlockMetaV2;
+
+#[derive(async_graphql::SimpleObject)]
+pub(crate) struct Block {
+    pub version: u64,
+    pub number: u32,
+    pub hash: String,
+    pub signature: String,
+    pub inner_hash: String,
+    pub previous_hash: String,
+    pub issuer: String,
+    pub time: u64,
+    pub pow_min: u32,
+    pub members_count: u64,
+    pub issuers_count: u32,
+    pub issuers_frame: u64,
+    pub median_time: u64,
+    pub nonce: u64,
+    pub monetary_mass: u64,
+    pub unit_base: u32,
+    pub dividend: Option<u32>,
+}
+
+impl From<BlockMetaV2> for Block {
+    fn from(block_db: BlockMetaV2) -> Self {
+        Block {
+            version: block_db.version,
+            number: block_db.number,
+            hash: block_db.hash.to_string(),
+            signature: block_db.signature.to_string(),
+            inner_hash: block_db.inner_hash.to_string(),
+            previous_hash: block_db.previous_hash.to_string(),
+            issuer: block_db.issuer.to_string(),
+            time: block_db.time,
+            pow_min: block_db.pow_min,
+            members_count: block_db.members_count,
+            issuers_count: block_db.issuers_count,
+            issuers_frame: block_db.issuers_frame,
+            median_time: block_db.median_time,
+            nonce: block_db.nonce,
+            monetary_mass: block_db.monetary_mass,
+            unit_base: block_db.unit_base,
+            dividend: block_db.dividend.map(|sa| sa.amount() as u32),
+        }
+    }
+}
diff --git a/rust-libs/modules/gva/src/lib.rs b/rust-libs/modules/gva/src/lib.rs
index ce60e01d3..9d868bf46 100644
--- a/rust-libs/modules/gva/src/lib.rs
+++ b/rust-libs/modules/gva/src/lib.rs
@@ -36,6 +36,7 @@ mod subscriptions;
 mod warp_;
 
 use crate::entities::{
+    block_gva::Block,
     tx_gva::TxGva,
     ud_gva::{CurrentUdGva, RevalUdGva, UdGva},
     AggregateSum, AmountWithBase, PeerCardGva, RawTxOrChanges, Sum, TxsHistoryGva, UtxoGva,
@@ -422,6 +423,10 @@ mod tests {
                 pubkey: PublicKey,
                 page_info: PageInfo<BlockNumber>,
             ) -> KvResult<PagedData<duniter_gva_dbs_reader::uds_of_pubkey::UdsWithSum>>;
+            fn get_current_frame<BcDb: 'static + BcV2DbReadable>(
+                &self,
+                bc_db: &BcDb,
+            ) -> anyhow::Result<Vec<duniter_dbs::BlockMetaV2>>;
             fn find_inputs<BcDb: 'static + BcV2DbReadable, TxsMpDb: 'static + TxsMpV2DbReadable>(
                 &self,
                 bc_db: &BcDb,
diff --git a/rust-libs/modules/gva/src/queries.rs b/rust-libs/modules/gva/src/queries.rs
index ce5ceff9e..6427b25ca 100644
--- a/rust-libs/modules/gva/src/queries.rs
+++ b/rust-libs/modules/gva/src/queries.rs
@@ -14,6 +14,7 @@
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 pub mod account_balance;
+pub mod current_frame;
 pub mod gen_tx;
 pub mod txs_history;
 pub mod uds;
@@ -26,6 +27,7 @@ use duniter_dbs::databases::cm_v1::CmV1DbReadable as _;
 pub struct QueryRoot(
     queries::NodeQuery,
     queries::account_balance::AccountBalanceQuery,
+    queries::current_frame::CurrentFrameQuery,
     queries::gen_tx::GenTxsQuery,
     queries::txs_history::TxsHistoryQuery,
     queries::uds::UdsQuery,
diff --git a/rust-libs/modules/gva/src/queries/current_frame.rs b/rust-libs/modules/gva/src/queries/current_frame.rs
new file mode 100644
index 000000000..550f0ea1f
--- /dev/null
+++ b/rust-libs/modules/gva/src/queries/current_frame.rs
@@ -0,0 +1,71 @@
+//  Copyright (C) 2020 Éloïs SANCHEZ.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+use crate::*;
+
+#[derive(Default)]
+pub(crate) struct CurrentFrameQuery;
+#[async_graphql::Object]
+impl CurrentFrameQuery {
+    /// Get blocks in current frame
+    async fn current_frame(
+        &self,
+        ctx: &async_graphql::Context<'_>,
+    ) -> async_graphql::Result<Vec<Block>> {
+        let data = ctx.data::<SchemaData>()?;
+        let dbs_reader = data.dbs_reader();
+
+        Ok(data
+            .dbs_pool
+            .execute(move |dbs| dbs_reader.get_current_frame(&dbs.bc_db_ro))
+            .await??
+            .into_iter()
+            .map(Into::into)
+            .collect())
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::tests::*;
+    use duniter_dbs::databases::bc_v2::BcV2DbRo;
+    use duniter_dbs::BlockMetaV2;
+
+    #[tokio::test]
+    async fn query_current_frame() -> anyhow::Result<()> {
+        let mut dbs_reader = MockDbsReader::new();
+        dbs_reader
+            .expect_get_current_frame::<BcV2DbRo<FileBackend>>()
+            .times(1)
+            .returning(|_| {
+                Ok(vec![BlockMetaV2 {
+                    ..Default::default()
+                }])
+            });
+        let schema = create_schema(dbs_reader)?;
+        assert_eq!(
+            exec_graphql_request(&schema, r#"{ currentFrame {nonce} }"#).await?,
+            serde_json::json!({
+                "data": {
+                    "currentFrame": [{
+                      "nonce": 0
+                    }]
+                }
+            })
+        );
+        Ok(())
+    }
+}
-- 
GitLab