Skip to content

Commit 24fab15

Browse files
fix(onchain): replace Vec::sort with manual bubble sort
soroban_sdk::Vec does not provide a sort() method. Replace with a manual bubble sort which is acceptable for the small expected distributor list size.
1 parent 5115a76 commit 24fab15

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

  • app/onchain/contracts/aid_escrow/src

app/onchain/contracts/aid_escrow/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,22 @@ impl AidEscrow {
420420
.get(&KEY_DISTRIBUTORS)
421421
.unwrap_or(Map::new(&env));
422422
let mut keys = distributors.keys();
423-
keys.sort();
423+
// Manual sort — soroban_sdk::Vec does not provide a sort() method.
424+
// Bubble sort is acceptable because distributor lists are expected to
425+
// be small (typically < 50 entries).
426+
let len = keys.len();
427+
if len > 1 {
428+
for i in 0..(len - 1) {
429+
for j in 0..(len - i - 1) {
430+
let a = keys.get(j).unwrap();
431+
let b = keys.get(j + 1).unwrap();
432+
if a > b {
433+
keys.set(j, b);
434+
keys.set(j + 1, a);
435+
}
436+
}
437+
}
438+
}
424439
keys
425440
}
426441

0 commit comments

Comments
 (0)