More logging
This commit is contained in:
@ -37,12 +37,12 @@ public class Lnurl
|
|||||||
"^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
|
"^(([^<>()\\[\\]\\\\.,;:\\s@\"]+(\\.[^<>()\\[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$");
|
||||||
|
|
||||||
lnurl = lnurl.ToLower().Trim();
|
lnurl = lnurl.ToLower().Trim();
|
||||||
|
|
||||||
if (lnurl.StartsWith("lnurlp:"))
|
if (lnurl.StartsWith("lnurlp:"))
|
||||||
{
|
{
|
||||||
return new Uri(lnurl.Replace("lnurlp://", "https://"));
|
return new Uri(lnurl.Replace("lnurlp://", "https://"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lnurl.StartsWith("lnurl"))
|
if (lnurl.StartsWith("lnurl"))
|
||||||
{
|
{
|
||||||
Bech32.Decode(lnurl, out var hrp, out var decoded);
|
Bech32.Decode(lnurl, out var hrp, out var decoded);
|
||||||
@ -72,8 +72,7 @@ public class Lnurl
|
|||||||
public async Task<LNURLService?> LoadAsync(string lnurl)
|
public async Task<LNURLService?> LoadAsync(string lnurl)
|
||||||
{
|
{
|
||||||
var url = ParseLnUrl(lnurl);
|
var url = ParseLnUrl(lnurl);
|
||||||
using var httpClient = new HttpClient();
|
var response = await _client.GetAsync(url);
|
||||||
var response = await httpClient.GetAsync(url);
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
@ -112,8 +111,7 @@ public class Lnurl
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var httpClient = new HttpClient();
|
var response = await _client.GetAsync(builder.Uri);
|
||||||
var response = await httpClient.GetAsync(builder.Uri);
|
|
||||||
if (response.IsSuccessStatusCode)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
@ -130,7 +128,7 @@ public class Lnurl
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new LNURLError(LNURLErrorCode.ServiceUnavailable, "Failed to load callback");
|
throw new LNURLError(LNURLErrorCode.ServiceUnavailable, $"Failed to load callback: {e.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,23 +137,31 @@ public class ZapperRelay : INostrRelay, IDisposable
|
|||||||
};
|
};
|
||||||
|
|
||||||
var zapSigned = zap.Sign(key);
|
var zapSigned = zap.Sign(key);
|
||||||
var invoice = await _lnurl.GetInvoiceAsync(svc, 5, "Thanks for your interaction!", zapSigned);
|
try
|
||||||
if (string.IsNullOrEmpty(invoice.Pr))
|
|
||||||
{
|
{
|
||||||
return new(false, $"blocked: failed to get invoice from {parsedTarget}");
|
var invoice = await _lnurl.GetInvoiceAsync(svc, 5, "Thanks for your interaction!", zapSigned);
|
||||||
}
|
if (string.IsNullOrEmpty(invoice.Pr))
|
||||||
|
{
|
||||||
|
return new(false, $"blocked: failed to get invoice from {parsedTarget}");
|
||||||
|
}
|
||||||
|
|
||||||
_logger.LogInformation("Paying invoice {pr}", invoice.Pr);
|
_logger.LogInformation("Paying invoice {pr}", invoice.Pr);
|
||||||
if (!await _albyApi.PayInvoice(invoice.Pr))
|
if (!await _albyApi.PayInvoice(invoice.Pr))
|
||||||
|
{
|
||||||
|
return new(false, "blocked: failed to pay invoice!");
|
||||||
|
}
|
||||||
|
|
||||||
|
var seenEvent = NostrBuf.Encode(ev);
|
||||||
|
(await _session.UpsertAsync(ref seenId, ref seenEvent)).Complete();
|
||||||
|
|
||||||
|
_logger.LogInformation("Zapped {name}!", senderProfile.Name);
|
||||||
|
return new(true, "Zapped!");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return new(false, "blocked: failed to pay invoice!");
|
_logger.LogError(e.ToString());
|
||||||
|
return new(false, $"blocked: Oh no! something went wrong! {e.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var seenEvent = NostrBuf.Encode(ev);
|
|
||||||
(await _session.UpsertAsync(ref seenId, ref seenEvent)).Complete();
|
|
||||||
|
|
||||||
_logger.LogInformation("Zapped {name}!", senderProfile.Name);
|
|
||||||
return new(true, "Zapped!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new(false, "blocked: kind not accepted, no zap for you!");
|
return new(false, "blocked: kind not accepted, no zap for you!");
|
||||||
|
Reference in New Issue
Block a user