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

Merge branch 'feat/gva-current-frame' into 'dev'

Feat/gva current frame

See merge request !1340
parents f27d893c c9193834
Branches
No related tags found
1 merge request!1340Feat/gva current frame
Showing
with 152 additions and 37 deletions
...@@ -958,9 +958,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" ...@@ -958,9 +958,9 @@ checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
[[package]] [[package]]
name = "dubp" name = "dubp"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc9edc056137805e63c68584a3066ff3ad83e00e434a2bfcbac8b5160decc5ac" checksum = "f2a6192b0248f4b198e9193a59ee73e26ee2feba9b7c4995e628d11d2c19448a"
dependencies = [ dependencies = [
"dubp-block", "dubp-block",
"dubp-common", "dubp-common",
...@@ -972,9 +972,9 @@ dependencies = [ ...@@ -972,9 +972,9 @@ dependencies = [
[[package]] [[package]]
name = "dubp-block" name = "dubp-block"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9bad4399d077e9d85c6dba2d8f69b7b0088ca3b52564ccc9593ccf8b34f1878" checksum = "4f59b0253ba66aee87741603f20bab7d67e2ebe11f2bbff58bbc08486b132bb2"
dependencies = [ dependencies = [
"dubp-documents", "dubp-documents",
"dubp-documents-parser", "dubp-documents-parser",
...@@ -987,9 +987,9 @@ dependencies = [ ...@@ -987,9 +987,9 @@ dependencies = [
[[package]] [[package]]
name = "dubp-common" name = "dubp-common"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e5079ffa4de9355caa45f098d6a8f92c9dc3df595ba1460a0ceca73b950f626" checksum = "a927b5f18b8d5f04b6d1ca179a5678f5f559140844268f78c6872d20fd6f6178"
dependencies = [ dependencies = [
"dup-crypto", "dup-crypto",
"serde", "serde",
...@@ -1000,9 +1000,9 @@ dependencies = [ ...@@ -1000,9 +1000,9 @@ dependencies = [
[[package]] [[package]]
name = "dubp-documents" name = "dubp-documents"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03f03022e76dc830f125ec2983ec8e580c6f46dd005473f182ae71b2cd905af5" checksum = "7ccce9aabcb92de2befbbd4360fc73d806df63dce414274bef427de2a7acb725"
dependencies = [ dependencies = [
"beef", "beef",
"dubp-wallet", "dubp-wallet",
...@@ -1014,9 +1014,9 @@ dependencies = [ ...@@ -1014,9 +1014,9 @@ dependencies = [
[[package]] [[package]]
name = "dubp-documents-parser" name = "dubp-documents-parser"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54c812d14ad4df502f96d0f32e7459588314791dd2d04640c4102793f2844c04" checksum = "abaa735586c05cc4cd1f240eb9531a9762d97e0f55a335e6e11658f4b10f29af"
dependencies = [ dependencies = [
"dubp-documents", "dubp-documents",
"json-pest-parser", "json-pest-parser",
...@@ -1028,9 +1028,9 @@ dependencies = [ ...@@ -1028,9 +1028,9 @@ dependencies = [
[[package]] [[package]]
name = "dubp-wallet" name = "dubp-wallet"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b03ead2777d7845c0e1fc9aa8b5f71c71a31e90e37189c4b515bd21635acf64" checksum = "0b73e3ae439e2eba8048ca9830a821cd6cbb51010e0049efc72e201433e6a61d"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"dubp-common", "dubp-common",
...@@ -1292,9 +1292,9 @@ dependencies = [ ...@@ -1292,9 +1292,9 @@ dependencies = [
[[package]] [[package]]
name = "dup-crypto" name = "dup-crypto"
version = "0.32.3" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64160d6011423b13588070b6cd58325536eec930c816ebc367e662bfbd4e23d2" checksum = "3e577ae936c53b85818749d1eefedf1d1afd6e0a8286b88543cb068396c16069"
dependencies = [ dependencies = [
"base64", "base64",
"bs58", "bs58",
......
...@@ -50,9 +50,7 @@ members = [ ...@@ -50,9 +50,7 @@ members = [
[patch.crates-io] [patch.crates-io]
#dubp = { git = "https://git.duniter.org/libs/dubp-rs-libs" } #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 = { path = "../dubp-rs-libs" }
#dubp-common = { path = "../dubp-rs-libs/common" }
#leveldb_minimal = { path = "../../../../rust/leveldb_minimal" } #leveldb_minimal = { path = "../../../../rust/leveldb_minimal" }
...@@ -17,7 +17,7 @@ neon-build = "0.4.0" ...@@ -17,7 +17,7 @@ neon-build = "0.4.0"
[dependencies] [dependencies]
bincode = "1.2.1" bincode = "1.2.1"
bs58 = "0.3.0" bs58 = "0.3.0"
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
dubp-wot = { path = "../../rust-libs/dubp-wot" } dubp-wot = { path = "../../rust-libs/dubp-wot" }
duniter-server = { path = "../../rust-libs/duniter-server" } duniter-server = { path = "../../rust-libs/duniter-server" }
flate2 = "1.0.16" flate2 = "1.0.16"
......
...@@ -34,7 +34,7 @@ pub fn raw_tx_parse_and_verify(mut cx: FunctionContext) -> JsResult<JsValue> { ...@@ -34,7 +34,7 @@ pub fn raw_tx_parse_and_verify(mut cx: FunctionContext) -> JsResult<JsValue> {
match TransactionDocumentV10::parse_from_raw_text(&raw_tx) { match TransactionDocumentV10::parse_from_raw_text(&raw_tx) {
Ok(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)) cx.throw_error(format!("{}", e))
} else { } else {
let tx_stringified = tx.to_string_object(); let tx_stringified = tx.to_string_object();
...@@ -57,7 +57,7 @@ pub fn tx_verify(mut cx: FunctionContext) -> JsResult<JsUndefined> { ...@@ -57,7 +57,7 @@ pub fn tx_verify(mut cx: FunctionContext) -> JsResult<JsUndefined> {
neon_serde::from_value(&mut cx, tx_obj)?; neon_serde::from_value(&mut cx, tx_obj)?;
match TransactionDocumentV10::from_string_object(&tx_stringified) { match TransactionDocumentV10::from_string_object(&tx_stringified) {
Ok(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)) cx.throw_error(format!("{}", e))
} else { } else {
Ok(cx.undefined()) Ok(cx.undefined())
......
...@@ -22,7 +22,7 @@ anyhow = "1.0.33" ...@@ -22,7 +22,7 @@ anyhow = "1.0.33"
arrayvec = "0.5.1" arrayvec = "0.5.1"
comfy-table = "1.0.0" comfy-table = "1.0.0"
dirs = "3.0.1" 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 = { 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-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" } duniter-gva = { path = "../../rust-libs/modules/gva" }
......
...@@ -6,5 +6,5 @@ license = "AGPL-3.0" ...@@ -6,5 +6,5 @@ license = "AGPL-3.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
serde = { version = "1.0.105", features = ["derive"] } serde = { version = "1.0.105", features = ["derive"] }
...@@ -14,7 +14,7 @@ path = "src/lib.rs" ...@@ -14,7 +14,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
duniter-dbs = { path = "../duniter-dbs" } duniter-dbs = { path = "../duniter-dbs" }
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
resiter = "0.4.0" resiter = "0.4.0"
[dev-dependencies] [dev-dependencies]
......
...@@ -13,7 +13,7 @@ path = "src/lib.rs" ...@@ -13,7 +13,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
chrono = "0.4.19" chrono = "0.4.19"
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
duniter-dbs = { path = "../duniter-dbs" } duniter-dbs = { path = "../duniter-dbs" }
fast-threadpool = "0.2.2" fast-threadpool = "0.2.2"
log = "0.4.11" log = "0.4.11"
......
...@@ -18,6 +18,7 @@ mod txs; ...@@ -18,6 +18,7 @@ mod txs;
mod uds; mod uds;
use crate::*; use crate::*;
use dubp::crypto::keys::ed25519::PublicKey;
use duniter_dbs::databases::bc_v2::BcV2DbWritable; use duniter_dbs::databases::bc_v2::BcV2DbWritable;
pub fn apply_block<B: Backend>( pub fn apply_block<B: Backend>(
...@@ -29,17 +30,22 @@ pub fn apply_block<B: Backend>( ...@@ -29,17 +30,22 @@ pub fn apply_block<B: Backend>(
version: 10, version: 10,
number: block.number().0, number: block.number().0,
hash: block.hash().0, hash: block.hash().0,
issuer: block.issuer(),
signature: block.signature(), signature: block.signature(),
inner_hash: block.inner_hash(), inner_hash: block.inner_hash(),
previous_hash: block.previous_hash(), previous_hash: block.previous_hash(),
issuer: block.issuer(),
previous_issuer: PublicKey::default(),
time: block.local_time(),
pow_min: block.pow_min() as u32, pow_min: block.pow_min() as u32,
members_count: block.members_count() as u64, members_count: block.members_count() as u64,
issuers_count: block.issuers_count() as u32, issuers_count: block.issuers_count() as u32,
issuers_frame: block.issuers_frame() as u64,
issuers_frame_var: 0,
median_time: block.common_time(), median_time: block.common_time(),
nonce: block.nonce(),
monetary_mass: block.monetary_mass(),
dividend: block.dividend(), dividend: block.dividend(),
unit_base: block.unit_base() as u32, unit_base: block.unit_base() as u32,
..Default::default()
}; };
( (
......
...@@ -16,7 +16,7 @@ arrayvec = "0.5.1" ...@@ -16,7 +16,7 @@ arrayvec = "0.5.1"
bincode = "1.2.1" bincode = "1.2.1"
byteorder = "1.3.4" byteorder = "1.3.4"
chrono = { version = "0.4.15", optional = true } 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 } kv_typed = { path = "../tools/kv_typed", default-features = false }
log = "0.4.8" log = "0.4.8"
mockall = { version = "0.8.0", optional = true } mockall = { version = "0.8.0", optional = true }
......
...@@ -12,7 +12,7 @@ edition = "2018" ...@@ -12,7 +12,7 @@ edition = "2018"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
duniter-dbs = { path = "../duniter-dbs" } duniter-dbs = { path = "../duniter-dbs" }
duniter-dbs-read-ops = { path = "../duniter-dbs-read-ops" } duniter-dbs-read-ops = { path = "../duniter-dbs-read-ops" }
duniter-dbs-write-ops = { path = "../duniter-dbs-write-ops" } duniter-dbs-write-ops = { path = "../duniter-dbs-write-ops" }
......
...@@ -8,7 +8,7 @@ edition = "2018" ...@@ -8,7 +8,7 @@ edition = "2018"
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
async-trait = "0.1.41" async-trait = "0.1.41"
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
duniter-conf = { path = "../duniter-conf" } duniter-conf = { path = "../duniter-conf" }
duniter-dbs = { path = "../duniter-dbs" } duniter-dbs = { path = "../duniter-dbs" }
duniter-mempools = { path = "../duniter-mempools" } duniter-mempools = { path = "../duniter-mempools" }
......
...@@ -8,7 +8,7 @@ edition = "2018" ...@@ -8,7 +8,7 @@ edition = "2018"
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
cfg-if = "1.0.0" cfg-if = "1.0.0"
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
duniter-conf = { path = "../duniter-conf" } duniter-conf = { path = "../duniter-conf" }
duniter-dbs = { path = "../duniter-dbs" } duniter-dbs = { path = "../duniter-dbs" }
duniter-dbs-read-ops = { path = "../duniter-dbs-read-ops" } duniter-dbs-read-ops = { path = "../duniter-dbs-read-ops" }
......
...@@ -11,7 +11,7 @@ arrayvec = "0.5.1" ...@@ -11,7 +11,7 @@ arrayvec = "0.5.1"
async-graphql = "2.0.0" async-graphql = "2.0.0"
async-mutex = "1.4.0" async-mutex = "1.4.0"
async-trait = "0.1.41" async-trait = "0.1.41"
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
duniter-conf = { path = "../../duniter-conf" } duniter-conf = { path = "../../duniter-conf" }
duniter-dbs = { path = "../../duniter-dbs" } duniter-dbs = { path = "../../duniter-dbs" }
duniter-dbs-read-ops = { path = "../../duniter-dbs-read-ops" } duniter-dbs-read-ops = { path = "../../duniter-dbs-read-ops" }
......
...@@ -14,7 +14,7 @@ path = "src/lib.rs" ...@@ -14,7 +14,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
duniter-dbs = { path = "../../../duniter-dbs" } duniter-dbs = { path = "../../../duniter-dbs" }
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
resiter = "0.4.0" resiter = "0.4.0"
[dev-dependencies] [dev-dependencies]
......
...@@ -14,7 +14,7 @@ path = "src/lib.rs" ...@@ -14,7 +14,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
duniter-dbs = { path = "../../../duniter-dbs" } duniter-dbs = { path = "../../../duniter-dbs" }
dubp = { version = "0.32.3" } dubp = { version = "0.33.0" }
resiter = "0.4.0" resiter = "0.4.0"
[dev-dependencies] [dev-dependencies]
......
// 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))
}
}
}
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
unused_import_braces unused_import_braces
)] )]
pub mod current_frame;
pub mod find_inputs; pub mod find_inputs;
pub mod pagination; pub mod pagination;
pub mod txs_history; pub mod txs_history;
...@@ -35,12 +36,15 @@ use dubp::common::crypto::hashs::Hash; ...@@ -35,12 +36,15 @@ use dubp::common::crypto::hashs::Hash;
use dubp::common::crypto::keys::ed25519::PublicKey; use dubp::common::crypto::keys::ed25519::PublicKey;
use dubp::documents::transaction::TransactionDocumentV10; use dubp::documents::transaction::TransactionDocumentV10;
use dubp::{common::prelude::BlockNumber, wallet::prelude::*}; use dubp::{common::prelude::BlockNumber, wallet::prelude::*};
use duniter_dbs::databases::{ use duniter_dbs::FileBackend;
use duniter_dbs::{
databases::{
bc_v2::{BcV2DbReadable, BcV2DbRo}, bc_v2::{BcV2DbReadable, BcV2DbRo},
gva_v1::{GvaV1DbReadable, GvaV1DbRo}, gva_v1::{GvaV1DbReadable, GvaV1DbRo},
txs_mp_v2::TxsMpV2DbReadable, txs_mp_v2::TxsMpV2DbReadable,
},
BlockMetaV2,
}; };
use duniter_dbs::FileBackend;
use duniter_dbs::{ use duniter_dbs::{
kv_typed::prelude::*, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, UtxoIdDbV2, kv_typed::prelude::*, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, UtxoIdDbV2,
}; };
...@@ -70,6 +74,15 @@ impl DbsReader { ...@@ -70,6 +74,15 @@ impl DbsReader {
.get(duniter_dbs::WalletConditionsV2::from_ref(account_script)) .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>( pub fn get_current_ud<BcDb: BcV2DbReadable>(
&self, &self,
bc_db: &BcDb, bc_db: &BcDb,
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
pub mod block_gva;
pub mod tx_gva; pub mod tx_gva;
pub mod ud_gva; pub mod ud_gva;
......
// 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),
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment