mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-23 14:40:36 +01:00
add common proj
This commit is contained in:
parent
ed4dea214d
commit
d8c519d008
10 changed files with 131 additions and 54 deletions
9
BTCPayApp.CommonServer/BTCPayApp.CommonServer.csproj
Normal file
9
BTCPayApp.CommonServer/BTCPayApp.CommonServer.csproj
Normal file
|
@ -0,0 +1,9 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<LangVersion>8</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
7
BTCPayApp.CommonServer/IBTCPayAppServerClient.cs
Normal file
7
BTCPayApp.CommonServer/IBTCPayAppServerClient.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace BTCPayApp.CommonServer
|
||||
{
|
||||
public interface IBTCPayAppServerClient
|
||||
{
|
||||
|
||||
}
|
||||
}
|
13
BTCPayApp.CommonServer/PairSuccessResult.cs
Normal file
13
BTCPayApp.CommonServer/PairSuccessResult.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace BTCPayApp.CommonServer
|
||||
{
|
||||
public class PairSuccessResult
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string StoreId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
|
||||
public string? ExistingWallet { get; set; }
|
||||
public string? ExistingWalletSeed { get; set; }
|
||||
public string Network { get; set; }
|
||||
}
|
||||
}
|
21
BTCPayServer/App/BTCPayAppExtensions.cs
Normal file
21
BTCPayServer/App/BTCPayAppExtensions.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace BTCPayServer.Controllers;
|
||||
|
||||
public static class BTCPayAppExtensions
|
||||
{
|
||||
public static IServiceCollection AddBTCPayApp(this IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddSingleton<BtcPayAppService>();
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
public static void UseBTCPayApp(this IApplicationBuilder builder)
|
||||
{
|
||||
builder.UseEndpoints(routeBuilder =>
|
||||
{
|
||||
routeBuilder.MapHub<BTCPayAppHub>("hub/btcpayapp");
|
||||
});
|
||||
}
|
||||
}
|
8
BTCPayServer/App/BTCPayAppHub.cs
Normal file
8
BTCPayServer/App/BTCPayAppHub.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
using BTCPayApp.CommonServer;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace BTCPayServer.Controllers;
|
||||
|
||||
public class BTCPayAppHub : Hub<IBTCPayAppServerClient>
|
||||
{
|
||||
}
|
20
BTCPayServer/App/BTCPayAppPlugin.cs
Normal file
20
BTCPayServer/App/BTCPayAppPlugin.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using BTCPayServer.Abstractions.Models;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace BTCPayServer.Controllers;
|
||||
|
||||
public class BTCPayAppPlugin : BaseBTCPayServerPlugin
|
||||
{
|
||||
public override void Execute(IApplicationBuilder applicationBuilder,
|
||||
IServiceProvider applicationBuilderApplicationServices)
|
||||
{
|
||||
applicationBuilder.UseBTCPayApp();
|
||||
}
|
||||
|
||||
public override void Execute(IServiceCollection applicationBuilder)
|
||||
{
|
||||
applicationBuilder.AddBTCPayApp();
|
||||
}
|
||||
}
|
|
@ -1,53 +1,19 @@
|
|||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayApp.CommonServer;
|
||||
using BTCPayServer.Client;
|
||||
using BTCPayServer.Data;
|
||||
using BTCPayServer.Plugins.Shopify;
|
||||
using BTCPayServer.Security.Greenfield;
|
||||
using BTCPayServer.Services.Stores;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using NBitcoin;
|
||||
using NBitcoin.DataEncoders;
|
||||
using NBXplorer;
|
||||
|
||||
namespace BTCPayServer.Controllers;
|
||||
|
||||
public class BtcPayAppService
|
||||
{
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
public BtcPayAppService(IMemoryCache memoryCache)
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
|
||||
private string CacheKey(string k) => $"BtcPayAppService_{k}";
|
||||
|
||||
public async Task<string> GeneratePairingCode(string storeId, string userId)
|
||||
{
|
||||
var code = Guid.NewGuid().ToString();
|
||||
_memoryCache.Set(CacheKey(code), new PairingRequest() {Key = code, StoreId = storeId, UserId = userId},
|
||||
TimeSpan.FromMinutes(5));
|
||||
return code;
|
||||
}
|
||||
|
||||
public PairingRequest? ConsumePairingCode(string code)
|
||||
{
|
||||
return _memoryCache.TryGetValue(CacheKey(code), out var pairingRequest)
|
||||
? (PairingRequest?)pairingRequest
|
||||
: null;
|
||||
}
|
||||
|
||||
public class PairingRequest
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string StoreId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
[Route("btcpayapp")]
|
||||
public class BtcPayAppController : Controller
|
||||
{
|
||||
|
@ -58,7 +24,8 @@ public class BtcPayAppController : Controller
|
|||
private readonly ExplorerClientProvider _explorerClientProvider;
|
||||
|
||||
public BtcPayAppController(BtcPayAppService appService, APIKeyRepository apiKeyRepository,
|
||||
StoreRepository storeRepository, BTCPayNetworkProvider btcPayNetworkProvider, ExplorerClientProvider explorerClientProvider)
|
||||
StoreRepository storeRepository, BTCPayNetworkProvider btcPayNetworkProvider,
|
||||
ExplorerClientProvider explorerClientProvider)
|
||||
{
|
||||
_appService = appService;
|
||||
_apiKeyRepository = apiKeyRepository;
|
||||
|
@ -106,28 +73,21 @@ public class BtcPayAppController : Controller
|
|||
Key = key.Id,
|
||||
StoreId = store.Id,
|
||||
UserId = res.UserId,
|
||||
ExistingWallet = onchain?.AccountDerivation?.GetExtPubKeys()?.FirstOrDefault()?.ToString(onchain.Network.NBitcoinNetwork),
|
||||
ExistingWallet =
|
||||
onchain?.AccountDerivation?.GetExtPubKeys()?.FirstOrDefault()
|
||||
?.ToString(onchain.Network.NBitcoinNetwork),
|
||||
ExistingWalletSeed = onchainSeed,
|
||||
Network = _btcPayNetworkProvider.GetNetwork<BTCPayNetwork>("BTC").NBitcoinNetwork.Name
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private async Task<string?> GetSeed(ExplorerClient client, DerivationSchemeSettings derivation)
|
||||
{
|
||||
return derivation.IsHotWallet &&
|
||||
await client.GetMetadataAsync<string>(derivation.AccountDerivation, WellknownMetadataKeys.Mnemonic) is { } seed &&
|
||||
!string.IsNullOrEmpty(seed) ? seed : null;
|
||||
}
|
||||
|
||||
|
||||
public class PairSuccessResult
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string StoreId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
|
||||
public string? ExistingWallet { get; set; }
|
||||
public string? ExistingWalletSeed { get; set; }
|
||||
public string Network { get; set; }
|
||||
await client.GetMetadataAsync<string>(derivation.AccountDerivation, WellknownMetadataKeys.Mnemonic) is
|
||||
{ } seed &&
|
||||
!string.IsNullOrEmpty(seed)
|
||||
? seed
|
||||
: null;
|
||||
}
|
||||
}
|
39
BTCPayServer/App/BtcPayAppService.cs
Normal file
39
BTCPayServer/App/BtcPayAppService.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace BTCPayServer.Controllers;
|
||||
|
||||
public class BtcPayAppService
|
||||
{
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
public BtcPayAppService(IMemoryCache memoryCache)
|
||||
{
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
|
||||
private string CacheKey(string k) => $"BtcPayAppService_{k}";
|
||||
|
||||
public async Task<string> GeneratePairingCode(string storeId, string userId)
|
||||
{
|
||||
var code = Guid.NewGuid().ToString();
|
||||
_memoryCache.Set(CacheKey(code), new PairingRequest() {Key = code, StoreId = storeId, UserId = userId},
|
||||
TimeSpan.FromMinutes(5));
|
||||
return code;
|
||||
}
|
||||
|
||||
public PairingRequest? ConsumePairingCode(string code)
|
||||
{
|
||||
return _memoryCache.TryGetValue(CacheKey(code), out var pairingRequest)
|
||||
? (PairingRequest?)pairingRequest
|
||||
: null;
|
||||
}
|
||||
|
||||
public class PairingRequest
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string StoreId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
}
|
|
@ -99,6 +99,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BTCPayApp.CommonServer\BTCPayApp.CommonServer.csproj" />
|
||||
<ProjectReference Include="..\BTCPayServer.Abstractions\BTCPayServer.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\BTCPayServer.Client\BTCPayServer.Client.csproj" />
|
||||
<ProjectReference Include="..\BTCPayServer.Data\BTCPayServer.Data.csproj" />
|
||||
|
|
|
@ -517,7 +517,6 @@ o.GetRequiredService<IEnumerable<IPaymentLinkExtension>>().ToDictionary(o => o.P
|
|||
});
|
||||
}
|
||||
|
||||
services.AddSingleton<BtcPayAppService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue