Skip to content

Commit

Permalink
Unnecesary psbt addition fix (#167)
Browse files Browse the repository at this point in the history
* refactor(ChannelRequests.razor): remove redundant code and simplify signature collection process
style(ChannelRequests.razor): replace IScheduler with var for consistency and readability

* fix(ChannelOperationRequest.cs): check if Wallet is not null before accessing IsHotWallet to prevent null reference exception
feat(ChannelRequests.razor): add validation for required human signatures before creating a job
fix(LightningService.cs): update signedPsbts condition to include hot wallet check for better filtering

* feat(LightningServiceTests.cs): add Wallet property to ChannelOperationRequest in test to support SingleSig wallets

---------

Co-authored-by: Marcos <[email protected]>
  • Loading branch information
Jossec101 and markettes authored May 11, 2023
1 parent 2b6bd51 commit 035ca2c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/Data/Models/ChannelOperationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ private bool CheckSignatures()
var userPSBTsCount = NumberOfSignaturesCollected;

//We add the internal Wallet signature
if(!Wallet.IsHotWallet) userPSBTsCount++;
if (Wallet != null && Wallet.IsHotWallet) return ChannelOperationRequestPsbts.Count(x=> x.IsTemplatePSBT) == 1;
userPSBTsCount++;

if (userPSBTsCount == Wallet.MofN)
{
Expand Down
34 changes: 9 additions & 25 deletions src/Pages/ChannelRequests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -744,38 +744,22 @@
return;
}

var channelOperationRequestPSBT = new ChannelOperationRequestPSBT()
{
ChannelOperationRequestId = _selectedRequest.Id,
PSBT = templatePsbt.ToBase64(),
UserSignerId = null,
};
var addResult = await ChannelOperationRequestPsbtRepository.AddAsync(channelOperationRequestPSBT);
if (addResult.Item1)
{
ToastService.ShowSuccess("Signature collected");

_selectedRequest = await ChannelOperationRequestRepository.GetById(_selectedRequest.Id);
_selectedRequest = await ChannelOperationRequestRepository.GetById(_selectedRequest.Id);

if (_selectedRequest != null
&& _selectedRequest.AreAllRequiredHumanSignaturesCollected)
{
await CreateJob();
}
else
{
ToastService.ShowError("Invalid PSBT");
}
if (_selectedRequest != null
&& _selectedRequest.AreAllRequiredHumanSignaturesCollected)
{
await CreateJob();
}
else
{
ToastService.ShowError("Error while saving the signature");
ToastService.ShowError("Invalid PSBT");
}


await FetchRequests();
_allRequestsDatagrid.Dispose();
StateHasChanged();
_approveOperationConfirmationModal.CloseModal();
await _approveOperationConfirmationModal.CloseModal();
}
}

Expand All @@ -784,7 +768,7 @@
try
{
//TODO Async notifications when the channel has opened -> event / notifications system
IScheduler scheduler = await SchedulerFactory.GetScheduler();
var scheduler = await SchedulerFactory.GetScheduler();

var map = new JobDataMap();
map.Put("openRequestId", _selectedRequest.Id);
Expand Down
2 changes: 1 addition & 1 deletion src/Services/LightningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public static PSBT GetCombinedPsbt(ChannelOperationRequest channelOperationReque
{
//PSBT Combine
var signedPsbts = channelOperationRequest.ChannelOperationRequestPsbts.Where(x =>
!x.IsFinalisedPSBT && !x.IsInternalWalletPSBT && !x.IsTemplatePSBT);
channelOperationRequest.Wallet != null && !x.IsFinalisedPSBT && !x.IsInternalWalletPSBT && (channelOperationRequest.Wallet.IsHotWallet || !x.IsTemplatePSBT));
var signedPsbts2 = signedPsbts.Select(x => x.PSBT);

var combinedPSBT = LightningHelper.CombinePSBTs(signedPsbts2, _logger);
Expand Down
3 changes: 2 additions & 1 deletion test/FundsManager.Tests/Services/LightningServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ public void GetCombinedPsbt_CombinedPSBTExists()
};
var operationRequest = new ChannelOperationRequest()
{
ChannelOperationRequestPsbts = channelOpReqPsbts
ChannelOperationRequestPsbts = channelOpReqPsbts,
Wallet = CreateWallet.SingleSig(_internalWallet)
};

// Act
Expand Down

0 comments on commit 035ca2c

Please sign in to comment.