BuildModel( EditSmtpExternalServiceViewModel viewModel, ExternalServiceData mainModel) { if (ModelState.IsValid && !string.IsNullOrEmpty(viewModel.TestEmail)) { var data = new ExternalServiceData(); data.Set(viewModel); data.Type = ExternalServiceType; var smtpService = new SmtpService(data); var error = await SendTestEmail(smtpService, viewModel.TestEmail); if (string.IsNullOrEmpty(error)) { viewModel.TestEmail = string.Empty; } else { ModelState.AddModelError(nameof(viewModel.TestEmail), error); } } if (!ModelState.IsValid) { return(null, viewModel); } mainModel.Set(viewModel); return(mainModel, null); }
BuildModel(EditExchangeExternalServiceDataViewModel viewModel, ExternalServiceData mainModel) { //current External Service data var externalServiceData = mainModel; if (!ModelState.IsValid) { return(null, new EditExchangeExternalServiceDataViewModel(viewModel, ExchangeService.GetAvailableExchanges())); } //current External Service data externalServiceData.Set((ExchangeExternalServiceData)viewModel); var exchangeService = new ExchangeService(externalServiceData); if (!await exchangeService.TestAccess()) { ModelState.AddModelError(String.Empty, "Could not connect with current settings"); return(null, new EditExchangeExternalServiceDataViewModel(viewModel, ExchangeService.GetAvailableExchanges())); } return(externalServiceData, null); }
public async Task ExchangeService_CanConstructClient() { var InvalidData = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now, }; var externalServiceData = new ExternalServiceData() { Type = ExchangeService.ExchangeServiceType, Name = "something" }; externalServiceData.Set(InvalidData); var exchangeService = GetExternalService(externalServiceData); await Assert.ThrowsAnyAsync <Exception>(async() => await exchangeService.ConstructClient()); var validData = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now, ExchangeName = "Binance", PrivateKey = "aa" }; externalServiceData.Set(validData); Assert.NotNull(exchangeService.ConstructClient()); }
public void ExchangeService_CanInitiate() { //import for service discovery to be able to initiate without constructor _ = new ExchangeService(); Assert.Throws <ArgumentException>(() => { _ = new ExchangeService(new ExternalServiceData() { Type = "invalid" }); }); var data = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now }; var externalServiceData = new ExternalServiceData() { Type = ExchangeService.ExchangeServiceType, Name = "something" }; externalServiceData.Set(data); var exchangeService = new ExchangeService(externalServiceData); Assert.Equal(exchangeService.GetData().PublicKey, data.PublicKey); Assert.Equal(exchangeService.GetData().PairedDate, data.PairedDate); }
public async Task AddOrUpdateExternalServiceData(ExternalServiceData externalServiceData) { using (var scope = _serviceScopeFactory.CreateScope()) { using (var context = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>()) { var created = false; if (string.IsNullOrEmpty(externalServiceData.Id)) { await context.ExternalServices.AddAsync(externalServiceData); created = true; } else { context.Attach(externalServiceData).State = EntityState.Modified; context.ExternalServices.Update(externalServiceData); } await context.SaveChangesAsync(); OnExternalServiceDataUpdated(new UpdatedItem <ExternalServiceData>() { Item = externalServiceData, Action = created ? UpdatedItem <ExternalServiceData> .UpdateAction.Added : UpdatedItem <ExternalServiceData> .UpdateAction.Updated }); } } }
public LightningNodeService(ExternalServiceData data, NBXplorerClientProvider nbXplorerClientProvider, NBXplorerSummaryProvider nbXplorerSummaryProvider, SocketFactory socketFactory) : base(data) { _nbXplorerClientProvider = nbXplorerClientProvider; _nbXplorerSummaryProvider = nbXplorerSummaryProvider; _socketFactory = socketFactory; }
BuildModel(EditExchangeExternalServiceDataViewModel viewModel, ExternalServiceData mainModel) { //current External Service data var externalServiceData = mainModel; if (!ModelState.IsValid) { return(null, new EditExchangeExternalServiceDataViewModel(viewModel, await ExchangeService.GetAvailableExchanges())); } //current External Service data externalServiceData.Set((ExchangeExternalServiceData)viewModel); var exchangeService = new ExchangeService(externalServiceData); if (!await exchangeService.TestAccess()) { ModelState.AddModelError(String.Empty, "Could not connect with current settings. Transmuter tests against fetching your balance amount from the exchange so you would need to enable that option if available"); return(null, new EditExchangeExternalServiceDataViewModel(viewModel, await ExchangeService.GetAvailableExchanges())); } return(externalServiceData, null); }
public DynamicServiceService(ExternalServiceData data, IRecipeManager recipeManager, IActionDispatcher actionDispatcher, IExternalServiceManager externalServiceManager) : base(data) { _data = data; _recipeManager = recipeManager; _actionDispatcher = actionDispatcher; _externalServiceManager = externalServiceManager; }
public NBXplorerWalletService(ExternalServiceData data, NBXplorerPublicWalletProvider nbXplorerPublicWalletProvider, DerivationSchemeParser derivationSchemeParser, NBXplorerClientProvider nbXplorerClientProvider) : base(data) { _nbXplorerPublicWalletProvider = nbXplorerPublicWalletProvider; _derivationSchemeParser = derivationSchemeParser; _nbXplorerClientProvider = nbXplorerClientProvider; }
protected BaseExternalService(ExternalServiceData data) { if (data.Type != ExternalServiceType) { throw new ArgumentException("f**k this shit you gave me the wrong external service data"); } _data = data; }
public Task <IViewComponentResult> InvokeAsync(ExternalServiceData serviceData, bool showAllData) { return(Task.FromResult <IViewComponentResult>(View(new ViewExternalServiceViewModel() { ShowAllData = showAllData, ExternalServiceData = serviceData, ExternalServiceDescriptor = _externalServiceDescriptors .SingleOrDefault(descriptor => descriptor.ExternalServiceType == serviceData.Type) }))); }
protected override Task <EditNBXplorerWalletExternalServiceDataViewModel> BuildViewModel( ExternalServiceData data) { var vm = new EditNBXplorerWalletExternalServiceDataViewModel( new NBXplorerWalletService(data, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _nbXplorerClientProvider) .GetData()); vm.CryptoCodes = new SelectList(_nbXplorerOptions.Cryptos?.ToList() ?? new List <string>(), vm.CryptoCode); return(Task.FromResult(vm)); }
protected override Task <(ExternalServiceData ToSave, SmtpExternalServiceData showViewModel)> BuildModel( SmtpExternalServiceData viewModel, ExternalServiceData mainModel) { if (!ModelState.IsValid) { return(Task.FromResult <(ExternalServiceData ToSave, SmtpExternalServiceData showViewModel)>((null, viewModel))); } mainModel.Set(viewModel); return(Task.FromResult <(ExternalServiceData ToSave, SmtpExternalServiceData showViewModel)>((mainModel, null))); }
protected override async Task <EditBtcPayServerDataViewModel> BuildViewModel(ExternalServiceData data) { var client = new BtcPayServerService(data); var clientData = client.GetData(); return(new EditBtcPayServerDataViewModel() { Seed = clientData.Seed ?? new Mnemonic(Wordlist.English, WordCount.Twelve).ToString(), Server = clientData.Server, PairingUrl = await client.GetPairingUrl(data.Name), Paired = await client.CheckAccess() }); }
protected override Task <EditSmtpExternalServiceViewModel> BuildViewModel(ExternalServiceData data) { var serviceData = new SmtpService(data).GetData(); return(Task.FromResult(new EditSmtpExternalServiceViewModel() { Password = serviceData.Password, Port = serviceData.Port, Server = serviceData.Server, Username = serviceData.Username, SSL = serviceData.SSL })); }
private async Task <(IActionResult Error, ExternalServiceData Data)> GetExternalServiceData(string identifier) { ExternalServiceData data = null; if (identifier.StartsWith("new")) { if (!_memoryCache.TryGetValue(identifier, out data)) { return(RedirectToAction("GetServices", "ExternalServices", new { statusMessage = "Error:Data could not be found or data session expired" }), null); } if (data.UserId != _userManager.GetUserId(User)) { return(RedirectToAction("GetServices", "ExternalServices", new { statusMessage = "Error:Data could not be found or data session expired" }), null); } } else { var services = await _externalServiceManager.GetExternalServicesData(new ExternalServicesDataQuery() { UserId = _userManager.GetUserId(User), Type = new string[] { ExchangeService.ExchangeServiceType }, ExternalServiceId = identifier }); if (!services.Any()) { return( RedirectToAction("GetServices", "ExternalServices", new { statusMessage = "Error:Data could not be found" }), null); } data = services.First(); } return(null, data); }
public void ExchangeService_CanConstructClient() { var data = new ExchangeExternalServiceData() { PublicKey = "test", PairedDate = DateTime.Now }; var externalServiceData = new ExternalServiceData() { Type = ExchangeService.ExchangeServiceType, Name = "something" }; externalServiceData.Set(data); var exchangeService = new ExchangeService(externalServiceData); Assert.NotNull(exchangeService.ConstructClient()); }
public void Create_DataCorrect_GotCorrectId() { var serviceType = ServiceType.GitLab; var user = UserFaker.Create(); var randomId = Rand.RandomString(); var id = ExternalServiceData.Create(user, serviceType, randomId, user.login); Assert.True(id > 0); var data = ExternalServiceData.Find(id); Assert.NotNull(data); Assert.AreEqual(user.id, data.user_id); Assert.AreEqual(randomId, data.origin_id); Assert.AreEqual(user.login, data.login); Assert.AreEqual(serviceType, data.service_type); }
public virtual Task <IActionResult> EditData(ExternalServiceData externalServiceData) { using (var scope = DependencyHelper.ServiceScopeFactory.CreateScope()) { var identifier = externalServiceData.Id ?? $"new_{Guid.NewGuid()}"; if (string.IsNullOrEmpty(externalServiceData.Id)) { var memoryCache = scope.ServiceProvider.GetService <IMemoryCache>(); memoryCache.Set(identifier, externalServiceData, new MemoryCacheEntryOptions() { SlidingExpiration = TimeSpan.FromMinutes(60) }); } return(Task.FromResult <IActionResult>(new RedirectToActionResult("EditData", ControllerName, new { identifier }))); } }
public async Task <IActionResult> CreateExternalService(CreateExternalServiceViewModel model) { if (!ModelState.IsValid) { model.Types = new SelectList(_externalServiceDescriptors, nameof(IExternalServiceDescriptor.ExternalServiceType), nameof(IExternalServiceDescriptor.Name), model.Type); return(View(model)); } var externalService = new ExternalServiceData() { Name = model.Name, Type = model.Type, UserId = _userManager.GetUserId(User) }; var serviceDescriptor = _externalServiceDescriptors.Single(descriptor => descriptor.ExternalServiceType == externalService.Type); return(await serviceDescriptor.EditData(externalService)); }
BuildModel(EditDynamicServiceDataViewModel viewModel, ExternalServiceData mainModel) { if (string.IsNullOrEmpty(viewModel.RecipeActionId) && string.IsNullOrEmpty(viewModel.RecipeActionGroupId)) { ModelState.AddModelError(string.Empty, "please select a recipe action or a recipe action group "); } if (!ModelState.IsValid) { var recipes = await _recipeManager.GetRecipes(new RecipesQuery() { UserId = _userManager.GetUserId(User) }); var recipe = string.IsNullOrEmpty(viewModel.RecipeId) ? null : recipes.SingleOrDefault(recipe1 => recipe1.Id.Equals(viewModel.RecipeId, StringComparison.InvariantCultureIgnoreCase)); return(null, new EditDynamicServiceDataViewModel() { Value = viewModel.Value, RecipeId = viewModel.RecipeId, RecipeActionId = viewModel.RecipeActionId, RecipeActionGroupId = viewModel.RecipeActionGroupId, Recipes = new SelectList(recipes, nameof(Recipe.Id), nameof(Recipe.Name), viewModel.RecipeId), RecipeActions = recipe == null? null : new SelectList(recipe.RecipeActions, nameof(RecipeAction.Id), nameof(RecipeAction.ActionId), viewModel.RecipeActionId), RecipeActionGroups = recipe == null? null : new SelectList(recipe.RecipeActionGroups, nameof(RecipeActionGroup.Id), nameof(RecipeActionGroup.Id), viewModel.RecipeActionGroupId), }); } mainModel.Set(viewModel); return(mainModel, null); }
BuildModel(EditNBXplorerWalletExternalServiceDataViewModel viewModel, ExternalServiceData mainModel) { var failureViewModel = new EditNBXplorerWalletExternalServiceDataViewModel(viewModel); failureViewModel.CryptoCodes = new SelectList(_nbXplorerOptions.Cryptos?.ToList() ?? new List <string>(), viewModel.CryptoCode); if (viewModel.Action.Equals("add-private-key", StringComparison.InvariantCultureIgnoreCase)) { failureViewModel.PrivateKeys.Add(new PrivateKeyDetails()); return(null, failureViewModel); } if (viewModel.Action.StartsWith("remove-private-key", StringComparison.InvariantCultureIgnoreCase)) { var index = int.Parse(viewModel.Action.Substring(viewModel.Action.IndexOf(":") + 1)); failureViewModel.PrivateKeys.RemoveAt(index); return(null, failureViewModel); } if ((!string.IsNullOrEmpty(viewModel.DerivationStrategy) && !string.IsNullOrEmpty(viewModel.Address)) || string.IsNullOrEmpty(viewModel.DerivationStrategy) && string.IsNullOrEmpty(viewModel.Address)) { ModelState.AddModelError(string.Empty, "Please choose to track either an address OR a derivation scheme"); } var client = _nbXplorerClientProvider.GetClient(viewModel.CryptoCode); BitcoinAddress address = null; DerivationStrategyBase derivationStrategy = null; if (!string.IsNullOrEmpty(viewModel.Address) && !string.IsNullOrEmpty(viewModel.CryptoCode)) { try { var factory = client.Network.DerivationStrategyFactory; address = BitcoinAddress.Create(viewModel.Address, factory.Network); } catch (Exception) { ModelState.AddModelError(nameof(viewModel.Address), "Invalid Address"); } } if (!string.IsNullOrEmpty(viewModel.DerivationStrategy) && !string.IsNullOrEmpty(viewModel.CryptoCode)) { try { var factory = client.Network.DerivationStrategyFactory; derivationStrategy = _derivationSchemeParser.Parse(factory, viewModel.DerivationStrategy); } catch { ModelState.AddModelError(nameof(viewModel.DerivationStrategy), "Invalid Derivation Scheme"); } } //current External Service data var externalServiceData = mainModel; externalServiceData.Set(viewModel); if (!ModelState.IsValid) { return(null, failureViewModel); } if (derivationStrategy != null) { client.Track(TrackedSource.Create(derivationStrategy)); } if (address != null) { client.Track(TrackedSource.Create(address)); } return(externalServiceData, null); }
public ExchangeService(ExternalServiceData data) : base(data) { }
BuildModel(EditBtcPayServerDataViewModel viewModel, ExternalServiceData mainModel) { if (viewModel.Action == "unpair") { viewModel.Seed = null; } //current External Service data var oldData = mainModel.Get <BtcPayServerExternalServiceData>(); if (oldData.Seed == viewModel.Seed && oldData.Server == viewModel.Server) { viewModel.LastCheck = oldData.LastCheck; viewModel.MonitoredInvoiceStatuses = oldData.MonitoredInvoiceStatuses; viewModel.PairedDate = oldData.PairedDate; } else { viewModel.PairedDate = DateTime.Now; } mainModel.Set((BtcPayServerExternalServiceData)viewModel); var service = new BtcPayServerService(mainModel); if (!ModelState.IsValid) { var serviceData = service.GetData(); return(null, new EditBtcPayServerDataViewModel() { Seed = serviceData.Seed ?? new Mnemonic(Wordlist.English, WordCount.Twelve).ToString(), Server = serviceData.Server, PairingUrl = await service.GetPairingUrl(mainModel.Name), Paired = await service.CheckAccess() }); } if (!await service.CheckAccess()) { viewModel.Seed = viewModel.Seed ?? new Mnemonic(Wordlist.English, WordCount.Twelve).ToString(); service.SetData(viewModel); viewModel.PairingUrl = await service.GetPairingUrl(mainModel.Name); viewModel.Paired = false; if (!string.IsNullOrEmpty(viewModel.PairingCode)) { var client = service.ConstructClient(); await client.AuthorizeClient(new PairingCode(viewModel.PairingCode)); if (!await service.CheckAccess()) { ModelState.AddModelError(string.Empty, "Could not pair with pairing code"); return(null, viewModel); } } ModelState.AddModelError(string.Empty, "Cannot proceed until paired"); return(null, viewModel); } return(mainModel, null); }
private async Task <IActionResult> SetItUp(CreatePaymentForwarderViewModel vm) { var client = _nbXplorerClientProvider.GetClient(vm.CryptoCode); var presetName = $"Generated_PaymentForwarder_{vm.CryptoCode}"; var sourceExternalServiceId = vm.SelectedSourceWalletExternalServiceId; if (vm.GenerateSourceWallet) { var genResponse = await client.GenerateWalletAsync(new GenerateWalletRequest() { ScriptPubKeyType = client.Network.NBitcoinNetwork.Consensus.SupportSegwit ? ScriptPubKeyType.SegwitP2SH : ScriptPubKeyType.Legacy, }); var data = new NBXplorerWalletExternalServiceData() { CryptoCode = vm.CryptoCode, DerivationStrategy = genResponse.DerivationScheme.ToString(), PrivateKeys = new List <PrivateKeyDetails>() { new PrivateKeyDetails() { MnemonicSeed = genResponse.Mnemonic } } }; var sourceWallet = new ExternalServiceData() { Name = presetName + "_Source_Wallet", UserId = _userManager.GetUserId(User), Type = NBXplorerWalletService.NBXplorerWalletServiceType, DataJson = client.Serializer.ToString(data) }; await _externalServiceManager.AddOrUpdateExternalServiceData(sourceWallet); sourceExternalServiceId = sourceWallet.Id; } var recipe = new Recipe() { Name = presetName, Description = "Generated from a preset", UserId = _userManager.GetUserId(User), Enabled = false }; await _recipeManager.AddOrUpdateRecipe(recipe); var recipeTrigger = new RecipeTrigger() { ExternalServiceId = sourceExternalServiceId, TriggerId = NBXplorerBalanceTrigger.Id, RecipeId = recipe.Id, DataJson = client.Serializer.ToString(new NBXplorerBalanceTriggerParameters() { BalanceValue = vm.SendEntireBalance ? 0 : vm.SendBalanceValue, BalanceComparer = vm.SendEntireBalance ? BalanceComparer.GreaterThan : BalanceComparer.GreaterThanOrEqual, BalanceMoneyUnit = vm.SendBalanceMoneyUnit }) }; await _recipeManager.AddOrUpdateRecipeTrigger(recipeTrigger); var recipeActionGroup = new RecipeActionGroup() { RecipeId = recipe.Id }; await _recipeManager.AddRecipeActionGroup(recipeActionGroup); var recipeActionGroupIndex = 0; var ouputs = new List <SendTransactionData.TransactionOutput>(); foreach (var paymentDestination in vm.PaymentDestinations) { var destinationExternalServiceId = paymentDestination.SelectedDestinationWalletExternalServiceId; NBXplorerWalletExternalServiceData data = null; if (string.IsNullOrEmpty(destinationExternalServiceId)) { data = new NBXplorerWalletExternalServiceData() { CryptoCode = vm.CryptoCode, Address = paymentDestination.DestinationAddress, DerivationStrategy = paymentDestination.DerivationStrategy, }; var wallet = new ExternalServiceData() { Name = presetName + $"_Dest_Wallet_{data.DerivationStrategy}", UserId = _userManager.GetUserId(User), Type = NBXplorerWalletService.NBXplorerWalletServiceType, DataJson = client.Serializer.ToString(data) }; await _externalServiceManager.AddOrUpdateExternalServiceData(wallet); destinationExternalServiceId = wallet.Id; } else { var service = vm.Services.Items.Cast <ExternalServiceData>() .Single(serviceData => serviceData.Id == destinationExternalServiceId); data = new NBXplorerWalletService(service, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _nbXplorerClientProvider).GetData(); } var recipeAction = new RecipeAction() { RecipeId = recipe.Id, RecipeActionGroupId = recipeActionGroup.Id, ActionId = new GenerateNextAddressDataActionHandler().ActionId, ExternalServiceId = destinationExternalServiceId, Order = recipeActionGroupIndex, DataJson = JsonConvert.SerializeObject(new GenerateNextAddressData()) }; await _recipeManager.AddOrUpdateRecipeAction(recipeAction); var noDecimalParse = paymentDestination.AmountPercentage / 100; ouputs.Add(new SendTransactionData.TransactionOutput() { DestinationAddress = "{{ActionData" + recipeActionGroupIndex + "}}", Amount = "{{TriggerData.Balance.ToDecimal(MoneyUnit.BTC) * " + noDecimalParse + "}}", SubtractFeesFromOutput = paymentDestination.SubtractFeesFromOutput }); recipeActionGroupIndex++; } var sweepRecipeAction = new RecipeAction() { RecipeId = recipe.Id, RecipeActionGroupId = recipeActionGroup.Id, ActionId = new SendTransactionDataActionHandler().ActionId, ExternalServiceId = sourceExternalServiceId, Order = recipeActionGroupIndex, DataJson = JsonConvert.SerializeObject(new SendTransactionData() { Outputs = ouputs }) }; await _recipeManager.AddOrUpdateRecipeAction(sweepRecipeAction); return(RedirectToAction("EditRecipe", "Recipes", new { id = recipe.Id, statusMessage = "Preset generated. Recipe is currently disabled for now. Please verify details are correct before enabling!" })); }
protected override Task <SmtpExternalServiceData> BuildViewModel(ExternalServiceData data) { return(Task.FromResult(new SmtpService(data).GetData())); }
protected override async Task <EditExchangeExternalServiceDataViewModel> BuildViewModel(ExternalServiceData data) { return(new EditExchangeExternalServiceDataViewModel(new ExchangeService(data).GetData(), await ExchangeService.GetAvailableExchanges())); }
public SmtpService(ExternalServiceData data) : base(data) { }
public Pop3Service(ExternalServiceData data) : base(data) { }
public BtcPayServerService(ExternalServiceData data) : base(data) { }