Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Data/Repositories/WalletWithdrawalRequestRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ public async Task<List<WalletWithdrawalRequest>> GetByReferenceIds(List<string>
{
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();

return await applicationDbContext.WalletWithdrawalRequests.Where(wr => !string.IsNullOrEmpty(wr.ReferenceId) && referenceIds.Contains(wr.ReferenceId)).ToListAsync();
// RBF replacements inherit the reference id of the request they replace, so a reference id can match a whole
// chain of requests. Only the latest one of each chain reflects the current status of the withdrawal.
var requests = await applicationDbContext.WalletWithdrawalRequests
.Where(wr => !string.IsNullOrEmpty(wr.ReferenceId) && referenceIds.Contains(wr.ReferenceId))
.ToListAsync();

return requests
.GroupBy(wr => wr.ReferenceId!)
.Select(g => g.OrderByDescending(wr => wr.Id).First())
.ToList();
}

public async Task<WalletWithdrawalRequest?> GetByTxHash(string txHash)
Expand Down
2 changes: 2 additions & 0 deletions src/Services/WithdrawalRequestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ private async Task<WalletWithdrawalRequest> CreateReplacementAsync(int originalR
CustomFeeRate = newFeeRate,
UserRequestorId = original.UserRequestorId,
RequestMetadata = original.RequestMetadata,
// The replacement represents the same external request, so callers can keep tracking it by reference id.
ReferenceId = original.ReferenceId,
BumpingWalletWithdrawalRequestId = original.Id,
IsRbfCancellation = cancellation,
WalletId = original.WalletId,
Expand Down
Loading