Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
6807eba
Add migration for legacy withdrawal data and update model snapshot
Jossec101 Jun 11, 2025
105a44f
Error handling in database migration and clean up whitespace in DbIni…
Jossec101 Jun 11, 2025
6dd9ccd
Remove obsolete properties from WalletWithdrawalRequest model and upd…
Jossec101 Jun 11, 2025
a92446b
Refactor wallet transfer logic to encapsulate destination address and…
Jossec101 Jun 11, 2025
2d51d60
Update withdrawal request destination handling to use WalletWithdrawa…
Jossec101 Jun 11, 2025
abd9a33
Refactor withdrawal request to use WalletWithdrawalRequestDestination…
Jossec101 Jun 11, 2025
73ee8f3
Enhance withdrawal request handling to ensure destination address is …
Jossec101 Jun 11, 2025
176edec
Include WalletWithdrawalRequestDestinations in various retrieval meth…
Jossec101 Jun 11, 2025
7e127bb
Refactor WalletWithdrawalRequest properties and update references to …
Jossec101 Jun 11, 2025
c825620
Undo autofmt
Jossec101 Jun 12, 2025
5457307
Working single output withdrawals with new data model
Jossec101 Jun 12, 2025
1a6c4bc
Fix tests to new withdrawal model
Jossec101 Jun 12, 2025
268bcea
Refactor destination address handling in WalletWithdrawalRequest to i…
Jossec101 Jun 12, 2025
dddf718
Remove redundant error logging in database migration exception handling
Jossec101 Jun 13, 2025
6d360f5
Update src/Services/BitcoinService.cs
Jossec101 Jun 13, 2025
698bf82
Remove rollback logic for migrated destinations in Down migration method
Jossec101 Jun 13, 2025
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
13 changes: 13 additions & 0 deletions NodeGuard.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"folders": [
{
"path": "."
},
{
"path": "src"
}
],
"settings": {
"editor.formatOnSave": false
}
}
2 changes: 1 addition & 1 deletion src/Data/DbInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void Initialize(IServiceProvider serviceProvider)
}
catch (Exception e)
{
logger.LogError(e, "Error while migrating");
throw new Exception("Error while migrating the database", e);
}

Thread.Sleep(1_000);
Expand Down
28 changes: 5 additions & 23 deletions src/Data/Models/WalletWithdrawalRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@
{
public WalletWithdrawalRequestStatus Status { get; set; }

[Obsolete("This is not used anymore, use the WalletWithdrawalRequestDestinations instead")]
/// <summary>
/// base58 address of the output of the request, its mutually exclusive with the WalletWithdrawalRequestDestinations
/// </summary>
public string DestinationAddress { get; set; }

/// <summary>
/// Description by the requestor
/// </summary>
Expand All @@ -91,28 +85,12 @@

public string? RejectCancelDescription { get; set; }

[Obsolete("This is not used anymore, use the WalletWithdrawalRequestDestinations instead")]
/// <summary>
/// TX amount in BTC, its mutually exclusive with the WalletWithdrawalRequestDestinations
/// </summary>
///
public decimal Amount { get; set; }

/// <summary>
/// Checks if all the threshold signatures are collected, including the internal wallet key (even if not signed yet)
/// </summary>
[NotMapped]
public bool AreAllRequiredHumanSignaturesCollected => CheckSignatures();

[NotMapped]
/// <summary>
/// This indicates if the request is a legacy request, meaning that it has no destinations and only a single address and amount
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
public bool IsLegacy => Amount > 0 && string.IsNullOrEmpty(DestinationAddress) &&
(WalletWithdrawalRequestDestinations == null || WalletWithdrawalRequestDestinations?.Count == 0);
#pragma warning restore CS0618 // Type or member is obsolete

[NotMapped]
public int NumberOfSignaturesCollected =>
WalletWithdrawalRequestPSBTs == null
Expand Down Expand Up @@ -193,7 +171,11 @@
}

[NotMapped]
public long SatsAmount => new Money(Amount, MoneyUnit.BTC).Satoshi;
public decimal TotalAmount =>
WalletWithdrawalRequestDestinations?.Sum(x => x.Amount) ?? 0m;

[NotMapped]
public long SatsAmount => new Money(WalletWithdrawalRequestDestinations?.Sum(x => x.Amount) ?? 0m, MoneyUnit.BTC).Satoshi;

