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
23 changes: 15 additions & 8 deletions Plugins/SamRockProtocol/Controllers/ProtocolController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
var descriptor = setupModel.BTC.Descriptor;

// Extract script type, fingerprint, derivation path, xpub, and address derivation suffix
var match = Regex.Match(descriptor, @"^(\w+)\(\[([a-fA-F0-9]{8})/([^\]]+)\](xpub[^/\)]+)(/[^\)]+)?\)(?:#[a-zA-Z0-9]+)?");
var match = Regex.Match(descriptor, @"^(\w+)\(\[([a-fA-F0-9]{8})/([^\]]+)\](xpub[^/\)]+)(/[^\)]+)?\)(?:#[a-zA-Z0-9]+)?$");
if (!match.Success)
{
result.Results[key] = new SamRockProtocolResponse(false,
Expand Down Expand Up @@ -252,7 +252,15 @@
{
if (string.Equals(setupModel.BTCLN.Type, "Boltz", StringComparison.OrdinalIgnoreCase))
{
await boltzWrapper.SetBoltz(StoreId, setupModel.BTCLN.LBTC.Descriptor, result);
if (string.IsNullOrWhiteSpace(setupModel.BTCLN.LBTC?.Descriptor))
{
result.Results[SamRockProtocolKeys.BTC_LN] = new SamRockProtocolResponse(false,
"Boltz setup requires a Liquid descriptor.", null);
}
else
{
await boltzWrapper.SetBoltz(StoreId, setupModel.BTCLN.LBTC.Descriptor, result);
}
}
else
{
Expand All @@ -264,12 +272,11 @@
// TODO: If both LBTC is set and BtcLn is set, need to generate as many addresses for LiquidChain
// as we have in setupModel.BtcLn.LiquidAddresses.Length to reserve them

var allSuccess = result.Results.Values.All(a => a.Success);
var allSuccess = result.Results.Count > 0 && result.Results.Values.All(a => a.Success);
string errorMessage = null;
if (!allSuccess && result.Results[SamRockProtocolKeys.BTC_LN] != null)
if (!allSuccess && result.Results.TryGetValue(SamRockProtocolKeys.BTC_LN, out var lnResult))
{
var res = result.Results[SamRockProtocolKeys.BTC_LN];
errorMessage = res.Message;
errorMessage = lnResult.Message;
}

samrockProtocolService.OtpUsed(otp, allSuccess, errorMessage);
Expand All @@ -278,8 +285,8 @@

return Ok(new
{
Success = true,
Message = "Wallet setup successfully.",
Success = allSuccess,
Message = allSuccess ? "Wallet setup successfully." : "Wallet setup failed.",
Result = result
});
}
Expand Down Expand Up @@ -343,7 +350,7 @@
if (isOD.Success)
{
var derivationSchemeSettings = new DerivationSchemeSettings();
var result = parser.ParseOutputDescriptor(derivationScheme);

Check warning on line 353 in Plugins/SamRockProtocol/Controllers/ProtocolController.cs

View workflow job for this annotation

GitHub Actions / build

'DerivationSchemeParser.ParseOutputDescriptor(string)' is obsolete: 'Use ParseOD instead'
derivationSchemeSettings.AccountOriginal = derivationScheme.Trim();
derivationSchemeSettings.AccountDerivation = result.Item1;
derivationSchemeSettings.AccountKeySettings = result.Item2?.Select((path, i) => new AccountKeySettings
Expand Down
4 changes: 4 additions & 0 deletions Plugins/SamRockProtocol/Models/SamRockProtocolResponse.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using Newtonsoft.Json;

namespace SamRockProtocol.Models;

public class SamRockProtocolResponse(bool success, string message, Exception exception)
{
public bool Success { get; set; } = success;
public string Message { get; set; } = message;
public string Error { get; set; } = exception?.Message;

[JsonIgnore]
public Exception Exception { get; set; } = exception;
}
Loading