using System; using System.Threading.Tasks; using BTCPayServer.Abstractions.Contracts; using BTCPayServer.Abstractions.Models; using BTCPayServer.Abstractions.Services; using BTCPayServer.Common; using BTCPayServer.Services.Stores; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NBitcoin; using WalletWasabi.Backend.Controllers; using WalletWasabi.Logging; using WalletWasabi.WabiSabi.Client; using LogLevel = WalletWasabi.Logging.LogLevel; namespace BTCPayServer.Plugins.Wabisabi; public class WabisabiPlugin : BaseBTCPayServerPlugin { public override IBTCPayServerPlugin.PluginDependency[] Dependencies { get; } = { new() { Identifier = nameof(BTCPayServer), Condition = ">=1.8.0" } }; public override void Execute(IServiceCollection applicationBuilder) { var utxoLocker = new LocalisedUTXOLocker(); applicationBuilder.AddSingleton( provider => { var res = ActivatorUtilities.CreateInstance(provider); res.UTXOLocker = utxoLocker; res.AddCoordinator("zkSNACKS Coordinator", "zksnacks", provider => { var chain = provider.GetService().GetExplorerClient("BTC").Network .NBitcoinNetwork.ChainName; if (chain == ChainName.Mainnet) { return new Uri("https://wasabiwallet.io/"); } if (chain == ChainName.Testnet) { return new Uri("https://wasabiwallet.co/"); } return new Uri("http://localhost:37127"); }); return res; }); applicationBuilder.AddHostedService(provider => provider.GetRequiredService()); applicationBuilder.AddSingleton(); applicationBuilder.AddSingleton(provider => new( provider, provider.GetRequiredService(), provider.GetRequiredService(), provider.GetRequiredService(), utxoLocker, provider.GetRequiredService(), provider.GetRequiredService>(), provider.GetRequiredService() )); applicationBuilder.AddWabisabiCoordinator(); applicationBuilder.AddSingleton(provider => provider.GetRequiredService()); applicationBuilder.AddHostedService(provider => provider.GetRequiredService()); ; applicationBuilder.AddSingleton(new UIExtension("Wabisabi/StoreIntegrationWabisabiOption", "store-integrations-list")); applicationBuilder.AddSingleton(new UIExtension("Wabisabi/WabisabiNav", "store-integrations-nav")); applicationBuilder.AddSingleton(new UIExtension("Wabisabi/WabisabiDashboard", "dashboard")); applicationBuilder.AddSingleton(new UIExtension("Wabisabi/WabisabiWalletSend", "onchain-wallet-send")); // applicationBuilder.AddSingleton(); Logger.SetMinimumLevel(LogLevel.Warning); Logger.SetModes(LogMode.DotNetLoggers); base.Execute(applicationBuilder); } // public class WabisabiPayoutProcessor: IPayoutProcessorFactory // { // private readonly LinkGenerator _linkGenerator; // // public WabisabiPayoutProcessor(LinkGenerator linkGenerator) // { // _linkGenerator = linkGenerator; // } // public string Processor { get; } = "Wabisabi"; // public string FriendlyName { get; } = "Coinjoin"; // public string ConfigureLink(string storeId, PaymentMethodId paymentMethodId, HttpRequest request) // { // return _linkGenerator.GetUriByAction( // nameof(WabisabiStoreController.UpdateWabisabiStoreSettings), // "WabisabiStore", // new { storeId}, // request.Scheme, // request.Host, // request.PathBase); // } // // public IEnumerable GetSupportedPaymentMethods() // { // return new[] {new PaymentMethodId("BTC", PaymentTypes.BTCLike)}; // } // // public Task ConstructProcessor(PayoutProcessorData settings) // { // return Task.FromResult(new ShellSerice()); // } // public class ShellSerice:IHostedService // { // public Task StartAsync(CancellationToken cancellationToken) // { // return Task.CompletedTask; // } // // public Task StopAsync(CancellationToken cancellationToken) // { // return Task.CompletedTask; // } // } // } // public override void Execute(IApplicationBuilder applicationBuilder, IServiceProvider applicationBuilderApplicationServices) { Task.Run(async () => { var walletProvider = (WalletProvider)applicationBuilderApplicationServices.GetRequiredService(); await walletProvider.ResetWabisabiStuckPayouts(null); }); Logger.DotnetLogger = applicationBuilderApplicationServices.GetService>(); base.Execute(applicationBuilder, applicationBuilderApplicationServices); } }