Skip to content

Commit

Permalink
Swap functions to reduce diff size
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-ch committed Dec 13, 2024
1 parent 0602da1 commit 9d52683
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions crates/fuel-core/src/schema/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,61 @@ impl CoinQuery {
}
}

async fn coins_to_spend_without_cache(
owner: fuel_tx::Address,
query_per_asset: Vec<SpendQueryElementInput>,
excluded_ids: Option<ExcludeInput>,
max_input: u16,
base_asset_id: &fuel_tx::AssetId,
db: &ReadView,
) -> async_graphql::Result<Vec<Vec<CoinType>>> {
let query_per_asset = query_per_asset
.into_iter()
.map(|e| {
AssetSpendTarget::new(
e.asset_id.0,
e.amount.0,
e.max
.and_then(|max| u16::try_from(max.0).ok())
.unwrap_or(max_input)
.min(max_input),
)
})
.collect_vec();
let excluded_ids: Option<Vec<_>> = excluded_ids.map(|exclude| {
let utxos = exclude
.utxos
.into_iter()
.map(|utxo| coins::CoinId::Utxo(utxo.into()));
let messages = exclude
.messages
.into_iter()
.map(|message| coins::CoinId::Message(message.into()));
utxos.chain(messages).collect()
});

let spend_query =
SpendQuery::new(owner, &query_per_asset, excluded_ids, *base_asset_id)?;

let all_coins = random_improve(db, &spend_query)
.await?
.into_iter()
.map(|coins| {
coins
.into_iter()
.map(|coin| match coin {
coins::CoinType::Coin(coin) => CoinType::Coin(coin.into()),
coins::CoinType::MessageCoin(coin) => {
CoinType::MessageCoin(coin.into())
}
})
.collect_vec()
})
.collect();

Ok(all_coins)
}

async fn coins_to_spend_with_cache(
owner: fuel_tx::Address,
query_per_asset: Vec<SpendQueryElementInput>,
Expand Down Expand Up @@ -364,7 +419,7 @@ async fn coins_to_spend_with_cache(
let Some(selected_coins) = selected_coins else {
return Err(CoinsQueryError::InsufficientCoinsForTheMax {
asset_id,
collected_amount: total_amount,
collected_amount: 0,
max,
}
.into())
Expand Down Expand Up @@ -394,61 +449,6 @@ async fn coins_to_spend_with_cache(
Ok(all_coins)
}

async fn coins_to_spend_without_cache(
owner: fuel_tx::Address,
query_per_asset: Vec<SpendQueryElementInput>,
excluded_ids: Option<ExcludeInput>,
max_input: u16,
base_asset_id: &fuel_tx::AssetId,
db: &ReadView,
) -> async_graphql::Result<Vec<Vec<CoinType>>> {
let query_per_asset = query_per_asset
.into_iter()
.map(|e| {
AssetSpendTarget::new(
e.asset_id.0,
e.amount.0,
e.max
.and_then(|max| u16::try_from(max.0).ok())
.unwrap_or(max_input)
.min(max_input),
)
})
.collect_vec();
let excluded_ids: Option<Vec<_>> = excluded_ids.map(|exclude| {
let utxos = exclude
.utxos
.into_iter()
.map(|utxo| coins::CoinId::Utxo(utxo.into()));
let messages = exclude
.messages
.into_iter()
.map(|message| coins::CoinId::Message(message.into()));
utxos.chain(messages).collect()
});

let spend_query =
SpendQuery::new(owner, &query_per_asset, excluded_ids, *base_asset_id)?;

let all_coins = random_improve(db, &spend_query)
.await?
.into_iter()
.map(|coins| {
coins
.into_iter()
.map(|coin| match coin {
coins::CoinType::Coin(coin) => CoinType::Coin(coin.into()),
coins::CoinType::MessageCoin(coin) => {
CoinType::MessageCoin(coin.into())
}
})
.collect_vec()
})
.collect();

Ok(all_coins)
}

async fn into_coin_id(
mut selected_stream: impl Stream<Item = CoinsToSpendIndexEntry> + Unpin,
max_coins: usize,
Expand Down

0 comments on commit 9d52683

Please sign in to comment.