Skip to content

Commit c8a2a28

Browse files
bug: Update wallet slice state in CertificateRepository (#369)
This commit updates the `CertificateRepository` by changing the logic for setting the state of wallet slices. Instead of using the `SetWalletSliceState` method, it now directly executes an SQL query to update the `state` column in the `wallet_slices` table. The new query sets the state to `WalletSliceState.Reserved` only if the current state is `WalletSliceState.Available`. If the number of rows changed by the query is not equal to 1, an `InvalidOperationException` is thrown with a corresponding error message. This change improves the accuracy and efficiency of setting the wallet slice state in the repository.
1 parent 1b3633e commit c8a2a28

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/ProjectOrigin.WalletSystem.Server/Repositories/CertificateRepository.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,20 @@ public async Task<IList<WalletSlice>> ReserveQuantity(string owner, string regis
437437

438438
foreach (var slice in takenSlices)
439439
{
440-
await SetWalletSliceState(slice.Id, WalletSliceState.Reserved);
440+
var rowsChanged = await _connection.ExecuteAsync(
441+
@"UPDATE wallet_slices
442+
SET state = @state
443+
WHERE id = @sliceId
444+
AND state = @expected",
445+
new
446+
{
447+
sliceid = slice.Id,
448+
state = WalletSliceState.Reserved,
449+
expected = WalletSliceState.Available
450+
});
451+
452+
if (rowsChanged != 1)
453+
throw new InvalidOperationException($"Slice with id {slice.Id} could not be found or was no longer available");
441454
}
442455

443456
return takenSlices;

0 commit comments

Comments
 (0)