diff --git a/lib/modules-lib/bc-db-reader/src/readers/block.rs b/lib/modules-lib/bc-db-reader/src/blocks.rs similarity index 89% rename from lib/modules-lib/bc-db-reader/src/readers/block.rs rename to lib/modules-lib/bc-db-reader/src/blocks.rs index f2a38f6c0f75d7273411ea96997e2486dea64b54..92be9d98fa978dc366b537e36860038203c03ad0 100644 --- a/lib/modules-lib/bc-db-reader/src/readers/block.rs +++ b/lib/modules-lib/bc-db-reader/src/blocks.rs @@ -13,8 +13,11 @@ // 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/>. +//! Define blocks entities and requests + +pub mod fork_tree; + use crate::constants::*; -use crate::entities::block::DbBlock; use crate::*; use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; @@ -22,8 +25,32 @@ use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp, PreviousBlockstamp}; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_dbs_tools::DbError; +use durs_wot::WotId; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; +#[derive(Clone, Debug, Deserialize, Serialize)] +/// A block as it is saved in a database +pub struct DbBlock { + /// Block document + pub block: BlockDocument, + /// List of certifications that expire in this block. + /// Warning : BlockNumber contain the emission block, not the written block ! + /// HashMap<(Source, Target), BlockNumber> + pub expire_certs: Option<HashMap<(WotId, WotId), BlockNumber>>, +} + +impl DbBlock { + /// Get blockstamp + pub fn blockstamp(&self) -> Blockstamp { + self.block.blockstamp() + } + /// Get previous blockstamp + pub fn previous_blockstamp(&self) -> PreviousBlockstamp { + self.block.previous_blockstamp() + } +} + /// Return true if the node already knows this block pub fn already_have_block<DB: DbReadable>( db: &DB, diff --git a/lib/modules-lib/bc-db-reader/src/entities/fork_tree.rs b/lib/modules-lib/bc-db-reader/src/blocks/fork_tree.rs similarity index 100% rename from lib/modules-lib/bc-db-reader/src/entities/fork_tree.rs rename to lib/modules-lib/bc-db-reader/src/blocks/fork_tree.rs diff --git a/lib/modules-lib/bc-db-reader/src/readers/currency_params.rs b/lib/modules-lib/bc-db-reader/src/currency_params.rs similarity index 98% rename from lib/modules-lib/bc-db-reader/src/readers/currency_params.rs rename to lib/modules-lib/bc-db-reader/src/currency_params.rs index 0e5eba74dc3ee1745d1649bbeec5af7606c06dc5..bed6d8cc19c03bade277e876f47941213710a044 100644 --- a/lib/modules-lib/bc-db-reader/src/readers/currency_params.rs +++ b/lib/modules-lib/bc-db-reader/src/currency_params.rs @@ -13,6 +13,8 @@ // 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/>. +//! Currency parameters storage. + use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; use dubp_currency_params::db::write_currency_params; diff --git a/lib/modules-lib/bc-db-reader/src/readers/current_meta_datas.rs b/lib/modules-lib/bc-db-reader/src/current_meta_datas.rs similarity index 83% rename from lib/modules-lib/bc-db-reader/src/readers/current_meta_datas.rs rename to lib/modules-lib/bc-db-reader/src/current_meta_datas.rs index 5dc9f6beccc165413bb772ead8687dc45689814d..f565a95c399a2704f1f481d1aff7ddda5faa5896 100644 --- a/lib/modules-lib/bc-db-reader/src/readers/current_meta_datas.rs +++ b/lib/modules-lib/bc-db-reader/src/current_meta_datas.rs @@ -13,13 +13,42 @@ // 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/>. +//! Current meta datas + +use crate::blocks::fork_tree::ForkTree; use crate::constants::*; -use crate::entities::current_meta_datas::CurrentMetaDataKey; -use crate::entities::fork_tree::ForkTree; use crate::{DbReadable, DbValue}; use dubp_common_doc::{Blockstamp, CurrencyName}; use durs_dbs_tools::DbError; +#[derive(Clone, Copy, Debug)] +/// Current meta data key +pub enum CurrentMetaDataKey { + /// Version of the database structure + DbVersion, + /// Currency name + CurrencyName, + /// Current blockstamp + CurrentBlockstamp, + /// Current "blokchain" time + CurrentBlockchainTime, + /// Fork tree + ForkTree, +} + +impl CurrentMetaDataKey { + /// To u32 + pub fn to_u32(self) -> u32 { + match self { + Self::DbVersion => 0, + Self::CurrencyName => 1, + Self::CurrentBlockstamp => 2, + Self::CurrentBlockchainTime => 3, + Self::ForkTree => 4, + } + } +} + /// Get DB version pub fn get_db_version<DB: DbReadable>(db: &DB) -> Result<usize, DbError> { db.read(|r| { diff --git a/lib/modules-lib/bc-db-reader/src/entities/block.rs b/lib/modules-lib/bc-db-reader/src/entities/block.rs deleted file mode 100644 index eaf40ea416cb3ec1f1a3acb740f200ad70026ec1..0000000000000000000000000000000000000000 --- a/lib/modules-lib/bc-db-reader/src/entities/block.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2017-2019 The AXIOM TEAM Association. -// -// 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 dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; -use dubp_common_doc::traits::Document; -use dubp_common_doc::{BlockNumber, Blockstamp, PreviousBlockstamp}; -use durs_wot::WotId; -use serde::{Deserialize, Serialize}; -use std::collections::HashMap; - -#[derive(Clone, Debug, Deserialize, Serialize)] -/// A block as it is saved in a database -pub struct DbBlock { - /// Block document - pub block: BlockDocument, - /// List of certifications that expire in this block. - /// Warning : BlockNumber contain the emission block, not the written block ! - /// HashMap<(Source, Target), BlockNumber> - pub expire_certs: Option<HashMap<(WotId, WotId), BlockNumber>>, -} - -impl DbBlock { - /// Get blockstamp - pub fn blockstamp(&self) -> Blockstamp { - self.block.blockstamp() - } - /// Get previous blockstamp - pub fn previous_blockstamp(&self) -> PreviousBlockstamp { - self.block.previous_blockstamp() - } -} diff --git a/lib/modules-lib/bc-db-reader/src/entities/current_meta_datas.rs b/lib/modules-lib/bc-db-reader/src/entities/current_meta_datas.rs deleted file mode 100644 index d479f0bdf5feb8a8dff012ba7a8ec4a823b9b7b0..0000000000000000000000000000000000000000 --- a/lib/modules-lib/bc-db-reader/src/entities/current_meta_datas.rs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2017-2019 The AXIOM TEAM Association. -// -// 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/>. - -//! Describe current meta datas - -#[derive(Clone, Copy, Debug)] -/// Current meta data key -pub enum CurrentMetaDataKey { - /// Version of the database structure - DbVersion, - /// Currency name - CurrencyName, - /// Current blockstamp - CurrentBlockstamp, - /// Current "blokchain" time - CurrentBlockchainTime, - /// Fork tree - ForkTree, -} - -impl CurrentMetaDataKey { - /// To u32 - pub fn to_u32(self) -> u32 { - match self { - Self::DbVersion => 0, - Self::CurrencyName => 1, - Self::CurrentBlockstamp => 2, - Self::CurrentBlockchainTime => 3, - Self::ForkTree => 4, - } - } -} diff --git a/lib/modules-lib/bc-db-reader/src/entities/identity.rs b/lib/modules-lib/bc-db-reader/src/entities/identity.rs deleted file mode 100644 index f15e245aa14b4ff33f907ae16c6108ec32f7ddd1..0000000000000000000000000000000000000000 --- a/lib/modules-lib/bc-db-reader/src/entities/identity.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2017-2019 The AXIOM TEAM Association. -// -// 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 dubp_common_doc::{BlockNumber, Blockstamp}; -use dubp_user_docs::documents::identity::IdentityDocumentV10; -use durs_wot::WotId; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] -/// Identity state -pub enum DbIdentityState { - /// Member - Member(Vec<usize>), - /// Expire Member - ExpireMember(Vec<usize>), - /// Explicit Revoked - ExplicitRevoked(Vec<usize>), - /// Explicit Revoked after expire - ExplicitExpireRevoked(Vec<usize>), - /// Implicit revoked - ImplicitRevoked(Vec<usize>), -} - -#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] -/// Identity in database -pub struct DbIdentity { - /// Identity hash - pub hash: String, - /// Identity state - pub state: DbIdentityState, - /// Blockstamp the identity was written - pub joined_on: Blockstamp, - /// Blockstamp the identity was expired - pub expired_on: Option<Blockstamp>, - /// Blockstamp the identity was revoked - pub revoked_on: Option<Blockstamp>, - /// Identity document - pub idty_doc: IdentityDocumentV10, - /// Identity wot id - pub wot_id: WotId, - /// Membership created block number - pub ms_created_block_id: BlockNumber, - /// Timestamp from which membership can be renewed - pub ms_chainable_on: Vec<u64>, - /// Timestamp from which the identity can write a new certification - pub cert_chainable_on: Vec<u64>, -} diff --git a/lib/modules-lib/bc-db-reader/src/filters/identities.rs b/lib/modules-lib/bc-db-reader/src/filters/identities.rs deleted file mode 100644 index 42f01512cbb8b81f7b7b3b6f160c00ee3c3aac82..0000000000000000000000000000000000000000 --- a/lib/modules-lib/bc-db-reader/src/filters/identities.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2017-2019 The AXIOM TEAM Association. -// -// 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/>. - -//! Define all filters applicable to identities - -use super::PagingFilter; -use dup_crypto::keys::*; - -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -/// Identities filter -pub struct IdentitiesFilter { - /// Pagination parameters - pub paging: PagingFilter, - /// Filter identities by public key - pub by_pubkey: Option<PubKey>, -} - -impl Default for IdentitiesFilter { - fn default() -> Self { - IdentitiesFilter { - paging: PagingFilter::default(), - by_pubkey: None, - } - } -} - -impl IdentitiesFilter { - /// Create "by pubkey" filter - pub fn by_pubkey(pubkey: PubKey) -> Self { - IdentitiesFilter { - paging: PagingFilter::default(), - by_pubkey: Some(pubkey), - } - } -} diff --git a/lib/modules-lib/bc-db-reader/src/entities.rs b/lib/modules-lib/bc-db-reader/src/indexes.rs similarity index 80% rename from lib/modules-lib/bc-db-reader/src/entities.rs rename to lib/modules-lib/bc-db-reader/src/indexes.rs index 1eff00ee87e3dfbfc43f7be82569a8a10148ea41..c90f459800f3fe35147b65a7115f7c5b3c07bc14 100644 --- a/lib/modules-lib/bc-db-reader/src/entities.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes.rs @@ -13,18 +13,9 @@ // 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/>. -//! Define database entities. +//! Blockchain stored indexes. -/// Block -pub mod block; - -pub mod current_meta_datas; - -/// Forks tree -pub mod fork_tree; - -/// Identities -pub mod identity; - -/// Sources of currency +pub mod balance; +pub mod certs; +pub mod identities; pub mod sources; diff --git a/lib/modules-lib/bc-db-reader/src/readers/balance.rs b/lib/modules-lib/bc-db-reader/src/indexes/balance.rs similarity index 96% rename from lib/modules-lib/bc-db-reader/src/readers/balance.rs rename to lib/modules-lib/bc-db-reader/src/indexes/balance.rs index 93f6975c05633dd30135b918603cd4bfac736535..02442d1b2c82d1b86f7d14e471a1d4a4e6e2138c 100644 --- a/lib/modules-lib/bc-db-reader/src/readers/balance.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/balance.rs @@ -13,7 +13,9 @@ // 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::entities::sources::*; +//! Balances stored index. + +use super::sources::*; use crate::BalancesV10Datas; use dubp_user_docs::documents::transaction::UTXOConditionsGroup; use durs_dbs_tools::{BinFreeStructDb, DbError}; diff --git a/lib/modules-lib/bc-db-reader/src/readers/certs.rs b/lib/modules-lib/bc-db-reader/src/indexes/certs.rs similarity index 97% rename from lib/modules-lib/bc-db-reader/src/readers/certs.rs rename to lib/modules-lib/bc-db-reader/src/indexes/certs.rs index 0e2433d627c2acff9f972752f3e9b51a168a2c39..3dc4959641734315e9738bce532da0d1f2c90d87 100644 --- a/lib/modules-lib/bc-db-reader/src/readers/certs.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/certs.rs @@ -13,6 +13,8 @@ // 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/>. +//! Certificatiosn stored index. + use crate::CertsExpirV10Datas; use dubp_common_doc::BlockNumber; use durs_dbs_tools::{BinFreeStructDb, DbError}; diff --git a/lib/modules-lib/bc-db-reader/src/readers/identity.rs b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs similarity index 74% rename from lib/modules-lib/bc-db-reader/src/readers/identity.rs rename to lib/modules-lib/bc-db-reader/src/indexes/identities.rs index 4d05e3942a2d5167c1d12bb19cce4d2ae609af14..d47b5aaab67bc2d5c11f8b35c421f1890aa97941 100644 --- a/lib/modules-lib/bc-db-reader/src/readers/identity.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs @@ -13,17 +13,88 @@ // 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/>. +//! Identities stored index. + use crate::constants::*; -use crate::entities::identity::DbIdentity; -use crate::filters::identities::IdentitiesFilter; +use crate::paging::PagingFilter; use crate::*; use dubp_common_doc::traits::Document; -use dubp_common_doc::BlockNumber; +use dubp_common_doc::{BlockNumber, Blockstamp}; +use dubp_user_docs::documents::identity::IdentityDocumentV10; use dup_crypto::keys::*; use durs_dbs_tools::DbError; use durs_wot::WotId; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +/// Identities filter +pub struct IdentitiesFilter { + /// Pagination parameters + pub paging: PagingFilter, + /// Filter identities by public key + pub by_pubkey: Option<PubKey>, +} + +impl Default for IdentitiesFilter { + fn default() -> Self { + IdentitiesFilter { + paging: PagingFilter::default(), + by_pubkey: None, + } + } +} + +impl IdentitiesFilter { + /// Create "by pubkey" filter + pub fn by_pubkey(pubkey: PubKey) -> Self { + IdentitiesFilter { + paging: PagingFilter::default(), + by_pubkey: Some(pubkey), + } + } +} + +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] +/// Identity state +pub enum DbIdentityState { + /// Member + Member(Vec<usize>), + /// Expire Member + ExpireMember(Vec<usize>), + /// Explicit Revoked + ExplicitRevoked(Vec<usize>), + /// Explicit Revoked after expire + ExplicitExpireRevoked(Vec<usize>), + /// Implicit revoked + ImplicitRevoked(Vec<usize>), +} + +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] +/// Identity in database +pub struct DbIdentity { + /// Identity hash + pub hash: String, + /// Identity state + pub state: DbIdentityState, + /// Blockstamp the identity was written + pub joined_on: Blockstamp, + /// Blockstamp the identity was expired + pub expired_on: Option<Blockstamp>, + /// Blockstamp the identity was revoked + pub revoked_on: Option<Blockstamp>, + /// Identity document + pub idty_doc: IdentityDocumentV10, + /// Identity wot id + pub wot_id: WotId, + /// Membership created block number + pub ms_created_block_id: BlockNumber, + /// Timestamp from which membership can be renewed + pub ms_chainable_on: Vec<u64>, + /// Timestamp from which the identity can write a new certification + pub cert_chainable_on: Vec<u64>, +} + /// Get identities in databases pub fn get_identities<DB: DbReadable>( db: &DB, @@ -65,18 +136,25 @@ pub fn get_identities<DB: DbReadable>( } } -/// Get identity in databases +/// Get identity by pubkey in databases pub fn get_identity<DB: DbReadable>( db: &DB, pubkey: &PubKey, ) -> Result<Option<DbIdentity>, DbError> { - db.read(|r| { - if let Some(v) = db.get_store(IDENTITIES).get(r, &pubkey.to_bytes_vector())? { - Ok(Some(DB::from_db_value(v)?)) - } else { - Ok(None) - } - }) + db.read(|r| get_identity_(db, r, pubkey)) +} + +/// Get identity by pubkey +pub fn get_identity_<DB: DbReadable, R: Reader>( + db: &DB, + r: &R, + pubkey: &PubKey, +) -> Result<Option<DbIdentity>, DbError> { + if let Some(v) = db.get_store(IDENTITIES).get(r, &pubkey.to_bytes_vector())? { + Ok(Some(DB::from_db_value(v)?)) + } else { + Ok(None) + } } /// Get uid from pubkey @@ -132,8 +210,7 @@ pub fn get_wot_uid_index<DB: DbReadable>(db: &DB) -> Result<HashMap<WotId, Strin mod test { use super::*; - use crate::entities::identity::*; - use crate::filters::PagingFilter; + use crate::paging::PagingFilter; use dubp_common_doc::Blockstamp; use dup_crypto_tests_tools::mocks::pubkey; use durs_common_tests_tools::collections::slice_same_elems; diff --git a/lib/modules-lib/bc-db-reader/src/entities/sources.rs b/lib/modules-lib/bc-db-reader/src/indexes/sources.rs similarity index 99% rename from lib/modules-lib/bc-db-reader/src/entities/sources.rs rename to lib/modules-lib/bc-db-reader/src/indexes/sources.rs index fff15894960ebfc01545c5913233fffe0cc925da..db855fbee316721da8032669022d2f16dc10bc9d 100644 --- a/lib/modules-lib/bc-db-reader/src/entities/sources.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/sources.rs @@ -13,6 +13,8 @@ // 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/>. +//! Sources stored index. + use dubp_indexes::sindex::UniqueIdUTXOv10; use dubp_user_docs::documents::transaction::*; use durs_common_tools::fatal_error; diff --git a/lib/modules-lib/bc-db-reader/src/lib.rs b/lib/modules-lib/bc-db-reader/src/lib.rs index ac91cbe5a803099d4914075a52d1326db8fa8b0c..398a2b0b5f335c7a7f6a5b8359002f30c4df59d6 100644 --- a/lib/modules-lib/bc-db-reader/src/lib.rs +++ b/lib/modules-lib/bc-db-reader/src/lib.rs @@ -27,15 +27,17 @@ unused_qualifications )] +pub mod blocks; pub mod constants; -pub mod entities; -pub mod filters; -pub mod readers; +pub mod currency_params; +pub mod current_meta_datas; +pub mod indexes; +pub mod paging; pub mod tools; pub use durs_dbs_tools::kv_db::{ KvFileDbRead as DbReadable, KvFileDbRoHandler as BcDbRo, KvFileDbSchema, KvFileDbStoreType, - KvFileDbValue as DbValue, + KvFileDbValue as DbValue, Readable as Reader, }; use constants::*; @@ -77,7 +79,7 @@ pub type CertsExpirV10Datas = fnv::FnvHashMap< pub type BalancesV10Datas = std::collections::HashMap< dubp_user_docs::documents::transaction::UTXOConditionsGroup, ( - crate::entities::sources::SourceAmount, + crate::indexes::sources::SourceAmount, std::collections::HashSet<dubp_indexes::sindex::UniqueIdUTXOv10>, ), >; diff --git a/lib/modules-lib/bc-db-reader/src/filters.rs b/lib/modules-lib/bc-db-reader/src/paging.rs similarity index 95% rename from lib/modules-lib/bc-db-reader/src/filters.rs rename to lib/modules-lib/bc-db-reader/src/paging.rs index 47bd2513303a3ddb86b3a43e574a07dfc3e41258..cae608a061b75e42318e181d0ccd7851b88a58e4 100644 --- a/lib/modules-lib/bc-db-reader/src/filters.rs +++ b/lib/modules-lib/bc-db-reader/src/paging.rs @@ -13,9 +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/>. -//! Define Define all filters applicable to database entities. - -pub mod identities; +//! Define pagination. use dubp_common_doc::BlockNumber; diff --git a/lib/modules-lib/bc-db-reader/src/readers.rs b/lib/modules-lib/bc-db-reader/src/readers.rs deleted file mode 100644 index 175d39025f4df2adaed11d496d8dddee838a19ae..0000000000000000000000000000000000000000 --- a/lib/modules-lib/bc-db-reader/src/readers.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (C) 2017-2019 The AXIOM TEAM Association. -// -// 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/>. - -//! Blockchain database readers. - -/// Balances read functions -pub mod balance; - -/// Block read functions -pub mod block; - -/// Certifications read functions -pub mod certs; - -/// Currency params read functions -pub mod currency_params; - -/// Current meta datas read functions -pub mod current_meta_datas; - -/// Identities read functions -pub mod identity; diff --git a/lib/modules-lib/bc-db-reader/src/tools.rs b/lib/modules-lib/bc-db-reader/src/tools.rs index 6142df902a03ec5b9ad9357269203a3d600d488f..d15e58aaf04dd16ad83bd20625977094c068feb8 100644 --- a/lib/modules-lib/bc-db-reader/src/tools.rs +++ b/lib/modules-lib/bc-db-reader/src/tools.rs @@ -15,7 +15,7 @@ //! Data calculation tools -use crate::entities::block::DbBlock; +use crate::blocks::DbBlock; use dubp_block_doc::block::BlockDocumentTrait; use dup_crypto::keys::PubKey; use durs_common_tools::fatal_error; diff --git a/lib/modules/blockchain/bc-db-writer/src/lib.rs b/lib/modules/blockchain/bc-db-writer/src/lib.rs index 1d02c53297237d0de7f355b24cb033406adaa17c..ff9b7352e2a36538121130eafd73a863c8a40093 100644 --- a/lib/modules/blockchain/bc-db-writer/src/lib.rs +++ b/lib/modules/blockchain/bc-db-writer/src/lib.rs @@ -53,7 +53,7 @@ use dubp_indexes::sindex::UniqueIdUTXOv10; use dubp_user_docs::documents::transaction::*; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; -use durs_bc_db_reader::entities::sources::UTXOContentV10; +use durs_bc_db_reader::indexes::sources::UTXOContentV10; use durs_bc_db_reader::{BalancesV10Datas, CertsExpirV10Datas}; use durs_common_tools::fatal_error; use durs_wot::data::{rusty::RustyWebOfTrust, WotId}; @@ -69,7 +69,7 @@ pub type Db = KvFileDbHandler; pub type DbReader = KvFileDbRoHandler; /// Forks tree meta datas (block number and hash only) -pub type ForksTreeV10Datas = durs_bc_db_reader::entities::fork_tree::ForkTree; +pub type ForksTreeV10Datas = durs_bc_db_reader::blocks::fork_tree::ForkTree; /// Database containing the wot graph (each node of the graph in an u32) pub type WotDB = RustyWebOfTrust; /// Memberships sorted by created block diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/block.rs b/lib/modules/blockchain/bc-db-writer/src/writers/block.rs index 631bd52fb4146561683c4800d5705583d7eed043..8b758502991ac8bab8a56f8811d6d5edf747cd86 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/block.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/block.rs @@ -17,10 +17,10 @@ use crate::DbError; use crate::*; use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::traits::Document; +use durs_bc_db_reader::blocks::fork_tree::ForkTree; +use durs_bc_db_reader::blocks::DbBlock; use durs_bc_db_reader::constants::*; -use durs_bc_db_reader::entities::block::DbBlock; -use durs_bc_db_reader::entities::current_meta_datas::CurrentMetaDataKey; -use durs_bc_db_reader::entities::fork_tree::ForkTree; +use durs_bc_db_reader::current_meta_datas::CurrentMetaDataKey; use durs_bc_db_reader::DbValue; use unwrap::unwrap; @@ -118,7 +118,7 @@ pub fn insert_new_fork_block( // As long as orphan blocks can succeed the last inserted block, they are inserted for stackable_block in - durs_bc_db_reader::readers::block::get_stackables_blocks(db, dal_block.blockstamp())? + durs_bc_db_reader::blocks::get_stackables_blocks(db, dal_block.blockstamp())? { let _ = insert_new_fork_block(db, fork_tree, stackable_block); } diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/certification.rs b/lib/modules/blockchain/bc-db-writer/src/writers/certification.rs index 0001db3814e4d92ff5bd442cc83ed02fca56cc27..62f3ce32ac64bed043807aaf8dc6ed4d0d01c1cd 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/certification.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/certification.rs @@ -19,7 +19,7 @@ use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use dup_crypto::keys::*; use durs_bc_db_reader::constants::*; -use durs_bc_db_reader::entities::identity::DbIdentity; +use durs_bc_db_reader::indexes::identities::DbIdentity; use durs_bc_db_reader::{CertsExpirV10Datas, DbReadable, DbValue}; use durs_wot::WotId; @@ -35,8 +35,9 @@ pub fn write_certification( written_timestamp: u64, ) -> Result<(), DbError> { // Get cert_chainable_on - let mut member_datas = durs_bc_db_reader::readers::identity::get_identity(db, &source_pubkey)? - .expect("Try to write certification with unexist certifier."); + let mut member_datas = + durs_bc_db_reader::indexes::identities::get_identity(db, &source_pubkey)? + .expect("Try to write certification with unexist certifier."); // Push new cert_chainable_on member_datas .cert_chainable_on diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/dividend.rs b/lib/modules/blockchain/bc-db-writer/src/writers/dividend.rs index 0943e99f31c25d43e10816964e7d6d0657e49893..738fc7fef0f381a86b563b4a0d7ba8cac78b37b2 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/dividend.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/dividend.rs @@ -17,7 +17,7 @@ use crate::*; use dubp_common_doc::BlockNumber; use dubp_user_docs::documents::transaction::*; use dup_crypto::keys::PubKey; -use durs_bc_db_reader::entities::sources::SourceAmount; +use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_reader::BalancesV10Datas; use std::collections::{HashMap, HashSet}; diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/fork_tree.rs b/lib/modules/blockchain/bc-db-writer/src/writers/fork_tree.rs index 3eaf641343c88049376ce21f3285bb3ae1490ab4..d7904b64a29d36cc71eda20ebb0c6ae1f007b70f 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/fork_tree.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/fork_tree.rs @@ -15,9 +15,9 @@ use crate::*; use dubp_common_doc::BlockHash; +use durs_bc_db_reader::blocks::fork_tree::ForkTree; use durs_bc_db_reader::constants::*; -use durs_bc_db_reader::entities::current_meta_datas::CurrentMetaDataKey; -use durs_bc_db_reader::entities::fork_tree::ForkTree; +use durs_bc_db_reader::current_meta_datas::CurrentMetaDataKey; /// SAve fork tree pub fn save_fork_tree(db: &Db, fork_tree: &ForkTree) -> Result<(), DbError> { @@ -99,7 +99,7 @@ mod test { use super::*; use dubp_currency_params::constants::DEFAULT_FORK_WINDOW_SIZE; - use durs_bc_db_reader::entities::fork_tree::{ForkTree, TreeNodeId}; + use durs_bc_db_reader::blocks::fork_tree::{ForkTree, TreeNodeId}; #[test] fn test_insert_new_head_block() -> Result<(), DbError> { diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/identity.rs b/lib/modules/blockchain/bc-db-writer/src/writers/identity.rs index e1f1d36a7b1287bb9813183ac48d30611d57f690..85a0b6c4b6847948cf2dcd2c2895b064b902fd72 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/identity.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/identity.rs @@ -21,7 +21,7 @@ use dubp_user_docs::documents::identity::IdentityDocumentV10; use dup_crypto::keys::PubKey; use dup_crypto::keys::PublicKey; use durs_bc_db_reader::constants::*; -use durs_bc_db_reader::entities::identity::{DbIdentity, DbIdentityState}; +use durs_bc_db_reader::indexes::identities::{DbIdentity, DbIdentityState}; use durs_bc_db_reader::{DbReadable, DbValue}; use durs_common_tools::fatal_error; use durs_wot::WotId; @@ -32,7 +32,7 @@ pub fn revert_create_identity( ms_db: &BinFreeStructDb<MsExpirV10Datas>, pubkey: &PubKey, ) -> Result<(), DbError> { - let dal_idty = durs_bc_db_reader::readers::identity::get_identity(db, pubkey)? + let dal_idty = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? .expect("Try to revert unexist idty."); // Remove membership ms_db.write(|db| { @@ -105,7 +105,7 @@ pub fn exclude_identity( exclusion_blockstamp: &Blockstamp, revert: bool, ) -> Result<(), DbError> { - let mut idty_datas = durs_bc_db_reader::readers::identity::get_identity(db, pubkey)? + let mut idty_datas = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? .expect("Try to exclude unexist idty."); idty_datas.state = if revert { match idty_datas.state { @@ -148,7 +148,7 @@ pub fn revoke_identity( explicit: bool, revert: bool, ) -> Result<(), DbError> { - let mut member_datas = durs_bc_db_reader::readers::identity::get_identity(db, pubkey)? + let mut member_datas = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? .expect("Try to revoke unexist idty."); member_datas.state = if revert { @@ -208,7 +208,7 @@ pub fn renewal_identity( revert: bool, ) -> Result<(), DbError> { // Get idty_datas - let mut idty_datas = durs_bc_db_reader::readers::identity::get_identity(db, pubkey)? + let mut idty_datas = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? .expect("Fatal error : try to renewal unknow identity !"); // Calculate new state value idty_datas.state = if revert { diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs index 315855d0f04daa2782f9a455c66f9d65a81fcdc8..2f3ee12ce2d3133727d839ecc6a77572fd5d3509 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs @@ -21,9 +21,9 @@ use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use dubp_user_docs::documents::identity::IdentityDocumentV10; use dup_crypto::keys::PubKey; -use durs_bc_db_reader::entities::block::DbBlock; -use durs_bc_db_reader::entities::fork_tree::ForkTree; -use durs_bc_db_reader::entities::sources::SourceAmount; +use durs_bc_db_reader::blocks::fork_tree::ForkTree; +use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_wot::WotId; use std::ops::Deref; diff --git a/lib/modules/blockchain/bc-db-writer/src/writers/transaction.rs b/lib/modules/blockchain/bc-db-writer/src/writers/transaction.rs index f9989386f8aacfc9afb11ecab7cbc0e23161a72f..d704c085297c6626e8e7355b319f067c6bf158ae 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/transaction.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/transaction.rs @@ -18,7 +18,7 @@ use durs_common_tools::fatal_error; use crate::*; use dubp_indexes::sindex::{SourceUniqueIdV10, UniqueIdUTXOv10}; -use durs_bc_db_reader::entities::sources::{SourceAmount, UTXOV10}; +use durs_bc_db_reader::indexes::sources::{SourceAmount, UTXOV10}; #[derive(Debug)] /// Transaction error diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index 65cc5165d99a779a83782c820b4b831ff9536d82..12c1ed525c5017b05bf6cc98cdb98a01e48eb821 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -123,17 +123,13 @@ pub fn dbex_bc(profile_path: PathBuf, _csv: bool, _query: DbExBcQuery) -> Result ); if let Some(current_blockstamp) = - durs_bc_db_reader::readers::current_meta_datas::get_current_blockstamp(&db)? + durs_bc_db_reader::current_meta_datas::get_current_blockstamp(&db)? { println!("Current block: #{}.", current_blockstamp); if let Some(current_block) = - durs_bc_db_reader::readers::block::get_block_in_local_blockchain( - &db, - current_blockstamp.id, - )? + durs_bc_db_reader::blocks::get_block_in_local_blockchain(&db, current_blockstamp.id)? { - let map_pubkey = - durs_bc_db_reader::readers::block::get_current_frame(¤t_block, &db)?; + let map_pubkey = durs_bc_db_reader::blocks::get_current_frame(¤t_block, &db)?; let mut vec = map_pubkey.iter().collect::<Vec<(&PubKey, &usize)>>(); vec.sort_by(|a, b| b.1.cmp(&a.1)); @@ -142,7 +138,7 @@ pub fn dbex_bc(profile_path: PathBuf, _csv: bool, _query: DbExBcQuery) -> Result println!("{},{},{}", &BLOCK, &USERNAME, &PUB_KEY); for (pub_key, v) in &vec { if let Ok(Some(identity)) = - durs_bc_db_reader::readers::identity::get_identity(&db, &pub_key) + durs_bc_db_reader::indexes::identities::get_identity(&db, &pub_key) { println!( "{},{},{}", @@ -157,7 +153,7 @@ pub fn dbex_bc(profile_path: PathBuf, _csv: bool, _query: DbExBcQuery) -> Result table.add_row(row![&BLOCK, &USERNAME, &PUB_KEY]); for (pub_key, v) in &vec { if let Ok(Some(identity)) = - durs_bc_db_reader::readers::identity::get_identity(&db, &pub_key) + durs_bc_db_reader::indexes::identities::get_identity(&db, &pub_key) { table.add_row(row![v, identity.idty_doc.username(), pub_key.to_string()]); } @@ -187,8 +183,8 @@ pub fn dbex_fork_tree(profile_path: PathBuf, _csv: bool) { load_db_duration.as_secs(), load_db_duration.subsec_millis() ); - let fork_tree = durs_bc_db_reader::readers::current_meta_datas::get_fork_tree(&db) - .expect("fail to get fork tree"); + let fork_tree = + durs_bc_db_reader::current_meta_datas::get_fork_tree(&db).expect("fail to get fork tree"); // Print all fork branches for (tree_node_id, blockstamp) in fork_tree.get_sheets() { debug!( @@ -230,7 +226,7 @@ pub fn dbex_tx(profile_path: PathBuf, _csv: bool, query: &DbExTxQuery) { let pubkey = if let Ok(ed25519_pubkey) = ed25519::PublicKey::from_base58(address_str) { PubKey::Ed25519(ed25519_pubkey) } else if let Some(pubkey) = - durs_bc_db_reader::readers::identity::get_pubkey_from_uid(&db, address_str) + durs_bc_db_reader::indexes::identities::get_pubkey_from_uid(&db, address_str) .expect("get_uid : DbError") { pubkey @@ -239,7 +235,7 @@ pub fn dbex_tx(profile_path: PathBuf, _csv: bool, query: &DbExTxQuery) { return; }; let address = UTXOConditionsGroup::Single(TransactionOutputCondition::Sig(pubkey)); - let address_balance = durs_bc_db_reader::readers::balance::get_address_balance( + let address_balance = durs_bc_db_reader::indexes::balance::get_address_balance( ¤cy_databases.balances_db, &address, ) @@ -296,7 +292,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { let currency_params = unwrap!(currency_params_db_datas).1; // get wot_index - let wot_index = durs_bc_db_reader::readers::identity::get_wot_index(&db).expect("DbError"); + let wot_index = durs_bc_db_reader::indexes::identities::get_wot_index(&db).expect("DbError"); // get wot_reverse_index let wot_reverse_index: HashMap<WotId, &PubKey> = @@ -304,7 +300,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { // get wot uid index let wot_uid_index = - durs_bc_db_reader::readers::identity::get_wot_uid_index(&db).expect("DbError"); + durs_bc_db_reader::indexes::identities::get_wot_uid_index(&db).expect("DbError"); // Open wot db let wot_db = BinFreeStructDb::File( @@ -381,7 +377,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { // Open blockchain database let db = durs_bc_db_reader::open_db_ro(&db_path.as_path()).expect("Fail to open DB."); // Get blocks_times - let all_blocks = durs_bc_db_reader::readers::block::get_blocks_in_local_blockchain( + let all_blocks = durs_bc_db_reader::blocks::get_blocks_in_local_blockchain( &db, BlockNumber(0), 10_000_000, @@ -424,7 +420,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { DbExWotQuery::MemberDatas(ref uid) => { println!(" Members count = {}.", members_count); if let Some(pubkey) = - durs_bc_db_reader::readers::identity::get_pubkey_from_uid(&db, uid) + durs_bc_db_reader::indexes::identities::get_pubkey_from_uid(&db, uid) .expect("get_pubkey_from_uid() : DbError !") { let wot_id = wot_index[&pubkey]; @@ -460,7 +456,7 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { .expect("Fail to get links source !"); println!("Certifiers : {}", sources.len()); for (i, source) in sources.iter().enumerate() { - let source_uid = durs_bc_db_reader::readers::identity::get_uid( + let source_uid = durs_bc_db_reader::indexes::identities::get_uid( &db, wot_reverse_index[&source], ) diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index c8519cbe163ae7a1266715f0d330a756450e526e..551f3bddb7dc9a941edcad099794d3bd4281073b 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -20,8 +20,8 @@ use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; use dubp_user_docs::documents::transaction::{TxAmount, TxBase}; use dup_crypto::keys::*; -use durs_bc_db_reader::entities::block::DbBlock; -use durs_bc_db_reader::entities::sources::SourceAmount; +use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_writer::writers::requests::*; use durs_bc_db_writer::BinFreeStructDb; use durs_common_tools::fatal_error; diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs index efd20a331e4deea13bd191202520544ffc485a4b..db03eb950e0e881bf3832660b158de87d550b14b 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs @@ -47,7 +47,7 @@ where // Rules that do not concern genesis block if block.number().0 > 0 { // Get previous block - let previous_block_opt = durs_bc_db_reader::readers::block::get_block_in_local_blockchain( + let previous_block_opt = durs_bc_db_reader::blocks::get_block_in_local_blockchain( db, BlockNumber(block.number().0 - 1), )?; diff --git a/lib/modules/blockchain/blockchain/src/dubp/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/mod.rs index e4207b3830d661f7ab0aa2f84cf01c1e21e0ecb7..f155897ac2b83b926204d96a959ea663c3f47cae 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/mod.rs @@ -24,7 +24,7 @@ use check::*; use dubp_block_doc::block::{BlockDocumentTrait, VerifyBlockHashError}; use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; -use durs_bc_db_reader::entities::block::DbBlock; +use durs_bc_db_reader::blocks::DbBlock; use durs_bc_db_writer::*; use unwrap::unwrap; @@ -68,7 +68,7 @@ pub fn check_and_apply_block( block_doc: BlockDocument, ) -> Result<CheckAndApplyBlockReturn, BlockError> { // Get BlockDocument && check if already have block - let already_have_block = durs_bc_db_reader::readers::block::already_have_block( + let already_have_block = durs_bc_db_reader::blocks::already_have_block( &bc.db, block_doc.blockstamp(), block_doc.previous_hash(), @@ -89,7 +89,7 @@ pub fn check_and_apply_block( ); // Detect expire_certs let blocks_expiring = Vec::with_capacity(0); - let expire_certs = durs_bc_db_reader::readers::certs::find_expire_certs( + let expire_certs = durs_bc_db_reader::indexes::certs::find_expire_certs( &bc.wot_databases.certs_db, blocks_expiring, )?; @@ -109,7 +109,7 @@ pub fn check_and_apply_block( let datas_path = durs_conf::get_datas_path(bc.profile_path.clone()); // Get and write currency params bc.currency_params = Some( - durs_bc_db_reader::readers::currency_params::get_and_write_currency_params( + durs_bc_db_reader::currency_params::get_and_write_currency_params( &datas_path, &block_doc, ), diff --git a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs index 15a09c4e0a8df001b5c8f0c01ac669ade875eaf5..9a84070479ec48a108d9061ea8940409a5928503 100644 --- a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs +++ b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs @@ -15,7 +15,7 @@ use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::Blockstamp; -use durs_bc_db_reader::entities::fork_tree::ForkTree; +use durs_bc_db_reader::blocks::fork_tree::ForkTree; use durs_bc_db_reader::DbReadable; use durs_bc_db_writer::DbError; use std::collections::HashSet; @@ -32,8 +32,7 @@ pub fn fork_resolution_algo<DB: DbReadable>( current_blockstamp: Blockstamp, invalid_blocks: &HashSet<Blockstamp>, ) -> Result<Option<Vec<Blockstamp>>, DbError> { - let current_bc_time = - durs_bc_db_reader::readers::current_meta_datas::get_current_common_time(db)?; + let current_bc_time = durs_bc_db_reader::current_meta_datas::get_current_common_time(db)?; debug!( "fork_resolution_algo({}, {})", @@ -54,7 +53,7 @@ pub fn fork_resolution_algo<DB: DbReadable>( let branch_head_blockstamp = branch.last().expect("safe unwrap"); let branch_head_median_time = - durs_bc_db_reader::readers::block::get_fork_block(db, *branch_head_blockstamp)? + durs_bc_db_reader::blocks::get_fork_block(db, *branch_head_blockstamp)? .expect("safe unwrap") .block .common_time(); @@ -97,7 +96,7 @@ mod tests { use crate::*; use dubp_block_doc::BlockDocument; use dubp_common_doc::{BlockHash, BlockNumber}; - use durs_bc_db_reader::entities::block::DbBlock; + use durs_bc_db_reader::blocks::DbBlock; #[test] fn test_fork_resolution_algo() -> Result<(), DbError> { @@ -131,13 +130,11 @@ mod tests { } // Local blockchain must contain at least `fork_window_size +2` blocks - assert!( - durs_bc_db_reader::readers::block::get_block_in_local_blockchain( - &db, - BlockNumber((fork_window_size + 1) as u32) - )? - .is_some() - ); + assert!(durs_bc_db_reader::blocks::get_block_in_local_blockchain( + &db, + BlockNumber((fork_window_size + 1) as u32) + )? + .is_some()); // Fork tree must contain at least `fork_window_size +2` blocks assert_eq!(fork_window_size, fork_tree.size()); diff --git a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs index 8f57e631e7ee0bacb301a5b1fd86aeea14e72af9..ba6be566820f91b3c88d611473fbad6e65f3c5a3 100644 --- a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs +++ b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs @@ -21,8 +21,8 @@ use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_user_docs::documents::transaction::{TxAmount, TxBase}; use dup_crypto::keys::*; -use durs_bc_db_reader::entities::block::DbBlock; -use durs_bc_db_reader::entities::sources::SourceAmount; +use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_writer::writers::requests::*; use durs_bc_db_writer::writers::transaction::DbTxV10; use durs_bc_db_writer::{BinFreeStructDb, DbError, TxV10Datas}; diff --git a/lib/modules/blockchain/blockchain/src/fork/rollback.rs b/lib/modules/blockchain/blockchain/src/fork/rollback.rs index 51afb4a21d5c37ba9e34b07b6936c648bf0506fd..14deab210ec5e3ca282b54499abb076063cc234b 100644 --- a/lib/modules/blockchain/blockchain/src/fork/rollback.rs +++ b/lib/modules/blockchain/blockchain/src/fork/rollback.rs @@ -31,10 +31,11 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) // Rollback (revert old branch) while bc.current_blockstamp.id.0 > last_common_block_number { if let Some(dal_block) = - durs_bc_db_reader::readers::block::get_fork_block(&bc.db, bc.current_blockstamp) - .unwrap_or_else(|_| { + durs_bc_db_reader::blocks::get_fork_block(&bc.db, bc.current_blockstamp).unwrap_or_else( + |_| { fatal_error!("revert block {} fail !", bc.current_blockstamp); - }) + }, + ) { let blockstamp = dal_block.block.blockstamp(); debug!("try to revert block #{}", blockstamp); @@ -88,8 +89,7 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) let mut new_branch_is_valid = true; let mut new_branch_blocks = Vec::with_capacity(new_bc_branch.len()); for blockstamp in &new_bc_branch { - if let Ok(Some(dal_block)) = - durs_bc_db_reader::readers::block::get_fork_block(&bc.db, *blockstamp) + if let Ok(Some(dal_block)) = durs_bc_db_reader::blocks::get_fork_block(&bc.db, *blockstamp) { new_branch_blocks.push(dal_block.clone()); if let Ok(CheckAndApplyBlockReturn::ValidMainBlock(ValidBlockApplyReqs( diff --git a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs index f2904355dc682bb976307a8b953b26f2c0b87864..1247e0b3427a318f2f09b322ff0d73bf85bb06ab 100644 --- a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs +++ b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs @@ -23,7 +23,7 @@ use unwrap::unwrap; pub fn apply_stackable_blocks(bc: &mut BlockchainModule) { 'blockchain: loop { let stackable_blocks = - durs_bc_db_reader::readers::block::get_stackables_blocks(&bc.db, bc.current_blockstamp) + durs_bc_db_reader::blocks::get_stackables_blocks(&bc.db, bc.current_blockstamp) .expect("Fatal error : Fail to read ForksDB !"); if stackable_blocks.is_empty() { break 'blockchain; diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index 4706747be31fd845b1a3a66d54379b56e3b4c2c6..8a857c9ddb653c62c94813f26dd27788be5a527d 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -61,7 +61,7 @@ use dubp_common_doc::traits::Document; use dubp_common_doc::Blockstamp; use dubp_currency_params::{CurrencyName, CurrencyParameters}; use dup_crypto::keys::*; -use durs_bc_db_reader::entities::fork_tree::ForkTree; +use durs_bc_db_reader::blocks::fork_tree::ForkTree; use durs_bc_db_writer::*; use durs_common_tools::fatal_error; use durs_message::events::*; @@ -190,16 +190,15 @@ impl BlockchainModule { let dbs_path = durs_conf::get_blockchain_db_path(profile_path.clone()); // Open databases - let fork_tree = durs_bc_db_reader::readers::current_meta_datas::get_fork_tree(&db) + let fork_tree = durs_bc_db_reader::current_meta_datas::get_fork_tree(&db) .unwrap_or_else(|_| fatal_error!("Fail to get fork tree.")); let wot_databases = WotsV10DBs::open(Some(&dbs_path)); let currency_databases = CurrencyV10DBs::open(Some(&dbs_path)); // Get current blockstamp - let current_blockstamp = - durs_bc_db_reader::readers::current_meta_datas::get_current_blockstamp(&db) - .expect("Fatal error : fail to read Blockchain DB !") - .unwrap_or_default(); + let current_blockstamp = durs_bc_db_reader::current_meta_datas::get_current_blockstamp(&db) + .expect("Fatal error : fail to read Blockchain DB !") + .unwrap_or_default(); // Get currency parameters let (currency_name, currency_params) = if let Some((currency_name, currency_params)) = @@ -215,7 +214,7 @@ impl BlockchainModule { // Get wot index let wot_index: HashMap<PubKey, WotId> = - durs_bc_db_reader::readers::identity::get_wot_index(&db) + durs_bc_db_reader::indexes::identities::get_wot_index(&db) .expect("Fatal eror : get_wot_index : Fail to read blockchain databases"); // Instanciate BlockchainModule diff --git a/lib/modules/blockchain/blockchain/src/requests/received.rs b/lib/modules/blockchain/blockchain/src/requests/received.rs index ec8218093fe5f8268938f6aa71609918d955bb92..197fd26c2af33c76d1cec8c0220d8f235c2f5887 100644 --- a/lib/modules/blockchain/blockchain/src/requests/received.rs +++ b/lib/modules/blockchain/blockchain/src/requests/received.rs @@ -37,12 +37,10 @@ pub fn receive_req( BlockchainRequest::CurrentBlock => { debug!("BlockchainModule : receive BlockchainRequest::CurrentBlock()"); - if let Ok(block_opt) = - durs_bc_db_reader::readers::block::get_block_in_local_blockchain( - &bc.db, - bc.current_blockstamp.id, - ) - { + if let Ok(block_opt) = durs_bc_db_reader::blocks::get_block_in_local_blockchain( + &bc.db, + bc.current_blockstamp.id, + ) { if let Some(block) = block_opt { debug!( "BlockchainModule : send_req_response(CurrentBlock({}))", @@ -73,10 +71,7 @@ pub fn receive_req( ); if let Ok(block_opt) = - durs_bc_db_reader::readers::block::get_block_in_local_blockchain( - &bc.db, - block_number, - ) + durs_bc_db_reader::blocks::get_block_in_local_blockchain(&bc.db, block_number) { if let Some(block) = block_opt { debug!( @@ -110,13 +105,11 @@ pub fn receive_req( first_block_number, count ); - if let Ok(blocks) = - durs_bc_db_reader::readers::block::get_blocks_in_local_blockchain( - &bc.db, - first_block_number, - count, - ) - { + if let Ok(blocks) = durs_bc_db_reader::blocks::get_blocks_in_local_blockchain( + &bc.db, + first_block_number, + count, + ) { if blocks.is_empty() { debug!( "BlockchainModule : Req : not found chunk (#{}, {}) in bdd !", @@ -152,7 +145,7 @@ pub fn receive_req( .map(|p| { ( p, - durs_bc_db_reader::readers::identity::get_uid(&bc.db, &p) + durs_bc_db_reader::indexes::identities::get_uid(&bc.db, &p) .expect("Fatal error : get_uid : Fail to read WotV10DB !"), ) }) @@ -160,7 +153,7 @@ pub fn receive_req( ), ); } /*BlockchainRequest::GetIdentities(filters) => { - let identities = durs_bc_db_reader::readers::identity::get_identities( + let identities = durs_bc_db_reader::indexes::identities::get_identities( &db, filters, bc.current_blockstamp.id, diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs index a42aa0bc5bf7c436a8e121d0946ac86608a06983..e70a5162b4160b18e4d6660fe82d0d88a836bcbb 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs @@ -30,8 +30,8 @@ pub fn execute( let blocks_job_begin = SystemTime::now(); // Get fork tree - let mut fork_tree = durs_bc_db_reader::readers::current_meta_datas::get_fork_tree(&db) - .expect("Fail to read DB."); + let mut fork_tree = + durs_bc_db_reader::current_meta_datas::get_fork_tree(&db).expect("Fail to read DB."); // Listen db requets let mut chunk_index = 0; diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs index 4a17edda9f6cf927cafb05d761a9304fd847357e..e0d7b6a07e25addeff481a21981267832319e085 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs @@ -96,7 +96,7 @@ impl BlockApplicator { // Find expire_certs let expire_certs = - durs_bc_db_reader::readers::certs::find_expire_certs(&self.certs_db, blocks_expiring) + durs_bc_db_reader::indexes::certs::find_expire_certs(&self.certs_db, blocks_expiring) .expect("find_expire_certs() : DbError"); // Get block blockstamp diff --git a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs index d288cca0c6247602542f9b6779d2e5788527aa22..8dcbfb644f826899128180c74cf9a86c24e932d4 100644 --- a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs @@ -98,7 +98,7 @@ pub fn json_reader_worker( let db_path = durs_conf::get_blockchain_db_path(profile_path); let db = durs_bc_db_reader::open_db_ro(&db_path).expect("Fail to open DB."); let current_blockstamp: Blockstamp = - durs_bc_db_reader::readers::current_meta_datas::get_current_blockstamp(&db) + durs_bc_db_reader::current_meta_datas::get_current_blockstamp(&db) .expect("get_current_blockstamp: Fail to read DB !") .unwrap_or_default(); info!("Local current blockstamp = {}", current_blockstamp); diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index f324aea93a584a400e7eafcb7932016971dbbf43..22508f607bea13fed1b64df7e7fc4db97853e869 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -189,7 +189,7 @@ pub fn local_sync<DC: DursConfTrait>( // Get local current blockstamp debug!("Get local current blockstamp..."); let current_blockstamp: Blockstamp = - durs_bc_db_reader::readers::current_meta_datas::get_current_blockstamp(&db) + durs_bc_db_reader::current_meta_datas::get_current_blockstamp(&db) .expect("DbError : fail to get current blockstamp !") .unwrap_or_default(); debug!("Success to get local current blockstamp."); @@ -202,7 +202,7 @@ pub fn local_sync<DC: DursConfTrait>( // Get wot index let wot_index: HashMap<PubKey, WotId> = - durs_bc_db_reader::readers::identity::get_wot_index(&db) + durs_bc_db_reader::indexes::identities::get_wot_index(&db) .expect("Fatal eror : get_wot_index : Fail to read blockchain databases"); // Start sync @@ -299,7 +299,7 @@ pub fn local_sync<DC: DursConfTrait>( let datas_path = durs_conf::get_datas_path(profile_path.clone()); if block_doc.number() == BlockNumber(0) { block_applicator.currency_params = Some( - durs_bc_db_reader::readers::currency_params::get_and_write_currency_params( + durs_bc_db_reader::currency_params::get_and_write_currency_params( &datas_path, &block_doc, ), diff --git a/lib/tools/dbs-tools/src/kv_db.rs b/lib/tools/dbs-tools/src/kv_db.rs index 6550fe3871eb8bfd3388b2fc3641b8fb420bc17e..4edbf67ebf74a059112da76c4fa9cbd74f068e60 100644 --- a/lib/tools/dbs-tools/src/kv_db.rs +++ b/lib/tools/dbs-tools/src/kv_db.rs @@ -23,5 +23,5 @@ pub use file::{ }; pub use rkv::{ store::multi::Iter, IntegerStore, MultiIntegerStore, MultiStore, - OwnedValue as KvFileDbOwnedValue, SingleStore, Value as KvFileDbValue, + OwnedValue as KvFileDbOwnedValue, Readable, SingleStore, Value as KvFileDbValue, };