diff --git a/lib/crypto/src/keys/mod.rs b/lib/crypto/src/keys/mod.rs index 34096c08ad3be06d9995edc648c10dee0b13dbcc..0b90c88f1586750735eaefdd30cbf00516ee7cfa 100644 --- a/lib/crypto/src/keys/mod.rs +++ b/lib/crypto/src/keys/mod.rs @@ -235,7 +235,32 @@ pub enum PubKey { Schnorr(), } +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +/// Error when parsing pubkey bytes +pub enum PubkeyFromBytesError { + /// Invalid bytes length + InvalidBytesLen { + /// Expected length + expected: usize, + /// Found length + found: usize, + }, +} + impl PubKey { + /// Create pubkey from bytes + pub fn from_bytes(bytes: &[u8]) -> Result<Self, PubkeyFromBytesError> { + if bytes.len() != *ed25519::PUBKEY_SIZE_IN_BYTES { + Err(PubkeyFromBytesError::InvalidBytesLen { + expected: *ed25519::PUBKEY_SIZE_IN_BYTES, + found: bytes.len(), + }) + } else { + let mut pubkey_buffer = [0u8; 32]; + pubkey_buffer.copy_from_slice(bytes); + Ok(PubKey::Ed25519(ed25519::PublicKey(pubkey_buffer))) + } + } /// Compute PubKey size in bytes pub fn size_in_bytes(&self) -> usize { match *self { diff --git a/lib/modules-lib/bc-db-reader/src/constants.rs b/lib/modules-lib/bc-db-reader/src/constants.rs index a7aecb4ca7f6ea3f54fd144c1af257ab46421c1f..3849292bf097b6bfc0498d966f18c42fc585edf3 100644 --- a/lib/modules-lib/bc-db-reader/src/constants.rs +++ b/lib/modules-lib/bc-db-reader/src/constants.rs @@ -34,5 +34,8 @@ pub static MAIN_BLOCKS: &str = "bc"; /// Blockstamp orphaned (no parent block) indexed by their previous blockstamp (PreviousBlockstamp, Vec<Blockstamp>) pub static ORPHAN_BLOCKSTAMP: &str = "ob"; -/// Identities (PubKey, DbIdentity) +/// Wot id index (PubKey, WotId) +pub static WOT_ID_INDEX: &str = "wii"; + +/// Identities (WotId, DbIdentity) pub static IDENTITIES: &str = "idty"; diff --git a/lib/modules-lib/bc-db-reader/src/current_meta_datas.rs b/lib/modules-lib/bc-db-reader/src/current_meta_datas.rs index f565a95c399a2704f1f481d1aff7ddda5faa5896..d1d1a76336b59bbf151e1bb1259da0792461501f 100644 --- a/lib/modules-lib/bc-db-reader/src/current_meta_datas.rs +++ b/lib/modules-lib/bc-db-reader/src/current_meta_datas.rs @@ -17,9 +17,11 @@ use crate::blocks::fork_tree::ForkTree; use crate::constants::*; +use crate::*; use crate::{DbReadable, DbValue}; use dubp_common_doc::{Blockstamp, CurrencyName}; use durs_dbs_tools::DbError; +use durs_wot::WotId; #[derive(Clone, Copy, Debug)] /// Current meta data key @@ -34,6 +36,8 @@ pub enum CurrentMetaDataKey { CurrentBlockchainTime, /// Fork tree ForkTree, + /// Greatest wot id + GreatestWotId, } impl CurrentMetaDataKey { @@ -45,6 +49,7 @@ impl CurrentMetaDataKey { Self::CurrentBlockstamp => 2, Self::CurrentBlockchainTime => 3, Self::ForkTree => 4, + Self::GreatestWotId => 5, } } } @@ -137,3 +142,20 @@ pub fn get_fork_tree<DB: DbReadable>(db: &DB) -> Result<ForkTree, DbError> { } }) } + +/// Get greatest wot id +#[inline] +pub fn get_greatest_wot_id_<DB: DbReadable, R: Reader>(db: &DB, r: &R) -> Result<WotId, DbError> { + if let Some(v) = db + .get_int_store(CURRENT_METAS_DATAS) + .get(r, CurrentMetaDataKey::GreatestWotId.to_u32())? + { + if let DbValue::U64(greatest_wot_id) = v { + Ok(WotId(greatest_wot_id as usize)) + } else { + Err(DbError::DBCorrupted) + } + } else { + Ok(WotId(0)) + } +} 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 d47b5aaab67bc2d5c11f8b35c421f1890aa97941..b83841a69213e0214a7e8892a8859b9925e042f0 100644 --- a/lib/modules-lib/bc-db-reader/src/indexes/identities.rs +++ b/lib/modules-lib/bc-db-reader/src/indexes/identities.rs @@ -102,17 +102,17 @@ pub fn get_identities<DB: DbReadable>( current_block_id: BlockNumber, ) -> Result<Vec<DbIdentity>, DbError> { if let Some(pubkey) = filters.by_pubkey { - if let Some(idty) = get_identity(db, &pubkey)? { + if let Some(idty) = get_identity_by_pubkey(db, &pubkey)? { Ok(vec![idty]) } else { Ok(vec![]) } } else { + let mut identities: Vec<DbIdentity> = Vec::new(); db.read(|r| { - let mut identities: Vec<DbIdentity> = Vec::new(); - for entry in db.get_store(IDENTITIES).iter_start(r)? { - if let Some(v) = entry?.1 { - let db_idty = DB::from_db_value::<DbIdentity>(v)?; + let greatest_wot_id = crate::current_meta_datas::get_greatest_wot_id_(db, r)?; + for wot_id in 0..=greatest_wot_id.0 { + if let Some(db_idty) = get_identity_by_wot_id_(db, r, WotId(wot_id))? { if filters .paging .check_created_on(db_idty.idty_doc.blockstamp().id, current_block_id) @@ -121,36 +121,60 @@ pub fn get_identities<DB: DbReadable>( } } } - identities.sort_by(|i1, i2| { - i1.idty_doc - .blockstamp() - .id - .cmp(&i2.idty_doc.blockstamp().id) - }); - Ok(identities - .into_iter() - .skip(filters.paging.page_size * filters.paging.page_number) - .take(filters.paging.page_size) - .collect()) - }) + Ok(()) + })?; + identities.sort_by(|i1, i2| { + i1.idty_doc + .blockstamp() + .id + .cmp(&i2.idty_doc.blockstamp().id) + }); + Ok(identities + .into_iter() + .skip(filters.paging.page_size * filters.paging.page_number) + .take(filters.paging.page_size) + .collect()) } } /// Get identity by pubkey in databases -pub fn get_identity<DB: DbReadable>( +pub fn get_identity_by_pubkey<DB: DbReadable>( db: &DB, pubkey: &PubKey, ) -> Result<Option<DbIdentity>, DbError> { - db.read(|r| get_identity_(db, r, pubkey)) + db.read(|r| get_identity_by_pubkey_(db, r, pubkey)) } /// Get identity by pubkey -pub fn get_identity_<DB: DbReadable, R: Reader>( +pub fn get_identity_by_pubkey_<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())? { + if let Some(wot_id) = get_wot_id_(db, r, pubkey)? { + get_identity_by_wot_id_(db, r, wot_id) + } else { + Ok(None) + } +} + +/// Get identity by pubkey +#[inline] +pub fn get_identity_by_wot_id<DB: DbReadable>( + db: &DB, + wot_id: WotId, +) -> Result<Option<DbIdentity>, DbError> { + db.read(|r| get_identity_by_wot_id_(db, r, wot_id)) +} + +/// Get identity by pubkey +#[inline] +pub fn get_identity_by_wot_id_<DB: DbReadable, R: Reader>( + db: &DB, + r: &R, + wot_id: WotId, +) -> Result<Option<DbIdentity>, DbError> { + if let Some(v) = db.get_int_store(IDENTITIES).get(r, wot_id.0 as u32)? { Ok(Some(DB::from_db_value(v)?)) } else { Ok(None) @@ -160,17 +184,17 @@ pub fn get_identity_<DB: DbReadable, R: Reader>( /// Get uid from pubkey #[inline] pub fn get_uid<DB: DbReadable>(db: &DB, pubkey: &PubKey) -> Result<Option<String>, DbError> { - Ok(get_identity(db, pubkey)?.map(|db_idty| db_idty.idty_doc.username().to_owned())) + Ok(get_identity_by_pubkey(db, pubkey)?.map(|db_idty| db_idty.idty_doc.username().to_owned())) } /// Get pubkey from uid pub fn get_pubkey_from_uid<DB: DbReadable>(db: &DB, uid: &str) -> Result<Option<PubKey>, DbError> { db.read(|r| { - for entry in db.get_store(IDENTITIES).iter_start(r)? { - if let Some(v) = entry?.1 { - let idty_doc = DB::from_db_value::<DbIdentity>(v)?.idty_doc; - if idty_doc.username() == uid { - return Ok(Some(idty_doc.issuers()[0])); + let greatest_wot_id = crate::current_meta_datas::get_greatest_wot_id_(db, r)?; + for wot_id in 0..=greatest_wot_id.0 { + if let Some(db_idty) = get_identity_by_wot_id_(db, r, WotId(wot_id))? { + if db_idty.idty_doc.username() == uid { + return Ok(Some(db_idty.idty_doc.issuers()[0])); } } } @@ -178,14 +202,42 @@ pub fn get_pubkey_from_uid<DB: DbReadable>(db: &DB, uid: &str) -> Result<Option< }) } +/// Get identity wot_id +pub fn get_wot_id<DB: DbReadable>(db: &DB, pubkey: &PubKey) -> Result<Option<WotId>, DbError> { + db.read(|r| get_wot_id_(db, r, pubkey)) +} + +/// Get identity wot_id +#[inline] +pub fn get_wot_id_<DB: DbReadable, R: Reader>( + db: &DB, + r: &R, + pubkey: &PubKey, +) -> Result<Option<WotId>, DbError> { + if let Some(v) = db + .get_store(WOT_ID_INDEX) + .get(r, &pubkey.to_bytes_vector())? + { + if let DbValue::U64(wot_id) = v { + Ok(Some(WotId(wot_id as usize))) + } else { + Err(DbError::DBCorrupted) + } + } else { + Ok(None) + } +} /// Get wot_id index pub fn get_wot_index<DB: DbReadable>(db: &DB) -> Result<HashMap<PubKey, WotId>, DbError> { db.read(|r| { let mut wot_index = HashMap::new(); - for entry in db.get_store(IDENTITIES).iter_start(r)? { - if let Some(v) = entry?.1 { - let db_idty = DB::from_db_value::<DbIdentity>(v)?; - wot_index.insert(db_idty.idty_doc.issuers()[0], db_idty.wot_id); + for entry in db.get_store(WOT_ID_INDEX).iter_start(r)? { + let (k, v_opt) = entry?; + if let Some(DbValue::U64(wot_id)) = v_opt { + wot_index.insert( + PubKey::from_bytes(k).map_err(|_| DbError::DBCorrupted)?, + WotId(wot_id as usize), + ); } } Ok(wot_index) @@ -196,10 +248,10 @@ pub fn get_wot_index<DB: DbReadable>(db: &DB) -> Result<HashMap<PubKey, WotId>, pub fn get_wot_uid_index<DB: DbReadable>(db: &DB) -> Result<HashMap<WotId, String>, DbError> { db.read(|r| { let mut wot_uid_index = HashMap::new(); - for entry in db.get_store(IDENTITIES).iter_start(r)? { - if let Some(v) = entry?.1 { - let db_idty = DB::from_db_value::<DbIdentity>(v)?; - wot_uid_index.insert(db_idty.wot_id, db_idty.idty_doc.username().to_owned()); + let greatest_wot_id = crate::current_meta_datas::get_greatest_wot_id_(db, r)?; + for wot_id in 0..=greatest_wot_id.0 { + if let Some(db_idty) = get_identity_by_wot_id_(db, r, WotId(wot_id))? { + wot_uid_index.insert(WotId(wot_id), db_idty.idty_doc.username().to_owned()); } } Ok(wot_uid_index) @@ -210,6 +262,7 @@ pub fn get_wot_uid_index<DB: DbReadable>(db: &DB) -> Result<HashMap<WotId, Strin mod test { use super::*; + use crate::current_meta_datas::CurrentMetaDataKey; use crate::paging::PagingFilter; use dubp_common_doc::Blockstamp; use dup_crypto_tests_tools::mocks::pubkey; @@ -247,18 +300,35 @@ mod test { // Write mock identities in DB let db = crate::tests::open_tmp_db()?; + let mut wot_id = 0; for idty in &mock_identities { let idty_bin = durs_dbs_tools::to_bytes(idty)?; db.write(|mut w| { - db.get_store(IDENTITIES).put( + db.get_store(WOT_ID_INDEX).put( w.as_mut(), &idty.idty_doc.issuers()[0].to_bytes_vector(), + &DbValue::U64(wot_id), + )?; + db.get_int_store(IDENTITIES).put( + w.as_mut(), + wot_id as u32, &KvFileDbHandler::db_value(&idty_bin)?, )?; Ok(w) })?; + wot_id += 1; } + // Write greatest wot id + db.write(|mut w| { + db.get_int_store(CURRENT_METAS_DATAS).put( + w.as_mut(), + CurrentMetaDataKey::GreatestWotId.to_u32(), + &DbValue::U64(wot_id), + )?; + Ok(w) + })?; + // Test default filters let mut filters = IdentitiesFilter::default(); assert!(slice_same_elems( diff --git a/lib/modules-lib/bc-db-reader/src/lib.rs b/lib/modules-lib/bc-db-reader/src/lib.rs index 398a2b0b5f335c7a7f6a5b8359002f30c4df59d6..a4b58e28bdaaad291df8cac8d41bd904c59f822a 100644 --- a/lib/modules-lib/bc-db-reader/src/lib.rs +++ b/lib/modules-lib/bc-db-reader/src/lib.rs @@ -54,7 +54,8 @@ pub fn bc_db_schema() -> KvFileDbSchema { MAIN_BLOCKS.to_owned() => KvFileDbStoreType::SingleIntKey, FORK_BLOCKS.to_owned() => KvFileDbStoreType::Single, ORPHAN_BLOCKSTAMP.to_owned() => KvFileDbStoreType::Single, - IDENTITIES.to_owned() => KvFileDbStoreType::Single, + IDENTITIES.to_owned() => KvFileDbStoreType::SingleIntKey, + WOT_ID_INDEX.to_owned() => KvFileDbStoreType::Single, ], } } 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 c56487583e6a57ae41d45792ca57b4cde65fe754..487c9be013b2efee673808199fb351558ecea207 100644 --- a/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs +++ b/lib/modules/blockchain/bc-db-writer/src/indexes/certs.rs @@ -19,7 +19,6 @@ use crate::{BinFreeStructDb, Db, DbError}; use dubp_common_doc::BlockNumber; 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::indexes::identities::DbIdentity; use durs_bc_db_reader::{CertsExpirV10Datas, DbReadable, DbValue}; @@ -30,7 +29,6 @@ pub fn write_certification( currency_params: &CurrencyParameters, db: &Db, certs_db: &BinFreeStructDb<CertsExpirV10Datas>, - source_pubkey: PubKey, source: WotId, target: WotId, created_block_id: BlockNumber, @@ -38,7 +36,7 @@ pub fn write_certification( ) -> Result<(), DbError> { // Get cert_chainable_on let mut member_datas = - durs_bc_db_reader::indexes::identities::get_identity(db, &source_pubkey)? + durs_bc_db_reader::indexes::identities::get_identity_by_wot_id(db, source)? .expect("Try to write certification with unexist certifier."); // Push new cert_chainable_on member_datas @@ -47,9 +45,9 @@ pub fn write_certification( // Write new identity datas let bin_member_datas = durs_dbs_tools::to_bytes(&member_datas)?; db.write(|mut w| { - db.get_store(IDENTITIES).put( + db.get_int_store(IDENTITIES).put( w.as_mut(), - &source_pubkey.to_bytes_vector(), + source.0 as u32, &DbValue::Blob(&bin_member_datas), )?; Ok(w) @@ -82,13 +80,16 @@ pub fn revert_write_cert( })?; // Pop last cert_chainable_on db.write(|mut w| { - let identities_store = db.get_store(IDENTITIES); - let pubkey_bytes = compact_doc.issuer.to_bytes_vector(); - if let Some(v) = identities_store.get(w.as_ref(), &pubkey_bytes)? { + 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 = Db::from_db_value::<DbIdentity>(v)?; member_datas.cert_chainable_on.pop(); let bin_member_datas = durs_dbs_tools::to_bytes(&member_datas)?; - identities_store.put(w.as_mut(), &pubkey_bytes, &DbValue::Blob(&bin_member_datas))? + identities_store.put( + w.as_mut(), + source.0 as u32, + &DbValue::Blob(&bin_member_datas), + )? } Ok(w) })?; 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 eaa5ff5ecd132d84294a66d387f730c4e2f53cf8..8f0ecd81176843bf1191bef96dcce0b5185a9ce2 100644 --- a/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs +++ b/lib/modules/blockchain/bc-db-writer/src/indexes/identities.rs @@ -23,6 +23,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::indexes::identities::get_wot_id_; use durs_bc_db_reader::indexes::identities::{DbIdentity, DbIdentityState}; use durs_bc_db_reader::{DbReadable, DbValue}; use durs_common_tools::fatal_error; @@ -34,7 +35,7 @@ pub fn revert_create_identity( ms_db: &BinFreeStructDb<MsExpirV10Datas>, pubkey: &PubKey, ) -> Result<(), DbError> { - let dal_idty = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? + let dal_idty = durs_bc_db_reader::indexes::identities::get_identity_by_pubkey(db, pubkey)? .expect("Try to revert unexist idty."); // Remove membership ms_db.write(|db| { @@ -47,10 +48,15 @@ pub fn revert_create_identity( })?; // Remove identity db.write(|mut w| { - db.get_store(IDENTITIES).delete( - w.as_mut(), - &dal_idty.idty_doc.issuers()[0].to_bytes_vector(), - )?; + let pubkey_bytes = dal_idty.idty_doc.issuers()[0].to_bytes_vector(); + if let Some(DbValue::U64(wot_id)) = + db.get_store(WOT_ID_INDEX).get(w.as_ref(), &pubkey_bytes)? + { + db.get_int_store(IDENTITIES) + .delete(w.as_mut(), wot_id as u32)?; + db.get_store(WOT_ID_INDEX) + .delete(w.as_mut(), &pubkey_bytes)?; + } Ok(w) })?; Ok(()) @@ -84,11 +90,13 @@ pub fn create_identity( // Write Identity let bin_idty = durs_dbs_tools::to_bytes(&idty)?; db.write(|mut w| { - db.get_store(IDENTITIES).put( + db.get_store(WOT_ID_INDEX).put( w.as_mut(), &idty.idty_doc.issuers()[0].to_bytes_vector(), - &DbValue::Blob(&bin_idty), + &DbValue::U64(wot_id.0 as u64), )?; + db.get_int_store(IDENTITIES) + .put(w.as_mut(), wot_id.0 as u32, &DbValue::Blob(&bin_idty))?; Ok(w) })?; // Write membership @@ -107,8 +115,9 @@ pub fn exclude_identity( exclusion_blockstamp: &Blockstamp, revert: bool, ) -> Result<(), DbError> { - let mut idty_datas = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? - .expect("Try to exclude unexist idty."); + let mut idty_datas = + durs_bc_db_reader::indexes::identities::get_identity_by_pubkey(db, pubkey)? + .expect("Try to exclude unexist idty."); idty_datas.state = if revert { match idty_datas.state { DbIdentityState::ExpireMember(renewed_counts) => { @@ -132,12 +141,16 @@ pub fn exclude_identity( // Write new identity datas let bin_idty = durs_dbs_tools::to_bytes(&idty_datas)?; db.write(|mut w| { - db.get_store(IDENTITIES).put( - w.as_mut(), - &pubkey.to_bytes_vector(), - &DbValue::Blob(&bin_idty), - )?; - Ok(w) + if let Some(wot_id) = get_wot_id_(db, w.as_ref(), &pubkey)? { + db.get_int_store(IDENTITIES).put( + w.as_mut(), + wot_id.0 as u32, + &DbValue::Blob(&bin_idty), + )?; + Ok(w) + } else { + Err(DbError::DBCorrupted) + } })?; Ok(()) } @@ -150,8 +163,9 @@ pub fn revoke_identity( explicit: bool, revert: bool, ) -> Result<(), DbError> { - let mut member_datas = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? - .expect("Try to revoke unexist idty."); + let mut member_datas = + durs_bc_db_reader::indexes::identities::get_identity_by_pubkey(db, pubkey)? + .expect("Try to revoke unexist idty."); member_datas.state = if revert { match member_datas.state { @@ -188,12 +202,16 @@ pub fn revoke_identity( // Update idty let bin_idty = durs_dbs_tools::to_bytes(&member_datas)?; db.write(|mut w| { - db.get_store(IDENTITIES).put( - w.as_mut(), - &pubkey.to_bytes_vector(), - &DbValue::Blob(&bin_idty), - )?; - Ok(w) + if let Some(wot_id) = get_wot_id_(db, w.as_ref(), &pubkey)? { + db.get_int_store(IDENTITIES).put( + w.as_mut(), + wot_id.0 as u32, + &DbValue::Blob(&bin_idty), + )?; + Ok(w) + } else { + Err(DbError::DBCorrupted) + } })?; Ok(()) } @@ -203,15 +221,15 @@ pub fn renewal_identity( currency_params: &CurrencyParameters, db: &Db, ms_db: &BinFreeStructDb<MsExpirV10Datas>, - pubkey: &PubKey, idty_wot_id: WotId, renewal_timestamp: u64, ms_created_block_id: BlockNumber, revert: bool, ) -> Result<(), DbError> { // Get idty_datas - let mut idty_datas = durs_bc_db_reader::indexes::identities::get_identity(db, pubkey)? - .expect("Fatal error : try to renewal unknow identity !"); + let mut idty_datas = + durs_bc_db_reader::indexes::identities::get_identity_by_wot_id(db, idty_wot_id)? + .expect("Fatal error : try to renewal unknow identity !"); // Calculate new state value idty_datas.state = if revert { match idty_datas.state { @@ -252,9 +270,9 @@ pub fn renewal_identity( // Write new identity datas let bin_idty = durs_dbs_tools::to_bytes(&idty_datas)?; db.write(|mut w| { - db.get_store(IDENTITIES).put( + db.get_int_store(IDENTITIES).put( w.as_mut(), - &pubkey.to_bytes_vector(), + idty_wot_id.0 as u32, &DbValue::Blob(&bin_idty), )?; Ok(w) @@ -271,8 +289,12 @@ pub fn renewal_identity( /// Remove identity from databases pub fn remove_identity(db: &Db, pubkey: PubKey) -> Result<(), DbError> { db.write(|mut w| { - db.get_store(IDENTITIES) - .delete(w.as_mut(), &pubkey.to_bytes_vector())?; - Ok(w) + if let Some(wot_id) = get_wot_id_(db, w.as_ref(), &pubkey)? { + db.get_int_store(IDENTITIES) + .delete(w.as_mut(), wot_id.0 as u32)?; + Ok(w) + } else { + Err(DbError::DBCorrupted) + } }) } 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 1ee889571fe634ba1d2a8eed102d516b735cd911..2f7fa57020feab3740a7a83fbef75531052facbc 100644 --- a/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs +++ b/lib/modules/blockchain/bc-db-writer/src/writers/requests.rs @@ -153,7 +153,7 @@ impl WotsDBsWriteQuery { crate::indexes::identities::revert_create_identity(&db, &databases.ms_db, pubkey)?; } WotsDBsWriteQuery::RenewalIdentity( - ref pubkey, + _, ref idty_wot_id, ref current_bc_time, ms_created_block_id, @@ -163,7 +163,6 @@ impl WotsDBsWriteQuery { currency_params, &db, &databases.ms_db, - pubkey, *idty_wot_id, *current_bc_time, ms_created_block_id, @@ -172,7 +171,7 @@ impl WotsDBsWriteQuery { trace!("DBWrWotsDBsWriteQueryiteRequest::RenewalIdentity..."); } WotsDBsWriteQuery::RevertRenewalIdentity( - ref pubkey, + _, ref idty_wot_id, ref current_bc_time, ms_created_block_id, @@ -181,7 +180,6 @@ impl WotsDBsWriteQuery { currency_params, &db, &databases.ms_db, - pubkey, *idty_wot_id, *current_bc_time, ms_created_block_id, @@ -205,7 +203,7 @@ impl WotsDBsWriteQuery { )?; } WotsDBsWriteQuery::CreateCert( - ref source_pubkey, + _, ref source, ref target, ref created_block_id, @@ -216,7 +214,6 @@ impl WotsDBsWriteQuery { currency_params, &db, &databases.certs_db, - *source_pubkey, *source, *target, *created_block_id, diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index 12c1ed525c5017b05bf6cc98cdb98a01e48eb821..a25e09c35c1540e3b0bfbfa4a3f6b676863a0de7 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -138,7 +138,9 @@ 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::indexes::identities::get_identity(&db, &pub_key) + durs_bc_db_reader::indexes::identities::get_identity_by_pubkey( + &db, &pub_key, + ) { println!( "{},{},{}", @@ -153,7 +155,9 @@ 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::indexes::identities::get_identity(&db, &pub_key) + durs_bc_db_reader::indexes::identities::get_identity_by_pubkey( + &db, &pub_key, + ) { table.add_row(row![v, identity.idty_doc.username(), pub_key.to_string()]); }