Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/updgrade dotnet8 #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/LnProxyApi.App.Tests/bin/Debug/net8.0/LnProxyApi.App.Tests.dll",
"args": [],
"cwd": "${workspaceFolder}/LnProxyApi.App.Tests",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/LnProxyApi.App.Tests/LnProxyApi.App.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/LnProxyApi.App.Tests/LnProxyApi.App.Tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/LnProxyApi.App.Tests/LnProxyApi.App.Tests.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
5 changes: 0 additions & 5 deletions LnProxyApi.App.Tests/HelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ namespace LnProxyApi.App.Tests;

public class LnProxyTests
{
[SetUp]
public void Setup()
{

}

[Test]
public void HexStringHelperTest()
Expand Down
2 changes: 1 addition & 1 deletion LnProxyApi.App.Tests/LnProxyApi.App.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
3 changes: 2 additions & 1 deletion LnProxyApi.App.Tests/LnProxyValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class InvoiceValidationTests
public void Setup()
{
var configuration = new Mock<IConfiguration>().Object;
var lndGrpcClientService = new Mock<LnGrpcClientService>(configuration).Object;
var logger = new Mock<ILogger<LightningService>>().Object;
lightningService = new LightningService(configuration, logger);
lightningService = new LightningService(logger, lndGrpcClientService);
}

[Test]
Expand Down
10 changes: 5 additions & 5 deletions LnProxyApi.App/Controllers/LnProxyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace LnProxyApi.Controllers;
[ApiController]
public class LnProxyController : ControllerBase
{
private readonly IConfiguration _configuration;
private readonly ILogger<LnProxyController> _logger;
private readonly LightningService _lightningService;

public LnProxyController(IConfiguration configuration, ILogger<LnProxyController> logger)
public LnProxyController(ILogger<LnProxyController> logger, LightningService lightningService)
{
_configuration = configuration;
_lightningService = lightningService;
_logger = logger;
}

Expand All @@ -31,10 +31,10 @@ public IActionResult Post([FromBody] LnProxyModel request)
return BadRequest(ModelState);
}

var lightningService = new LightningService(_configuration, _logger);

_logger.LogInformation($"Creating proxy request invoice {request.Invoice}: {@request}");

AddHoldInvoiceResp response = lightningService.CreateHodlInvoice(
AddHoldInvoiceResp response = _lightningService.CreateHodlInvoice(
request.Invoice,
request.Description,
request.DescriptionHash,
Expand Down
2 changes: 1 addition & 1 deletion LnProxyApi.App/LnProxyApi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions LnProxyApi.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using LnProxyApi.LndGrpc.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
builder.Services.AddSingleton<LnGrpcClientService>();
builder.Services.AddSingleton<LightningService>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
Expand Down
20 changes: 10 additions & 10 deletions LnProxyApi.App/Services/LightningService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public class LightningService
{ Invoice.Types.InvoiceState.Open, "OPEN" }
};

private LnGrpcClientService lnGrpcService;
private readonly ILogger _logger;
private LnGrpcClientService _lnGrpcService;
private readonly ILogger <LightningService> _logger;

public LightningService(IConfiguration configuration, ILogger logger)
public LightningService(ILogger <LightningService> logger, LnGrpcClientService lnGrpcService)
{
_logger = logger;
lnGrpcService = new LnGrpcClientService(configuration);
_lnGrpcService = lnGrpcService;
}


private PayReq DecodePayRequest(string invoice)
{
try
{
var client = lnGrpcService.GetLightningClient();
var client = _lnGrpcService.GetLightningClient();
var payReq = new PayReqString
{
PayReq = invoice,
Expand All @@ -61,7 +61,7 @@ private PayReq DecodePayRequest(string invoice)

private async Task SettleAndPayInvoice(PayReq originalInvoice, string request, long feeLimitMsat)
{
var routerClient = lnGrpcService.GetRouterClient();
var routerClient = _lnGrpcService.GetRouterClient();
var estimateFee = EstimateRouteFee(originalInvoice).Result;
var req = new SendPaymentRequest()
{
Expand All @@ -76,7 +76,7 @@ private async Task SettleAndPayInvoice(PayReq originalInvoice, string request, l
await foreach (var payment in call.ResponseStream.ReadAllAsync())
{
try
{ var invoiceClient = lnGrpcService.GetInvoiceClient();
{ var invoiceClient = _lnGrpcService.GetInvoiceClient();
if (payment.Status == Payment.Types.PaymentStatus.Failed)
{
var cancel = new CancelInvoiceMsg()
Expand Down Expand Up @@ -118,7 +118,7 @@ private async Task SettleAndPayInvoice(PayReq originalInvoice, string request, l

public async Task SubscribeToHodlInvoice(ByteString rHash, PayReq originalInvoice, string originalRequest, long feeLimitMsat)
{
var invoiceClient = lnGrpcService.GetInvoiceClient();
var invoiceClient = _lnGrpcService.GetInvoiceClient();

var sub = new SubscribeSingleInvoiceRequest() { RHash = rHash };
var call = invoiceClient.SubscribeSingleInvoice(sub);
Expand Down Expand Up @@ -168,7 +168,7 @@ private async Task<RouteFeeResponse> EstimateRouteFee(PayReq payReqFromInvoice)
{
try
{
var client = lnGrpcService.GetRouterClient();
var client = _lnGrpcService.GetRouterClient();
var route = new RouteFeeRequest()
{
AmtSat = payReqFromInvoice.NumSatoshis,
Expand Down Expand Up @@ -271,7 +271,7 @@ public AddHoldInvoiceResp CreateHodlInvoice(string payRequestString, string? pay

ValidateInvoice(payReqFromInvoice, hodlInvoice);

var invoiceResponse = lnGrpcService.GetInvoiceClient().AddHoldInvoice(hodlInvoice);
var invoiceResponse = _lnGrpcService.GetInvoiceClient().AddHoldInvoice(hodlInvoice);
_logger.LogInformation($"Created hodl invoice: {@invoiceResponse}");
_ = SubscribeToHodlInvoice(hodlInvoice.Hash, payReqFromInvoice, payRequestString, feeBudgetMsat);
return invoiceResponse;
Expand Down
31 changes: 31 additions & 0 deletions LnProxyApi.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LnProxyApi", "LnProxyApi.App\LnProxyApi.csproj", "{462E9C37-8A3A-4D1F-9829-D81CB85FCE4D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LnProxyApi.App.Tests", "LnProxyApi.App.Tests\LnProxyApi.App.Tests.csproj", "{83AEB476-275E-4FA0-9622-011BC9776FC9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{462E9C37-8A3A-4D1F-9829-D81CB85FCE4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{462E9C37-8A3A-4D1F-9829-D81CB85FCE4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{462E9C37-8A3A-4D1F-9829-D81CB85FCE4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{462E9C37-8A3A-4D1F-9829-D81CB85FCE4D}.Release|Any CPU.Build.0 = Release|Any CPU
{83AEB476-275E-4FA0-9622-011BC9776FC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83AEB476-275E-4FA0-9622-011BC9776FC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83AEB476-275E-4FA0-9622-011BC9776FC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83AEB476-275E-4FA0-9622-011BC9776FC9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DF2CF7F5-C638-4A2E-B4CE-C3AE4D27F7A8}
EndGlobalSection
EndGlobal