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

[style] bc-db-reader: use transpose()

parent 3f5bb49a
No related branches found
No related tags found
No related merge requests found
...@@ -117,15 +117,11 @@ pub fn get_fork_block<DB: BcDbInReadTx>( ...@@ -117,15 +117,11 @@ pub fn get_fork_block<DB: BcDbInReadTx>(
blockstamp: Blockstamp, blockstamp: Blockstamp,
) -> Result<Option<BlockDb>, DbError> { ) -> Result<Option<BlockDb>, DbError> {
let blockstamp_bytes: Vec<u8> = blockstamp.into(); let blockstamp_bytes: Vec<u8> = blockstamp.into();
if let Some(v) = db db.db()
.db()
.get_store(FORK_BLOCKS) .get_store(FORK_BLOCKS)
.get(db.r(), &blockstamp_bytes)? .get(db.r(), &blockstamp_bytes)?
{ .map(from_db_value)
Ok(Some(from_db_value(v)?)) .transpose()
} else {
Ok(None)
}
} }
/// Get block hash /// Get block hash
......
...@@ -153,15 +153,11 @@ pub fn get_identity_by_wot_id<DB: BcDbInReadTx>( ...@@ -153,15 +153,11 @@ pub fn get_identity_by_wot_id<DB: BcDbInReadTx>(
db: &DB, db: &DB,
wot_id: WotId, wot_id: WotId,
) -> Result<Option<IdentityDb>, DbError> { ) -> Result<Option<IdentityDb>, DbError> {
if let Some(v) = db db.db()
.db()
.get_int_store(IDENTITIES) .get_int_store(IDENTITIES)
.get(db.r(), wot_id.0 as u32)? .get(db.r(), wot_id.0 as u32)?
{ .map(from_db_value)
Ok(Some(from_db_value(v)?)) .transpose()
} else {
Ok(None)
}
} }
/// Get identity state from pubkey /// Get identity state from pubkey
...@@ -194,19 +190,17 @@ pub fn get_wot_id_from_uid<DB: BcDbInReadTx>(db: &DB, uid: &str) -> Result<Optio ...@@ -194,19 +190,17 @@ pub fn get_wot_id_from_uid<DB: BcDbInReadTx>(db: &DB, uid: &str) -> Result<Optio
/// Get identity wot_id /// Get identity wot_id
#[inline] #[inline]
pub fn get_wot_id<DB: BcDbInReadTx>(db: &DB, pubkey: &PubKey) -> Result<Option<WotId>, DbError> { pub fn get_wot_id<DB: BcDbInReadTx>(db: &DB, pubkey: &PubKey) -> Result<Option<WotId>, DbError> {
if let Some(v) = db db.db()
.db()
.get_store(WOT_ID_INDEX) .get_store(WOT_ID_INDEX)
.get(db.r(), &pubkey.to_bytes_vector())? .get(db.r(), &pubkey.to_bytes_vector())?
{ .map(|v| {
if let DbValue::U64(wot_id) = v { if let DbValue::U64(wot_id) = v {
Ok(Some(WotId(wot_id as usize))) Ok(WotId(wot_id as usize))
} else { } else {
Err(DbError::DBCorrupted) Err(DbError::DBCorrupted)
} }
} else { })
Ok(None) .transpose()
}
} }
/// Get wot_id index /// Get wot_id index
pub fn get_wot_index<DB: BcDbInReadTx>(db: &DB) -> Result<HashMap<PubKey, WotId>, DbError> { pub fn get_wot_index<DB: BcDbInReadTx>(db: &DB) -> Result<HashMap<PubKey, WotId>, DbError> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment