Skip to content

Commit

Permalink
chore: Clean up comments and add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
netrome committed Oct 29, 2024
1 parent 833ade0 commit 97f786f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 55 deletions.
15 changes: 1 addition & 14 deletions crates/fuel-core/src/database/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ impl OnChainIterableKeyValueView {
/// Retrieve the full block and all associated transactions
pub fn get_full_block(&self, height: &BlockHeight) -> StorageResult<Option<Block>> {
let db_block = self.storage::<FuelBlocks>().get(height)?;

if let Some(block) = db_block {
// fetch all the transactions
// TODO: Use multiget when it's implemented.
// https://github.com/FuelLabs/fuel-core/issues/2344
let transaction_ids = block.transactions().iter().into_boxed();
let txs = <Self as StorageBatchInspect<Transactions>>::get_batch(
self,
Expand All @@ -78,17 +76,6 @@ impl OnChainIterableKeyValueView {
.map(|res| res.and_then(|opt| opt.ok_or(not_found!(Transactions))))
.try_collect()?;

// let transaction_ids = Box::new(block.transactions().iter());
// let txs = self
// .storage::<Transactions>()
// .get_multi(transaction_ids)
// .map(|tx| {
// tx.and_then(|tx| {
// tx.ok_or(not_found!(Transactions)).map(Cow::into_owned)
// })
// })
// .try_collect()?;
//
Ok(Some(block.into_owned().uncompress(txs)))
} else {
Ok(None)
Expand Down
8 changes: 1 addition & 7 deletions crates/fuel-core/src/graphql_api/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ impl ReadView {
&self,
tx_ids: Vec<TxId>,
) -> Vec<StorageResult<Transaction>> {
// TODO: Use multiget when it's implemented.
// https://github.com/FuelLabs/fuel-core/issues/2344
let on_chain_results: BTreeMap<_, _> = tx_ids
.iter()
.enumerate()
Expand All @@ -178,11 +176,7 @@ impl ReadView {
let mut results = on_chain_results;
results.extend(off_chain_results);

// let result = tx_ids
// .iter()
// .map(|tx_id| self.transaction(tx_id))
// .collect::<Vec<_>>();
// Give a chance to other tasks to run.
// Give a chance for other tasks to run.
tokio::task::yield_now().await;

results.into_values().collect()
Expand Down
18 changes: 2 additions & 16 deletions crates/fuel-core/src/query/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ use fuel_core_storage::{
IntoBoxedIter,
IterDirection,
},
// not_found,
// tables::Coins,
Error as StorageError,
Result as StorageResult,
// StorageAsRef,
};
use fuel_core_types::{
entities::coins::coin::Coin,
Expand All @@ -24,26 +21,15 @@ use futures::{
impl ReadView {
pub fn coin(&self, utxo_id: UtxoId) -> StorageResult<Coin> {
self.on_chain.coin(utxo_id)
// let coin = self
// .on_chain
// .as_ref()
// .storage::<Coins>()
// .get(&utxo_id)?
// .ok_or(not_found!(Coins))?
// .into_owned();

// Ok(coin.uncompress(utxo_id))
}

pub async fn coins(
&self,
utxo_ids: Vec<UtxoId>,
) -> impl Iterator<Item = StorageResult<Coin>> + '_ {
let coins: Vec<_> = self.on_chain.coins(utxo_ids.iter().into_boxed()).collect();
// TODO: Use multiget when it's implemented.
// https://github.com/FuelLabs/fuel-core/issues/2344
// let coins = utxo_ids.into_iter().map(|id| self.coin(id));
// Give a chance to other tasks to run.

// Give a chance for other tasks to run.
tokio::task::yield_now().await;
coins.into_iter()
}
Expand Down
17 changes: 2 additions & 15 deletions crates/fuel-core/src/query/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,14 @@ impl ReadView {
&self,
ids: Vec<Nonce>,
) -> impl Stream<Item = StorageResult<Message>> {
// let ids = Box::new(ids.iter());
// let messages: Vec<_> = self
// .on_chain
// .as_ref()
// .storage::<Messages>()
// .get_multi(Box::new(ids))
// .map(|res| {
// res.and_then(|opt| opt.ok_or(not_found!(Messages)).map(Cow::into_owned))
// })
// .collect();

let messages: Vec<_> = self
.on_chain
.message_batch(ids.iter().into_boxed())
.collect();

//// TODO: Use multiget when it's implemented.
//// https://github.com/FuelLabs/fuel-core/issues/2344
// let messages = ids.into_iter().map(|id| self.message(&id));
//// Give a chance to other tasks to run.
// Give a chance for other tasks to run.
tokio::task::yield_now().await;

futures::stream::iter(messages)
}

Expand Down
7 changes: 4 additions & 3 deletions crates/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ pub trait StorageBatchMutate<Type: Mappable>: StorageMutate<Type> {
Type::Key: 'a;
}

// TODO: Document
/// TODO
/// Allows getting batches of values from the storage,
/// which can be faster in certain implementatoins than

Check warning on line 181 in crates/storage/src/lib.rs

View workflow job for this annotation

GitHub Actions / find-typos

"implementatoins" should be "implementations".
/// getting values one by one.
pub trait StorageBatchInspect<Type: Mappable> {
/// TODO
/// Get a batch of values associated with the provided keys.
fn get_batch<'a>(
&'a self,
keys: BoxedIter<'a, &'a Type::Key>,
Expand Down

0 comments on commit 97f786f

Please sign in to comment.