diff --git a/lib/modules-lib/bc-db-reader/src/blocks.rs b/lib/modules-lib/bc-db-reader/src/blocks.rs index 46b4ff738b3338d2734de9067195f455fc86358a..6c0530e679988c67df5eaced5e7f5fcf526b5c57 100644 --- a/lib/modules-lib/bc-db-reader/src/blocks.rs +++ b/lib/modules-lib/bc-db-reader/src/blocks.rs @@ -31,7 +31,7 @@ use std::collections::HashMap; #[derive(Clone, Debug, Deserialize, Serialize)] /// A block as it is saved in a database -pub struct DbBlock { +pub struct BlockDb { /// Block document pub block: BlockDocument, /// List of certifications that expire in this block. @@ -40,7 +40,7 @@ pub struct DbBlock { pub expire_certs: Option<HashMap<(WotId, WotId), BlockNumber>>, } -impl DbBlock { +impl BlockDb { /// Get blockstamp pub fn blockstamp(&self) -> Blockstamp { self.block.blockstamp() @@ -88,7 +88,7 @@ pub fn already_have_block<DB: BcDbInReadTx>( .get_int_store(MAIN_BLOCKS) .get(db.r(), blockstamp.id.0)? { - if from_db_value::<DbBlock>(v)?.block.blockstamp() == blockstamp { + if from_db_value::<BlockDb>(v)?.block.blockstamp() == blockstamp { Ok(true) } else { Ok(false) @@ -102,7 +102,7 @@ pub fn already_have_block<DB: BcDbInReadTx>( pub fn get_block<DB: BcDbInReadTx>( db: &DB, blockstamp: Blockstamp, -) -> Result<Option<DbBlock>, DbError> { +) -> Result<Option<BlockDb>, DbError> { let opt_dal_block = get_db_block_in_local_blockchain(db, blockstamp.id)?; if opt_dal_block.is_none() { get_fork_block(db, blockstamp) @@ -115,7 +115,7 @@ pub fn get_block<DB: BcDbInReadTx>( pub fn get_fork_block<DB: BcDbInReadTx>( db: &DB, blockstamp: Blockstamp, -) -> Result<Option<DbBlock>, DbError> { +) -> Result<Option<BlockDb>, DbError> { let blockstamp_bytes: Vec<u8> = blockstamp.into(); if let Some(v) = db .db() @@ -155,7 +155,7 @@ pub fn get_block_in_local_blockchain<DB: BcDbInReadTx>( pub fn get_db_block_in_local_blockchain<DB: BcDbInReadTx>( db: &DB, block_number: BlockNumber, -) -> Result<Option<DbBlock>, DbError> { +) -> Result<Option<BlockDb>, DbError> { if let Some(v) = db .db() .get_int_store(MAIN_BLOCKS) @@ -178,7 +178,7 @@ pub fn get_blocks_in_local_blockchain<DB: BcDbInReadTx>( let mut current_block_number = first_block_number; while let Some(v) = bc_store.get(db.r(), current_block_number.0)? { - blocks.push(from_db_value::<DbBlock>(v)?.block); + blocks.push(from_db_value::<BlockDb>(v)?.block); count -= 1; if count > 0 { current_block_number = BlockNumber(current_block_number.0 + 1); @@ -194,7 +194,7 @@ pub fn get_blocks_in_local_blockchain<DB: BcDbInReadTx>( pub fn get_blocks_in_local_blockchain_by_numbers<DB: BcDbInReadTx>( db: &DB, numbers: Vec<BlockNumber>, -) -> Result<Vec<DbBlock>, DbError> { +) -> Result<Vec<BlockDb>, DbError> { numbers .into_iter() .filter_map(|n| match get_db_block_in_local_blockchain(db, n) { @@ -202,7 +202,7 @@ pub fn get_blocks_in_local_blockchain_by_numbers<DB: BcDbInReadTx>( Ok(None) => None, Err(e) => Some(Err(e)), }) - .collect::<Result<Vec<DbBlock>, DbError>>() + .collect::<Result<Vec<BlockDb>, DbError>>() } /// Get current frame of calculating members @@ -237,7 +237,7 @@ pub fn get_current_frame<DB: BcDbInReadTx>( pub fn get_stackables_blocks<DB: BcDbInReadTx>( db: &DB, current_blockstamp: Blockstamp, -) -> Result<Vec<DbBlock>, DbError> { +) -> Result<Vec<BlockDb>, DbError> { get_orphan_blocks(db, current_blockstamp) } @@ -245,7 +245,7 @@ pub fn get_stackables_blocks<DB: BcDbInReadTx>( pub fn get_orphan_blocks<DB: BcDbInReadTx>( db: &DB, blockstamp: PreviousBlockstamp, -) -> Result<Vec<DbBlock>, DbError> { +) -> Result<Vec<BlockDb>, DbError> { let blockstamp_bytes: Vec<u8> = blockstamp.into(); if let Some(v) = db .db() @@ -261,7 +261,7 @@ pub fn get_orphan_blocks<DB: BcDbInReadTx>( .get_store(FORK_BLOCKS) .get(db.r(), &orphan_blockstamp_bytes)? { - orphan_blocks.push(from_db_value::<DbBlock>(v)?); + orphan_blocks.push(from_db_value::<BlockDb>(v)?); } else { return Err(DbError::DBCorrupted); } diff --git a/lib/modules-lib/bc-db-reader/src/constants.rs b/lib/modules-lib/bc-db-reader/src/constants.rs index 5eabbb72cb918650b711c70eb8f6d52f6ffd0767..9e160a7daf7a3202d9e50fc197371d70246263ca 100644 --- a/lib/modules-lib/bc-db-reader/src/constants.rs +++ b/lib/modules-lib/bc-db-reader/src/constants.rs @@ -25,10 +25,10 @@ pub static DEFAULT_PAGE_SIZE: &usize = &50; /// Current meta datas (CurrentMetaDataKey, ?) pub static CURRENT_METAS_DATAS: &str = "cmd"; -/// Fork blocks referenced in tree or in orphan blockstamps (Blockstamp, DbBlock) +/// Fork blocks referenced in tree or in orphan blockstamps (Blockstamp, BlockDb) pub static FORK_BLOCKS: &str = "fb"; -/// Blocks in main branch (BlockNumber, DbBlock) +/// Blocks in main branch (BlockNumber, BlockDb) pub static MAIN_BLOCKS: &str = "bc"; /// Blockstamp orphaned (no parent block) indexed by their previous blockstamp (PreviousBlockstamp, Vec<Blockstamp>) @@ -37,7 +37,7 @@ pub static ORPHAN_BLOCKSTAMP: &str = "ob"; /// Wot id index (PubKey, WotId) pub static WOT_ID_INDEX: &str = "wii"; -/// Identities (WotId, DbIdentity) +/// Identities (WotId, IdentityDb) pub static IDENTITIES: &str = "idty"; /// Memberships sorted by created block (BlockNumber, Vec<WotId>) diff --git a/lib/modules-lib/bc-db-reader/src/indexes/identities.rs b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs index 80eeddc859c5286e3afaa93d2c733ed7d7d75745..1dbae742536bd864c189e9d9e3f03a7361d15e64 100644 --- a/lib/modules-lib/bc-db-reader/src/indexes/identities.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs @@ -57,7 +57,7 @@ impl IdentitiesFilter { #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] /// Identity state -pub enum DbIdentityState { +pub enum IdentityStateDb { /// Member Member(Vec<usize>), /// Expire Member @@ -72,11 +72,11 @@ pub enum DbIdentityState { #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)] /// Identity in database -pub struct DbIdentity { +pub struct IdentityDb { /// Identity hash pub hash: String, /// Identity state - pub state: DbIdentityState, + pub state: IdentityStateDb, /// Blockstamp the identity was written pub joined_on: Blockstamp, /// Blockstamp the identity was expired @@ -100,7 +100,7 @@ pub fn get_identities<DB: BcDbInReadTx>( db: &DB, filters: IdentitiesFilter, current_block_id: BlockNumber, -) -> Result<Vec<DbIdentity>, DbError> { +) -> Result<Vec<IdentityDb>, DbError> { if let Some(pubkey) = filters.by_pubkey { if let Some(idty) = get_identity_by_pubkey(db, &pubkey)? { Ok(vec![idty]) @@ -108,7 +108,7 @@ pub fn get_identities<DB: BcDbInReadTx>( Ok(vec![]) } } else { - let mut identities: Vec<DbIdentity> = Vec::new(); + let mut identities: Vec<IdentityDb> = Vec::new(); let greatest_wot_id = crate::current_meta_datas::get_greatest_wot_id_(db)?; for wot_id in 0..=greatest_wot_id.0 { if let Some(db_idty) = get_identity_by_wot_id(db, WotId(wot_id))? { @@ -139,7 +139,7 @@ pub fn get_identities<DB: BcDbInReadTx>( pub fn get_identity_by_pubkey<DB: BcDbInReadTx>( db: &DB, pubkey: &PubKey, -) -> Result<Option<DbIdentity>, DbError> { +) -> Result<Option<IdentityDb>, DbError> { if let Some(wot_id) = get_wot_id(db, pubkey)? { get_identity_by_wot_id(db, wot_id) } else { @@ -152,7 +152,7 @@ pub fn get_identity_by_pubkey<DB: BcDbInReadTx>( pub fn get_identity_by_wot_id<DB: BcDbInReadTx>( db: &DB, wot_id: WotId, -) -> Result<Option<DbIdentity>, DbError> { +) -> Result<Option<IdentityDb>, DbError> { if let Some(v) = db .db() .get_int_store(IDENTITIES) @@ -169,7 +169,7 @@ pub fn get_identity_by_wot_id<DB: BcDbInReadTx>( pub fn get_idty_state_by_pubkey<DB: BcDbInReadTx>( db: &DB, pubkey: &PubKey, -) -> Result<Option<DbIdentityState>, DbError> { +) -> Result<Option<IdentityStateDb>, DbError> { Ok(get_identity_by_pubkey(db, pubkey)?.map(|db_idty| db_idty.state)) } @@ -246,10 +246,10 @@ mod test { use durs_common_tests_tools::collections::slice_same_elems; use durs_dbs_tools::kv_db::KvFileDbHandler; - fn gen_mock_dal_idty(pubkey: PubKey, created_block_id: BlockNumber) -> DbIdentity { - DbIdentity { + fn gen_mock_dal_idty(pubkey: PubKey, created_block_id: BlockNumber) -> IdentityDb { + IdentityDb { hash: "".to_owned(), - state: DbIdentityState::Member(vec![]), + state: IdentityStateDb::Member(vec![]), joined_on: Blockstamp::default(), expired_on: None, revoked_on: None, diff --git a/lib/modules-lib/bc-db-reader/src/tools.rs b/lib/modules-lib/bc-db-reader/src/tools.rs index d15e58aaf04dd16ad83bd20625977094c068feb8..cda4c9800e1ec01673566fa925560edf1a190371 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::blocks::DbBlock; +use crate::blocks::BlockDb; use dubp_block_doc::block::BlockDocumentTrait; use dup_crypto::keys::PubKey; use durs_common_tools::fatal_error; @@ -24,7 +24,7 @@ use std::collections::HashMap; /// Compute median issuers frame pub fn compute_median_issuers_frame<S: std::hash::BuildHasher>( - current_block: &DbBlock, + current_block: &BlockDb, current_frame: &HashMap<PubKey, usize, S>, ) -> usize { if !current_frame.is_empty() { diff --git a/lib/modules-lib/bc-db-reader/src/traits.rs b/lib/modules-lib/bc-db-reader/src/traits.rs index bf4a36e737a19770b4142bfc93c97695cc1f61d3..ab51e9b4b663d7418e052bc241b47946979c4567 100644 --- a/lib/modules-lib/bc-db-reader/src/traits.rs +++ b/lib/modules-lib/bc-db-reader/src/traits.rs @@ -16,8 +16,8 @@ //! BlockChain Datas Access Layer in Read-Only mode. // ! Define read only trait -use crate::blocks::DbBlock; -use crate::indexes::identities::{DbIdentity, DbIdentityState}; +use crate::blocks::BlockDb; +use crate::indexes::identities::{IdentityDb, IdentityStateDb}; use crate::{BcDbWithReaderStruct, DbReadable, DbReader}; use dubp_common_doc::{BlockNumber, Blockstamp}; use dup_crypto::keys::PubKey; @@ -73,20 +73,20 @@ impl<'a> BcDbWithReader for MockBcDbInReadTx { #[cfg_attr(feature = "mock", automock)] pub trait BcDbInReadTx: BcDbWithReader { fn get_current_blockstamp(&self) -> Result<Option<Blockstamp>, DbError>; - fn get_current_block(&self) -> Result<Option<DbBlock>, DbError>; + fn get_current_block(&self) -> Result<Option<BlockDb>, DbError>; fn get_db_block_in_local_blockchain( &self, block_number: BlockNumber, - ) -> Result<Option<DbBlock>, DbError>; + ) -> Result<Option<BlockDb>, DbError>; #[cfg(feature = "client-indexer")] fn get_db_blocks_in_local_blockchain( &self, numbers: Vec<BlockNumber>, - ) -> Result<Vec<DbBlock>, DbError>; + ) -> Result<Vec<BlockDb>, DbError>; fn get_uid_from_pubkey(&self, pubkey: &PubKey) -> Result<Option<String>, DbError>; fn get_idty_state_by_pubkey(&self, pubkey: &PubKey) - -> Result<Option<DbIdentityState>, DbError>; - fn get_identity_by_pubkey(&self, pubkey: &PubKey) -> Result<Option<DbIdentity>, DbError>; + -> Result<Option<IdentityStateDb>, DbError>; + fn get_identity_by_pubkey(&self, pubkey: &PubKey) -> Result<Option<IdentityDb>, DbError>; } impl<T> BcDbInReadTx for T @@ -98,7 +98,7 @@ where crate::current_meta_datas::get_current_blockstamp(self) } #[inline] - fn get_current_block(&self) -> Result<Option<DbBlock>, DbError> { + fn get_current_block(&self) -> Result<Option<BlockDb>, DbError> { if let Some(current_blockstamp) = crate::current_meta_datas::get_current_blockstamp(self)? { crate::blocks::get_db_block_in_local_blockchain(self, current_blockstamp.id) } else { @@ -109,7 +109,7 @@ where fn get_db_block_in_local_blockchain( &self, block_number: BlockNumber, - ) -> Result<Option<DbBlock>, DbError> { + ) -> Result<Option<BlockDb>, DbError> { crate::blocks::get_db_block_in_local_blockchain(self, block_number) } #[cfg(feature = "client-indexer")] @@ -117,7 +117,7 @@ where fn get_db_blocks_in_local_blockchain( &self, numbers: Vec<BlockNumber>, - ) -> Result<Vec<DbBlock>, DbError> { + ) -> Result<Vec<BlockDb>, DbError> { crate::blocks::get_blocks_in_local_blockchain_by_numbers(self, numbers) } #[inline] @@ -128,11 +128,11 @@ where fn get_idty_state_by_pubkey( &self, pubkey: &PubKey, - ) -> Result<Option<DbIdentityState>, DbError> { + ) -> Result<Option<IdentityStateDb>, DbError> { crate::indexes::identities::get_idty_state_by_pubkey(self, pubkey) } #[inline] - fn get_identity_by_pubkey(&self, pubkey: &PubKey) -> Result<Option<DbIdentity>, DbError> { + fn get_identity_by_pubkey(&self, pubkey: &PubKey) -> Result<Option<IdentityDb>, DbError> { crate::indexes::identities::get_identity_by_pubkey(self, pubkey) } } diff --git a/lib/modules/blockchain/bc-db-writer/src/blocks.rs b/lib/modules/blockchain/bc-db-writer/src/blocks.rs index 4c4ab106be29e487f6c0124616f436c860709018..8bfa0758a448afe748ca69604de40123536e5582 100644 --- a/lib/modules/blockchain/bc-db-writer/src/blocks.rs +++ b/lib/modules/blockchain/bc-db-writer/src/blocks.rs @@ -21,7 +21,7 @@ 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::blocks::BlockDb; use durs_bc_db_reader::constants::*; use durs_bc_db_reader::{from_db_value, DbValue}; use unwrap::unwrap; @@ -32,7 +32,7 @@ pub fn insert_new_head_block( db: &Db, w: &mut DbWriter, fork_tree: Option<&mut ForkTree>, - dal_block: DbBlock, + dal_block: BlockDb, ) -> Result<(), DbError> { // Serialize datas let bin_dal_block = durs_dbs_tools::to_bytes(&dal_block)?; @@ -84,7 +84,7 @@ pub fn insert_new_fork_block( db: &Db, w: &mut DbWriter, fork_tree: &mut ForkTree, - dal_block: DbBlock, + dal_block: BlockDb, ) -> Result<bool, DbError> { let bin_dal_block = durs_dbs_tools::to_bytes(&dal_block)?; let blockstamp_bytes: Vec<u8> = dal_block.blockstamp().into(); diff --git a/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs b/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs index 92c8e4d7d20ad021f12056b106da05399ca0e0eb..fdfae05a0eda189f5a17204ddca9ecddec890b96 100644 --- a/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs +++ b/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs @@ -20,7 +20,7 @@ use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use durs_bc_db_reader::constants::*; -use durs_bc_db_reader::indexes::identities::DbIdentity; +use durs_bc_db_reader::indexes::identities::IdentityDb; use durs_bc_db_reader::{from_db_value, DbReadable, DbValue}; use durs_wot::WotId; @@ -78,7 +78,7 @@ pub fn revert_write_cert( // Pop last cert_chainable_on let identities_store = db.get_int_store(IDENTITIES); if let Some(v) = identities_store.get(w.as_ref(), source.0 as u32)? { - let mut member_datas = from_db_value::<DbIdentity>(v)?; + let mut member_datas = from_db_value::<IdentityDb>(v)?; member_datas.cert_chainable_on.pop(); let bin_member_datas = durs_dbs_tools::to_bytes(&member_datas)?; identities_store.put( diff --git a/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs b/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs index e524c028afc6cd52c919feae5cc4d0e6d3e33b5e..10e5c88b0d13cd28bf33d0b39e6f6bf8a90c290a 100644 --- a/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs +++ b/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs @@ -25,7 +25,7 @@ use dup_crypto::keys::PublicKey; use durs_bc_db_reader::constants::*; use durs_bc_db_reader::current_meta_datas::CurrentMetaDataKey; use durs_bc_db_reader::indexes::identities::get_wot_id; -use durs_bc_db_reader::indexes::identities::{DbIdentity, DbIdentityState}; +use durs_bc_db_reader::indexes::identities::{IdentityDb, IdentityStateDb}; use durs_bc_db_reader::{DbReadable, DbValue}; use durs_common_tools::fatal_error; use durs_wot::WotId; @@ -86,9 +86,9 @@ pub fn create_identity( ) -> Result<(), DbError> { let mut idty_doc = idty_doc.clone(); idty_doc.reduce(); - let idty = DbIdentity { + let idty = IdentityDb { hash: "0".to_string(), - state: DbIdentityState::Member(vec![0]), + state: IdentityStateDb::Member(vec![0]), joined_on: current_blockstamp, expired_on: None, revoked_on: None, @@ -131,15 +131,15 @@ pub fn exclude_identity( .expect("Try to exclude unexist idty."); idty_datas.state = if revert { match idty_datas.state { - DbIdentityState::ExpireMember(renewed_counts) => { - DbIdentityState::Member(renewed_counts) + IdentityStateDb::ExpireMember(renewed_counts) => { + IdentityStateDb::Member(renewed_counts) } _ => fatal_error!("Try to revert exclusion for a no excluded identity !"), } } else { match idty_datas.state { - DbIdentityState::Member(renewed_counts) => { - DbIdentityState::ExpireMember(renewed_counts) + IdentityStateDb::Member(renewed_counts) => { + IdentityStateDb::ExpireMember(renewed_counts) } _ => fatal_error!("Try to exclude for an already excluded/revoked identity !"), } @@ -177,25 +177,25 @@ pub fn revoke_identity( member_datas.state = if revert { match member_datas.state { - DbIdentityState::ExplicitRevoked(renewed_counts) => { - DbIdentityState::Member(renewed_counts) + IdentityStateDb::ExplicitRevoked(renewed_counts) => { + IdentityStateDb::Member(renewed_counts) } - DbIdentityState::ExplicitExpireRevoked(renewed_counts) - | DbIdentityState::ImplicitRevoked(renewed_counts) => { - DbIdentityState::ExpireMember(renewed_counts) + IdentityStateDb::ExplicitExpireRevoked(renewed_counts) + | IdentityStateDb::ImplicitRevoked(renewed_counts) => { + IdentityStateDb::ExpireMember(renewed_counts) } _ => fatal_error!("Try to revert revoke_identity() for a no revoked idty !"), } } else { match member_datas.state { - DbIdentityState::ExpireMember(renewed_counts) => { - DbIdentityState::ExplicitExpireRevoked(renewed_counts) + IdentityStateDb::ExpireMember(renewed_counts) => { + IdentityStateDb::ExplicitExpireRevoked(renewed_counts) } - DbIdentityState::Member(renewed_counts) => { + IdentityStateDb::Member(renewed_counts) => { if explicit { - DbIdentityState::ExplicitRevoked(renewed_counts) + IdentityStateDb::ExplicitRevoked(renewed_counts) } else { - DbIdentityState::ImplicitRevoked(renewed_counts) + IdentityStateDb::ImplicitRevoked(renewed_counts) } } _ => fatal_error!("Try to revert revoke an already revoked idty !"), @@ -237,28 +237,28 @@ pub fn renewal_identity( // Calculate new state value idty_datas.state = if revert { match idty_datas.state { - DbIdentityState::Member(renewed_counts) => { + IdentityStateDb::Member(renewed_counts) => { let mut new_renewed_counts = renewed_counts.clone(); new_renewed_counts[renewed_counts.len() - 1] -= 1; if new_renewed_counts[renewed_counts.len() - 1] > 0 { - DbIdentityState::Member(new_renewed_counts) + IdentityStateDb::Member(new_renewed_counts) } else { - DbIdentityState::ExpireMember(new_renewed_counts) + IdentityStateDb::ExpireMember(new_renewed_counts) } } _ => fatal_error!("Try to revert renewal_identity() for an excluded or revoked idty !"), } } else { match idty_datas.state { - DbIdentityState::Member(renewed_counts) => { + IdentityStateDb::Member(renewed_counts) => { let mut new_renewed_counts = renewed_counts.clone(); new_renewed_counts[renewed_counts.len() - 1] += 1; - DbIdentityState::Member(new_renewed_counts) + IdentityStateDb::Member(new_renewed_counts) } - DbIdentityState::ExpireMember(renewed_counts) => { + IdentityStateDb::ExpireMember(renewed_counts) => { let mut new_renewed_counts = renewed_counts.clone(); new_renewed_counts.push(0); - DbIdentityState::Member(new_renewed_counts) + IdentityStateDb::Member(new_renewed_counts) } _ => fatal_error!("Try to renewed a revoked identity !"), } 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 07865a248a6b86417c7ee8bf0d58fd043ae38434..c640d12fbc44cef936b317fa23e4053191e3d006 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs @@ -21,7 +21,7 @@ use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; use dubp_user_docs::documents::identity::IdentityDocumentV10; use dup_crypto::keys::PubKey; use durs_bc_db_reader::blocks::fork_tree::ForkTree; -use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_wot::WotId; use std::ops::Deref; @@ -41,9 +41,9 @@ pub enum DBsWriteRequest { /// Contain a pending write request for blocks databases pub enum BlocksDBsWriteQuery { /// Write block - WriteBlock(DbBlock), + WriteBlock(BlockDb), /// Revert block - RevertBlock(DbBlock), + RevertBlock(BlockDb), } impl BlocksDBsWriteQuery { diff --git a/lib/modules/blockchain/blockchain/src/dubp.rs b/lib/modules/blockchain/blockchain/src/dubp.rs index 4b07984f1134c66546c94d46e3f904806bf4cb61..84fdf9e20e4b379beaa6fd1d97726817d67a32d0 100644 --- a/lib/modules/blockchain/blockchain/src/dubp.rs +++ b/lib/modules/blockchain/blockchain/src/dubp.rs @@ -25,7 +25,7 @@ use dubp_block_doc::block::BlockDocumentTrait; use dubp_block_doc::BlockDocument; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; -use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::DbError; use durs_bc_db_writer::{BcDbRwWithWriter, Db, DbWriter}; use unwrap::unwrap; @@ -135,7 +135,7 @@ fn treat_unchainable_block( block_doc.blockstamp() ); - let dal_block = DbBlock { + let dal_block = BlockDb { block: block_doc.clone(), expire_certs: None, }; diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index 517be653c0b993bb0422c3f7e770d4eac1f1e35e..bd07fc2e41ec86092ec335a9f0e72aed9b9c2c51 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -20,7 +20,7 @@ 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::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::indexes::sources::get_block_consumed_sources_; use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_writer::writers::requests::*; @@ -281,8 +281,8 @@ pub fn apply_valid_block_v10<W: WebOfTrust>( }, ); }*/ - // Create DbBlock - let block_db = DbBlock { + // Create BlockDb + let block_db = BlockDb { block: BlockDocument::V10(block), expire_certs: Some(expire_certs.clone()), }; diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs b/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs index 5010748ee4da5799a645a2318395fd7f7b196bed..bc5c5e5979cdd4927a5fd03dedd4e26c6de5efa5 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/global/rules.rs @@ -21,7 +21,7 @@ mod br_g100; use dubp_block_doc::BlockDocument; //use dup_crypto::keys::PubKey; -use durs_bc_db_reader::indexes::identities::DbIdentityState; +use durs_bc_db_reader::indexes::identities::IdentityStateDb; use durs_bc_db_reader::{BcDbInReadTx, DbError}; //use durs_wot::*; use failure::Fail; @@ -52,7 +52,7 @@ pub enum InvalidRuleError { #[fail(display = "BR_G100: issuer is not a member (not exist)")] IssuerNotExist, #[fail(display = "BR_G100: issuer is not a member (issuer_state={:?})", _0)] - NotMemberIssuer(DbIdentityState), + NotMemberIssuer(IdentityStateDb), #[fail(display = "BR_G04: wrong issuers count")] _WrongIssuersCount, #[fail(display = "BR_G05: wrong issuers frame size")] diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/global/rules/br_g100.rs b/lib/modules/blockchain/blockchain/src/dubp/check/global/rules/br_g100.rs index 3cb201dfc9dc1fb0ab8af38b06690dc47938dd4b..2b51f679d14a1282e04e01dfd63c054a3f14b400 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/global/rules/br_g100.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/global/rules/br_g100.rs @@ -17,7 +17,7 @@ use super::{InvalidRuleError, RuleDatas, RuleNotSyncDatas}; use dubp_common_doc::traits::Document; -use durs_bc_db_reader::indexes::identities::DbIdentityState; +use durs_bc_db_reader::indexes::identities::IdentityStateDb; use durs_bc_db_reader::BcDbInReadTx; use rules_engine::rule::{Rule, RuleFn, RuleNumber}; use rules_engine::ProtocolVersion; @@ -42,7 +42,7 @@ fn v10<DB: BcDbInReadTx>( let RuleNotSyncDatas { ref db } = not_sync_datas; if let Some(idty_state) = db.get_idty_state_by_pubkey(&block.issuers()[0])? { - if let DbIdentityState::Member(_) = idty_state { + if let IdentityStateDb::Member(_) = idty_state { Ok(()) } else { Err(InvalidRuleError::NotMemberIssuer(idty_state)) @@ -98,7 +98,7 @@ mod tests { .expect_get_idty_state_by_pubkey() .times(1) .with(eq(pubkey)) - .returning(|_| Ok(Some(DbIdentityState::Member(vec![1])))); + .returning(|_| Ok(Some(IdentityStateDb::Member(vec![1])))); let mut datas = RuleDatas { block: &block, diff --git a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs index 725c91c633cc49f9f5c80b9b4a7436fdd99a86df..2acf65e3b10ce657ad5917c49c184d60c156cd50 100644 --- a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs +++ b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs @@ -101,7 +101,7 @@ mod tests { use crate::*; use dubp_block_doc::BlockDocument; use dubp_common_doc::{BlockHash, BlockNumber}; - use durs_bc_db_reader::blocks::DbBlock; + use durs_bc_db_reader::blocks::BlockDb; #[test] fn test_fork_resolution_algo() -> Result<(), DbError> { @@ -129,7 +129,7 @@ mod tests { &db, &mut w, Some(&mut fork_tree), - DbBlock { + BlockDb { block: block.clone(), expire_certs: None, }, @@ -201,7 +201,7 @@ mod tests { &db, &mut w, &mut fork_tree, - DbBlock { + BlockDb { block: BlockDocument::V10( dubp_blocks_tests_tools::mocks::gen_empty_timed_block_v10( determining_blockstamp, @@ -282,7 +282,7 @@ mod tests { db, &mut w, fork_tree, - DbBlock { + BlockDb { block: block.clone(), expire_certs: None, }, diff --git a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs index 81b18c3d6fa97bebc2c83f7db34b1198c413e0de..a8f1b2e7453bd300db66b2b25ea1ee773fe0640a 100644 --- a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs +++ b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs @@ -20,7 +20,7 @@ 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::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::indexes::sources::SourceAmount; use durs_bc_db_writer::writers::requests::*; use durs_bc_db_writer::{BinFreeStructDb, DbError}; @@ -54,7 +54,7 @@ impl From<DbError> for RevertValidBlockError { } pub fn revert_block<W: WebOfTrust>( - dal_block: DbBlock, + dal_block: BlockDb, wot_index: &mut HashMap<PubKey, WotId>, wot_db: &BinFreeStructDb<W>, ) -> Result<ValidBlockRevertReqs, RevertValidBlockError> { @@ -246,7 +246,7 @@ pub fn revert_block_v10<W: WebOfTrust>( // Return DBs requests Ok(ValidBlockRevertReqs { new_current_blockstamp: block.previous_blockstamp(), - block_query: BlocksDBsWriteQuery::RevertBlock(DbBlock { + block_query: BlocksDBsWriteQuery::RevertBlock(BlockDb { block: BlockDocument::V10(block), expire_certs: Some(expire_certs), }), diff --git a/lib/modules/gva/src/schema/entities/block.rs b/lib/modules/gva/src/schema/entities/block.rs index 10e54692e20b1d6d51fbbe107663ef765fe57076..1d8b8d6071f38925b02897005a4108902b087de3 100644 --- a/lib/modules/gva/src/schema/entities/block.rs +++ b/lib/modules/gva/src/schema/entities/block.rs @@ -20,7 +20,7 @@ use crate::schema::query_trails::QueryTrailBlockExtensions; use chrono::NaiveDateTime; use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::traits::Document; -use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::{BcDbInReadTx, DbError}; use durs_common_tools::fatal_error; use juniper::{Executor, FieldResult}; @@ -45,7 +45,7 @@ impl Block { // Convert BlockDb (db entity) into Block (gva entity) pub(crate) fn from_block_db<DB: BcDbInReadTx>( db: &DB, - block_db: DbBlock, + block_db: BlockDb, ask_issuer_name: bool, ) -> Result<Block, DbError> { Ok(Block { @@ -61,7 +61,7 @@ impl Block { hash: block_db .block .hash() - .unwrap_or_else(|| fatal_error!("DbBlock without hash.")) + .unwrap_or_else(|| fatal_error!("BlockDb without hash.")) .to_string(), common_time: NaiveDateTime::from_timestamp(block_db.block.common_time() as i64, 0), pow_min: block_db.block.pow_min() as i32, diff --git a/lib/modules/gva/src/schema/queries/block.rs b/lib/modules/gva/src/schema/queries/block.rs index fc9253a510d619b04fc7cf108ab7ba0f04fcefff..8f6ad8e4758c66e1e21f653be07b5a87b71aa440 100644 --- a/lib/modules/gva/src/schema/queries/block.rs +++ b/lib/modules/gva/src/schema/queries/block.rs @@ -46,7 +46,7 @@ mod tests { use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp}; use dup_crypto::hashs::Hash; use dup_crypto_tests_tools::mocks::{hash, pubkey}; - use durs_bc_db_reader::blocks::DbBlock; + use durs_bc_db_reader::blocks::BlockDb; use mockall::predicate::eq; use serde_json::json; @@ -70,7 +70,7 @@ mod tests { ); block.issuers = vec![pubkey('B')]; block.pow_min = 70; - Ok(Some(DbBlock { + Ok(Some(BlockDb { block: BlockDocument::V10(block), expire_certs: None, })) diff --git a/lib/modules/gva/src/schema/queries/blocks.rs b/lib/modules/gva/src/schema/queries/blocks.rs index fa4a97c1d497be9640a30bf80d2517902f43536f..1defe5e34d2df9989af1eb7a9f3bbd549b31e80a 100644 --- a/lib/modules/gva/src/schema/queries/blocks.rs +++ b/lib/modules/gva/src/schema/queries/blocks.rs @@ -21,7 +21,7 @@ use crate::schema::inputs::block_interval::{BlockInterval, FilledBlockInterval}; use crate::schema::inputs::paging::{FilledPaging, Paging}; use crate::schema::inputs::sort_order::SortOrder; use dubp_common_doc::BlockNumber; -use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_reader::{BcDbInReadTx, DbError}; use juniper_from_schema::{QueryTrail, Walked}; @@ -76,7 +76,7 @@ pub(crate) fn execute<DB: BcDbInReadTx>( .collect(); // Get blocks - let blocks: Vec<DbBlock> = db.get_db_blocks_in_local_blockchain(blocks_numbers)?; + let blocks: Vec<BlockDb> = db.get_db_blocks_in_local_blockchain(blocks_numbers)?; // Convert BlockDb (db entity) into Block (gva entity) let ask_field_issuer_name = BlocksPage::ask_field_blocks_issuer_name(trail); @@ -106,7 +106,7 @@ mod tests { use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp}; use dup_crypto::hashs::Hash; use dup_crypto_tests_tools::mocks::{hash, pubkey}; - use durs_bc_db_reader::blocks::DbBlock; + use durs_bc_db_reader::blocks::BlockDb; use mockall::predicate::eq; use serde_json::json; @@ -246,15 +246,15 @@ mod tests { .with(eq(vec![BlockNumber(2), BlockNumber(3), BlockNumber(4)])) .returning(move |_| { Ok(vec![ - DbBlock { + BlockDb { block: BlockDocument::V10(block_2.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(block_3.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(current_block.clone()), expire_certs: None, }, @@ -308,11 +308,11 @@ mod tests { .with(eq(vec![BlockNumber(0), BlockNumber(2)])) .returning(move |_| { Ok(vec![ - DbBlock { + BlockDb { block: BlockDocument::V10(block_0.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(current_block.clone()), expire_certs: None, }, @@ -378,15 +378,15 @@ mod tests { .with(eq(vec![BlockNumber(2), BlockNumber(1), BlockNumber(0)])) .returning(move |_| { Ok(vec![ - DbBlock { + BlockDb { block: BlockDocument::V10(current_block.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(block_1.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(block_0.clone()), expire_certs: None, }, @@ -441,15 +441,15 @@ mod tests { .with(eq(vec![BlockNumber(0), BlockNumber(1), BlockNumber(2)])) .returning(move |_| { Ok(vec![ - DbBlock { + BlockDb { block: BlockDocument::V10(block_0.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(block_1.clone()), expire_certs: None, }, - DbBlock { + BlockDb { block: BlockDocument::V10(current_block.clone()), expire_certs: None, }, diff --git a/lib/modules/gva/src/schema/queries/current.rs b/lib/modules/gva/src/schema/queries/current.rs index 6a736f8a6bb2c2f7a7c9f1984e98b6a6e5bf7794..68b2c59bc41cc8bbbb3963d2664ea01a8cdf20da 100644 --- a/lib/modules/gva/src/schema/queries/current.rs +++ b/lib/modules/gva/src/schema/queries/current.rs @@ -38,7 +38,7 @@ mod tests { use dubp_common_doc::{BlockHash, BlockNumber, Blockstamp}; use dup_crypto::hashs::Hash; use dup_crypto_tests_tools::mocks::{hash, pubkey}; - use durs_bc_db_reader::blocks::DbBlock; + use durs_bc_db_reader::blocks::BlockDb; use mockall::predicate::eq; use serde_json::json; @@ -58,7 +58,7 @@ mod tests { ); current_block.issuers = vec![pubkey('B')]; current_block.pow_min = 70; - Ok(Some(DbBlock { + Ok(Some(BlockDb { block: BlockDocument::V10(current_block), expire_certs: None, })) diff --git a/lib/tests-tools/bc-db-tests-tools/src/mocks.rs b/lib/tests-tools/bc-db-tests-tools/src/mocks.rs index b541a2bb014b7948e69f72452d6a3366793eb202..9f49661411755787d2e3d348e7d54afa2c223ea7 100644 --- a/lib/tests-tools/bc-db-tests-tools/src/mocks.rs +++ b/lib/tests-tools/bc-db-tests-tools/src/mocks.rs @@ -17,7 +17,7 @@ use dubp_block_doc::BlockDocument; use durs_bc_db_reader::blocks::fork_tree::ForkTree; -use durs_bc_db_reader::blocks::DbBlock; +use durs_bc_db_reader::blocks::BlockDb; use durs_bc_db_writer::blocks::{insert_new_fork_block, insert_new_head_block}; use durs_bc_db_writer::current_meta_datas::update_current_meta_datas; use durs_bc_db_writer::{Db, DbError}; @@ -37,7 +37,7 @@ pub fn insert_main_block( &db_tmp, &mut w, fork_tree, - DbBlock { + BlockDb { block, expire_certs: None, }, @@ -58,7 +58,7 @@ pub fn insert_fork_block( db_tmp, &mut w, fork_tree, - DbBlock { + BlockDb { block, expire_certs: None, },