Skip to content

Commit c9aaf9a

Browse files
committed
Use coins to spend in indexation
1 parent e61b069 commit c9aaf9a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

crates/fuel-core/src/coins_query.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ pub async fn select_coins_to_spend(
251251
total: u128,
252252
max: u16,
253253
asset_id: &AssetId,
254+
allow_partial: bool,
254255
exclude: &Exclude,
255256
batch_size: usize,
256257
) -> Result<Vec<CoinsToSpendIndexKey>, CoinsQueryError> {
@@ -287,11 +288,13 @@ pub async fn select_coins_to_spend(
287288
big_coins(big_coins_stream, adjusted_total, max, exclude).await?;
288289

289290
if selected_big_coins_total < total {
290-
return Err(CoinsQueryError::InsufficientCoinsForTheMax {
291-
asset_id: *asset_id,
292-
collected_amount: selected_big_coins_total,
293-
max,
294-
});
291+
if !allow_partial {
292+
return Err(CoinsQueryError::InsufficientCoinsForTheMax {
293+
asset_id: *asset_id,
294+
collected_amount: selected_big_coins_total,
295+
max,
296+
})
297+
}
295298
}
296299

297300
let Some(last_selected_big_coin) = selected_big_coins.last() else {
@@ -1322,6 +1325,7 @@ mod tests {
13221325
TOTAL,
13231326
MAX,
13241327
&AssetId::default(),
1328+
false,
13251329
&exclude,
13261330
BATCH_SIZE,
13271331
)
@@ -1384,6 +1388,7 @@ mod tests {
13841388
TOTAL,
13851389
MAX,
13861390
&AssetId::default(),
1391+
false,
13871392
&exclude,
13881393
BATCH_SIZE,
13891394
)
@@ -1431,6 +1436,7 @@ mod tests {
14311436
TOTAL,
14321437
MAX,
14331438
&AssetId::default(),
1439+
false,
14341440
&exclude,
14351441
BATCH_SIZE,
14361442
)
@@ -1459,6 +1465,7 @@ mod tests {
14591465
TOTAL,
14601466
MAX,
14611467
&AssetId::default(),
1468+
false,
14621469
&exclude,
14631470
BATCH_SIZE,
14641471
)
@@ -1486,6 +1493,7 @@ mod tests {
14861493
TOTAL,
14871494
MAX,
14881495
&AssetId::default(),
1496+
false,
14891497
&exclude,
14901498
BATCH_SIZE,
14911499
)
@@ -1521,6 +1529,7 @@ mod tests {
15211529
TOTAL,
15221530
MAX,
15231531
&asset_id,
1532+
false,
15241533
&exclude,
15251534
BATCH_SIZE,
15261535
)

crates/fuel-core/src/schema/coins.rs

+1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ async fn coins_to_spend_with_cache(
435435
total_amount,
436436
max,
437437
&asset_id,
438+
asset.allow_partial.unwrap_or(false),
438439
excluded,
439440
db.batch_size,
440441
)

0 commit comments

Comments
 (0)