mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Refactor: Remove uneeded dependencies to PaymentMethodHandlerDictionary
This commit is contained in:
@@ -28,9 +28,6 @@ namespace BTCPayServer.Data
|
|||||||
{
|
{
|
||||||
public class StoreData
|
public class StoreData
|
||||||
{
|
{
|
||||||
[NotMapped]
|
|
||||||
[JsonIgnore]
|
|
||||||
public PaymentMethodHandlerDictionary PaymentMethodHandlerDictionary { get; set; }
|
|
||||||
public string Id
|
public string Id
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ namespace BTCPayServer.HostedServices
|
|||||||
foreach (var store in await ctx.Stores.ToArrayAsync())
|
foreach (var store in await ctx.Stores.ToArrayAsync())
|
||||||
{
|
{
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
_StoreRepository.PrepareEntity(store);
|
|
||||||
var blob = store.GetStoreBlob();
|
var blob = store.GetStoreBlob();
|
||||||
if (blob.WalletKeyPathRoots == null)
|
if (blob.WalletKeyPathRoots == null)
|
||||||
continue;
|
continue;
|
||||||
@@ -139,7 +138,6 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
foreach (var store in await ctx.Stores.ToArrayAsync())
|
foreach (var store in await ctx.Stores.ToArrayAsync())
|
||||||
{
|
{
|
||||||
_StoreRepository.PrepareEntity(store);
|
|
||||||
var blob = store.GetStoreBlob();
|
var blob = store.GetStoreBlob();
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
if (blob.NetworkFeeDisabled != null)
|
if (blob.NetworkFeeDisabled != null)
|
||||||
@@ -160,7 +158,6 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
foreach (var store in await ctx.Stores.ToArrayAsync())
|
foreach (var store in await ctx.Stores.ToArrayAsync())
|
||||||
{
|
{
|
||||||
_StoreRepository.PrepareEntity(store);
|
|
||||||
var blob = store.GetStoreBlob();
|
var blob = store.GetStoreBlob();
|
||||||
#pragma warning disable CS0612 // Type or member is obsolete
|
#pragma warning disable CS0612 // Type or member is obsolete
|
||||||
decimal multiplier = 1.0m;
|
decimal multiplier = 1.0m;
|
||||||
@@ -191,7 +188,6 @@ namespace BTCPayServer.HostedServices
|
|||||||
{
|
{
|
||||||
foreach (var store in await ctx.Stores.ToArrayAsync())
|
foreach (var store in await ctx.Stores.ToArrayAsync())
|
||||||
{
|
{
|
||||||
_StoreRepository.PrepareEntity(store);
|
|
||||||
foreach (var method in store.GetSupportedPaymentMethods(_NetworkProvider).OfType<Payments.Lightning.LightningSupportedPaymentMethod>())
|
foreach (var method in store.GetSupportedPaymentMethods(_NetworkProvider).OfType<Payments.Lightning.LightningSupportedPaymentMethod>())
|
||||||
{
|
{
|
||||||
var lightning = method.GetLightningUrl();
|
var lightning = method.GetLightningUrl();
|
||||||
|
|||||||
@@ -71,12 +71,10 @@ namespace BTCPayServer.Hosting
|
|||||||
{
|
{
|
||||||
var opts = o.GetRequiredService<BTCPayServerOptions>();
|
var opts = o.GetRequiredService<BTCPayServerOptions>();
|
||||||
var dbContext = o.GetRequiredService<ApplicationDbContextFactory>();
|
var dbContext = o.GetRequiredService<ApplicationDbContextFactory>();
|
||||||
var paymentMethodHandlerDictionary = o.GetService<PaymentMethodHandlerDictionary>();
|
|
||||||
var dbpath = Path.Combine(opts.DataDir, "InvoiceDB");
|
var dbpath = Path.Combine(opts.DataDir, "InvoiceDB");
|
||||||
if (!Directory.Exists(dbpath))
|
if (!Directory.Exists(dbpath))
|
||||||
Directory.CreateDirectory(dbpath);
|
Directory.CreateDirectory(dbpath);
|
||||||
return new InvoiceRepository(dbContext, dbpath, o.GetRequiredService<BTCPayNetworkProvider>(),
|
return new InvoiceRepository(dbContext, dbpath, o.GetRequiredService<BTCPayNetworkProvider>());
|
||||||
paymentMethodHandlerDictionary);
|
|
||||||
});
|
});
|
||||||
services.AddSingleton<BTCPayServerEnvironment>();
|
services.AddSingleton<BTCPayServerEnvironment>();
|
||||||
services.TryAddSingleton<TokenRepository>();
|
services.TryAddSingleton<TokenRepository>();
|
||||||
|
|||||||
@@ -38,11 +38,10 @@ namespace BTCPayServer.Services.Invoices
|
|||||||
|
|
||||||
private ApplicationDbContextFactory _ContextFactory;
|
private ApplicationDbContextFactory _ContextFactory;
|
||||||
private readonly BTCPayNetworkProvider _Networks;
|
private readonly BTCPayNetworkProvider _Networks;
|
||||||
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
|
|
||||||
private CustomThreadPool _IndexerThread;
|
private CustomThreadPool _IndexerThread;
|
||||||
|
|
||||||
public InvoiceRepository(ApplicationDbContextFactory contextFactory, string dbreezePath,
|
public InvoiceRepository(ApplicationDbContextFactory contextFactory, string dbreezePath,
|
||||||
BTCPayNetworkProvider networks, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary)
|
BTCPayNetworkProvider networks)
|
||||||
{
|
{
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
retry:
|
retry:
|
||||||
@@ -53,8 +52,7 @@ retry:
|
|||||||
catch when (retryCount++ < 5) { goto retry; }
|
catch when (retryCount++ < 5) { goto retry; }
|
||||||
_IndexerThread = new CustomThreadPool(1, "Invoice Indexer");
|
_IndexerThread = new CustomThreadPool(1, "Invoice Indexer");
|
||||||
_ContextFactory = contextFactory;
|
_ContextFactory = contextFactory;
|
||||||
_Networks = networks;
|
_Networks = networks.UnfilteredNetworks;
|
||||||
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InvoiceEntity CreateNewInvoice()
|
public InvoiceEntity CreateNewInvoice()
|
||||||
@@ -715,7 +713,7 @@ retry:
|
|||||||
private InvoiceEntity ToObject(byte[] value)
|
private InvoiceEntity ToObject(byte[] value)
|
||||||
{
|
{
|
||||||
var entity = NBitcoin.JsonConverters.Serializer.ToObject<InvoiceEntity>(ZipUtils.Unzip(value), null);
|
var entity = NBitcoin.JsonConverters.Serializer.ToObject<InvoiceEntity>(ZipUtils.Unzip(value), null);
|
||||||
entity.Networks = _Networks?.UnfilteredNetworks;
|
entity.Networks = _Networks;
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
private T ToObject<T>(byte[] value, BTCPayNetworkBase network)
|
private T ToObject<T>(byte[] value, BTCPayNetworkBase network)
|
||||||
|
|||||||
@@ -61,11 +61,6 @@ namespace BTCPayServer.Services.PaymentRequests
|
|||||||
string.IsNullOrEmpty(userId) ||
|
string.IsNullOrEmpty(userId) ||
|
||||||
(data.StoreData != null && data.StoreData.UserStores.Any(u => u.ApplicationUserId == userId)))
|
(data.StoreData != null && data.StoreData.UserStores.Any(u => u.ApplicationUserId == userId)))
|
||||||
.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);
|
.SingleOrDefaultAsync(x => x.Id == id, cancellationToken);
|
||||||
if (result != null)
|
|
||||||
{
|
|
||||||
result.StoreData = _storeRepository.PrepareEntity(result.StoreData);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,10 @@ namespace BTCPayServer.Services.Stores
|
|||||||
public class StoreRepository
|
public class StoreRepository
|
||||||
{
|
{
|
||||||
private ApplicationDbContextFactory _ContextFactory;
|
private ApplicationDbContextFactory _ContextFactory;
|
||||||
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
|
|
||||||
|
|
||||||
public StoreRepository(ApplicationDbContextFactory contextFactory, PaymentMethodHandlerDictionary paymentMethodHandlerDictionary)
|
public StoreRepository(ApplicationDbContextFactory contextFactory)
|
||||||
{
|
{
|
||||||
_ContextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory));
|
_ContextFactory = contextFactory ?? throw new ArgumentNullException(nameof(contextFactory));
|
||||||
_paymentMethodHandlerDictionary = paymentMethodHandlerDictionary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<StoreData> FindStore(string storeId)
|
public async Task<StoreData> FindStore(string storeId)
|
||||||
@@ -29,7 +27,7 @@ namespace BTCPayServer.Services.Stores
|
|||||||
using (var ctx = _ContextFactory.CreateContext())
|
using (var ctx = _ContextFactory.CreateContext())
|
||||||
{
|
{
|
||||||
var result = await ctx.FindAsync<StoreData>(storeId).ConfigureAwait(false);
|
var result = await ctx.FindAsync<StoreData>(storeId).ConfigureAwait(false);
|
||||||
return PrepareEntity(result);
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +50,7 @@ namespace BTCPayServer.Services.Stores
|
|||||||
#pragma warning disable CS0612 // Type or member is obsolete
|
#pragma warning disable CS0612 // Type or member is obsolete
|
||||||
us.Store.Role = us.Role;
|
us.Store.Role = us.Role;
|
||||||
#pragma warning restore CS0612 // Type or member is obsolete
|
#pragma warning restore CS0612 // Type or member is obsolete
|
||||||
return PrepareEntity(us.Store);
|
return us.Store;
|
||||||
}).FirstOrDefault();
|
}).FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +92,7 @@ namespace BTCPayServer.Services.Stores
|
|||||||
#pragma warning disable CS0612 // Type or member is obsolete
|
#pragma warning disable CS0612 // Type or member is obsolete
|
||||||
u.StoreData.Role = u.Role;
|
u.StoreData.Role = u.Role;
|
||||||
#pragma warning restore CS0612 // Type or member is obsolete
|
#pragma warning restore CS0612 // Type or member is obsolete
|
||||||
return PrepareEntity(u.StoreData);
|
return u.StoreData;
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +184,7 @@ namespace BTCPayServer.Services.Stores
|
|||||||
ctx.Add(store);
|
ctx.Add(store);
|
||||||
ctx.Add(userStore);
|
ctx.Add(userStore);
|
||||||
await ctx.SaveChangesAsync().ConfigureAwait(false);
|
await ctx.SaveChangesAsync().ConfigureAwait(false);
|
||||||
return PrepareEntity(store);
|
return store;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,12 +233,5 @@ namespace BTCPayServer.Services.Stores
|
|||||||
return ctx.Database.SupportDropForeignKey();
|
return ctx.Database.SupportDropForeignKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StoreData PrepareEntity(StoreData storeData)
|
|
||||||
{
|
|
||||||
if(storeData != null)
|
|
||||||
storeData.PaymentMethodHandlerDictionary = _paymentMethodHandlerDictionary;
|
|
||||||
return storeData;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user