mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-31 11:54:24 +01:00
Fix Local client
This cleans up the client factory for plugins so that it is less hectic looking. Additionally, it fixes a bug where if you reuse the factory after setting a store, the state might stick.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BTCPayServer.Abstractions.Contracts;
|
||||
@@ -6,5 +7,6 @@ namespace BTCPayServer.Abstractions.Contracts;
|
||||
public interface IStoreRepository
|
||||
{
|
||||
Task<T?> GetSettingAsync<T>(string storeId, string name) where T : class;
|
||||
Task<Dictionary<string, T?>> GetSettingsAsync<T>(string name) where T : class;
|
||||
Task UpdateSetting<T>(string storeId, string name, T obj) where T : class;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ using BTCPayServer.Services.Custodian.Client.MockCustodian;
|
||||
using BTCPayServer.Services;
|
||||
using BTCPayServer.Services.Notifications;
|
||||
using BTCPayServer.Services.Notifications.Blobs;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NBitcoin;
|
||||
@@ -58,8 +59,19 @@ namespace BTCPayServer.Tests
|
||||
var s = await client.GetStores();
|
||||
var store = await client.GetStore(user.StoreId);
|
||||
Assert.NotNull(store);
|
||||
var addr = await client.GetLightningDepositAddress(user.StoreId,"BTC");
|
||||
var addr = await client.GetLightningDepositAddress(user.StoreId, "BTC");
|
||||
Assert.NotNull(BitcoinAddress.Create(addr, Network.RegTest));
|
||||
|
||||
await user.CreateStoreAsync();
|
||||
var store1 = user.StoreId;
|
||||
await user.CreateStoreAsync();
|
||||
var store2 = user.StoreId;
|
||||
var store1Client = await factory.Create(null, store1);
|
||||
var store2Client = await factory.Create(null, store2);
|
||||
var store1Res = await store1Client.GetStore(store1);
|
||||
var store2Res = await store2Client.GetStore(store2);
|
||||
Assert.Equal(store1, store1Res.Id);
|
||||
Assert.Equal(store2, store2Res.Id);
|
||||
}
|
||||
|
||||
[Fact(Timeout = TestTimeout)]
|
||||
|
||||
@@ -90,8 +90,8 @@
|
||||
<PackageReference Include="TwentyTwenty.Storage.Google" Version="2.12.1" />
|
||||
<PackageReference Include="TwentyTwenty.Storage.Local" Version="2.12.1" />
|
||||
<PackageReference Include="YamlDotNet" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -384,6 +384,13 @@ namespace BTCPayServer.Services.Stores
|
||||
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, T?>> GetSettingsAsync<T>(string name) where T : class
|
||||
{
|
||||
await using var ctx = _ContextFactory.CreateContext();
|
||||
var data = await ctx.StoreSettings.Where(s => s.Name == name).ToDictionaryAsync(settingData => settingData.StoreId);
|
||||
return data.ToDictionary(pair => pair.Key, pair => Deserialize<T>(pair.Value.Value));
|
||||
}
|
||||
|
||||
public async Task UpdateSetting<T>(string storeId, string name, T obj) where T : class
|
||||
{
|
||||
await using var ctx = _ContextFactory.CreateContext();
|
||||
|
||||
Reference in New Issue
Block a user