#region Relationships

Expand All @@ -205,7 +187,7 @@
public ApplicationUser UserRequestor { get; set; }
public int WalletId { get; set; }

public Wallet Wallet { get; set; }

Check warning on line 190 in src/Data/Models/WalletWithdrawalRequest.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Nullability of reference types in type of parameter 'value' of 'void WalletWithdrawalRequest.Wallet.set' doesn't match implicitly implemented member 'void IBitcoinRequest.Wallet.set' (possibly because of nullability attributes).

public List<WalletWithdrawalRequestPSBT> WalletWithdrawalRequestPSBTs { get; set; }

Expand Down
8 changes: 7 additions & 1 deletion src/Data/Repositories/WalletWithdrawalRequestRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ INBXplorerService nBXplorerService
.ThenInclude(x => x.Keys)
.Include(x => x.UserRequestor)
.Include(x => x.WalletWithdrawalRequestPSBTs)
.Include(x => x.WalletWithdrawalRequestDestinations)
.SingleOrDefaultAsync(x => x.Id == id);

return request;
Expand Down Expand Up @@ -92,6 +93,7 @@ public async Task<List<WalletWithdrawalRequest>> GetAll()
.Include(x => x.Wallet).ThenInclude(x => x.Keys)
.Include(x => x.UserRequestor)
.Include(x => x.WalletWithdrawalRequestPSBTs)
.Include(x => x.WalletWithdrawalRequestDestinations)
.AsSplitQuery()
.ToListAsync();
}
Expand All @@ -104,6 +106,7 @@ public async Task<List<WalletWithdrawalRequest>> GetUnsignedPendingRequestsByUse
.Include(x => x.Wallet).ThenInclude(x => x.Keys)
.Include(x => x.UserRequestor)
.Include(x => x.WalletWithdrawalRequestPSBTs)
.Include(x => x.WalletWithdrawalRequestDestinations)
.Where(request => request.Wallet != null
&& request.Wallet.Keys.Count(key => userId == key.UserId) > request.WalletWithdrawalRequestPSBTs.Count(req => req.SignerId == userId)
&& (request.Status == WalletWithdrawalRequestStatus.Pending || request.Status == WalletWithdrawalRequestStatus.PSBTSignaturesPending))
Expand All @@ -119,6 +122,7 @@ public async Task<List<WalletWithdrawalRequest>> GetAllUnsignedPendingRequests()
.Include(x => x.Wallet).ThenInclude(x => x.Keys)
.Include(x => x.UserRequestor)
.Include(x => x.WalletWithdrawalRequestPSBTs)
.Include(x => x.WalletWithdrawalRequestDestinations)
.Where(request => request.Status == WalletWithdrawalRequestStatus.Pending || request.Status == WalletWithdrawalRequestStatus.PSBTSignaturesPending)
.AsSplitQuery()
.ToListAsync();
Expand Down Expand Up @@ -155,7 +159,7 @@ public async Task<List<WalletWithdrawalRequest>> GetAllUnsignedPendingRequests()
return (false, "Balance could not be retrieved from the wallet.");
}

var requestMoneyAmount = new Money(type.Amount, MoneyUnit.BTC);
var requestMoneyAmount = new Money(type.TotalAmount, MoneyUnit.BTC);

if ((Money)balance.Confirmed < requestMoneyAmount)
{
Expand Down Expand Up @@ -272,6 +276,7 @@ public async Task<List<WalletWithdrawalRequest>> GetPendingRequests()
|| request.Status == WalletWithdrawalRequestStatus.Pending
|| request.Status == WalletWithdrawalRequestStatus.PSBTSignaturesPending)
.Include(request => request.Wallet)
.Include(x => x.WalletWithdrawalRequestDestinations)
.ToListAsync();

return walletWithdrawalRequests;
Expand All @@ -284,6 +289,7 @@ public async Task<List<WalletWithdrawalRequest>> GetOnChainPendingWithdrawals()
var walletWithdrawalRequests = await applicationDbContext.WalletWithdrawalRequests
.Where(request => request.Status == WalletWithdrawalRequestStatus.OnChainConfirmationPending)
.Include(request => request.Wallet)
.Include(x => x.WalletWithdrawalRequestDestinations)
.ToListAsync();

return walletWithdrawalRequests;
Expand Down
Loading
Loading