protected override async Task <TypedActionHandlerResult <LightningNodeInformation> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, GetLightningNodeInfoData actionData) { using (var serviceScope = DependencyHelper.ServiceScopeFactory.CreateScope()) { var externalService = await recipeAction.GetExternalService(); var service = new LightningNodeService(externalService, serviceScope.ServiceProvider.GetService <NBXplorerClientProvider>(), serviceScope.ServiceProvider.GetService <NBXplorerSummaryProvider>(), serviceScope.ServiceProvider.GetService <SocketFactory>() ); var client = service.ConstructClient(); var result = await client.GetInfo(); return(new TypedActionHandlerResult <LightningNodeInformation>() { Executed = true, Result = $"Got lightning node info block height:{result.BlockHeight}, node: {result.NodeInfoList.First()}", TypedData = result }); } }
protected override async Task <TypedActionHandlerResult <PayResponse> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, PayBolt11InvoiceData actionData) { using (var serviceScope = DependencyHelper.ServiceScopeFactory.CreateScope()) { var externalService = await recipeAction.GetExternalService(); var service = new LightningNodeService(externalService, serviceScope.ServiceProvider.GetService <NBXplorerClientProvider>(), serviceScope.ServiceProvider.GetService <NBXplorerSummaryProvider>(), serviceScope.ServiceProvider.GetService <SocketFactory>() ); var client = service.ConstructClient(); var response = await client.Pay(InterpolateString(actionData.Bolt11, data)); return(new TypedActionHandlerResult <PayResponse>() { Executed = response.Result == PayResult.Ok, Result = $"Paying Bolt11 Invoice: {Enum.GetName(typeof(PayResult), response.Result)}", TypedData = response }); } }
protected override async Task <TypedActionHandlerResult <BitcoinAddress> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, GetOnChainLightningDepositAddressData actionData) { using (var serviceScope = DependencyHelper.ServiceScopeFactory.CreateScope()) { var externalService = await recipeAction.GetExternalService(); var service = new LightningNodeService(externalService, serviceScope.ServiceProvider.GetService <NBXplorerClientProvider>(), serviceScope.ServiceProvider.GetService <NBXplorerSummaryProvider>(), serviceScope.ServiceProvider.GetService <SocketFactory>() ); var client = service.ConstructClient(); var result = await client.GetDepositAddress(); return(new TypedActionHandlerResult <BitcoinAddress>() { Executed = true, Result = $"Got deposit address {result}", TypedData = result }); } }
protected override async Task <TypedActionHandlerResult <PSBT> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, NBXplorerCreatePSBTData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _derivationStrategyFactoryProvider, _nbXplorerClientProvider); var wallet = await walletService.ConstructClient(); var walletData = walletService.GetData(); var explorerClient = _nbXplorerClientProvider.GetClient(walletData.CryptoCode); var tx = await wallet.BuildTransaction(actionData.Outputs.Select(output => (Money.Parse(InterpolateString(output.Amount, data)), (IDestination)BitcoinAddress.Create(InterpolateString(output.DestinationAddress, data), explorerClient.Network.NBitcoinNetwork), output.SubtractFeesFromOutput)), walletData.PrivateKeys); var psbt = PSBT.FromTransaction(tx); return(new NBXplorerActionHandlerResult <PSBT>( _nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = true, TypedData = psbt, Result = $"PSBT created {psbt}" }); }
public SP35UnlockRecipes(MinecraftClient client, RecipeAction action, bool craftingRecipeBookOpen, bool craftingRecipeBookFilterActive, bool smeltingRecipeBookOpen, bool smeltingRecipeBookFilterActive, bool blastFurnaceRecipeBookOpen, bool blastFurnaceRecipeBookFilterActive, bool smokerRecipeBookOpen, bool smokerRecipeBookFilterActive, Identifier[] recipeIds, Identifier[] recipeIdsInit = null) : base(client) { Action = (RecipeAction)Data.WriteVarInt((int)action); CraftingRecipeBookOpen = Data.WriteBoolean(craftingRecipeBookOpen); CraftingRecipeBookFilterActive = Data.WriteBoolean(craftingRecipeBookFilterActive); SmeltingRecipeBookOpen = Data.WriteBoolean(smeltingRecipeBookOpen); SmeltingRecipeBookFilterActive = Data.WriteBoolean(smeltingRecipeBookFilterActive); BlastFurnaceRecipeBookOpen = Data.WriteBoolean(blastFurnaceRecipeBookOpen); BlastFurnaceRecipeBookFilterActive = Data.WriteBoolean(blastFurnaceRecipeBookFilterActive); SmokerRecipeBookOpen = Data.WriteBoolean(smokerRecipeBookOpen); SmokerRecipeBookFilterActive = Data.WriteBoolean(smokerRecipeBookFilterActive); Data.WriteVarInt(recipeIds.Length); RecipeIds = Data.WriteArray <Identifier, DataTypes.Identifier>(recipeIds); if (action == RecipeAction.Init) { if (recipeIdsInit != null) { Data.WriteVarInt(recipeIdsInit.Length); RecipeIdsInit = Data.WriteArray <Identifier, DataTypes.Identifier>(recipeIdsInit); } else { throw new System.ArgumentNullException(nameof(recipeIdsInit), "recipeIdsInit should be provided when action is init!"); } } }
public async Task Dispatch(object triggerData, RecipeAction recipeAction) { foreach (var actionHandler in _handlers) { try { var result = await actionHandler.Execute(triggerData, recipeAction); if (result.Executed) { await _recipeManager.AddRecipeInvocation(new RecipeInvocation() { RecipeId = recipeAction.RecipeId, Timestamp = DateTime.Now, RecipeActionId = recipeAction.Id, ActionResult = result.Result, TriggerDataJson = JObject.FromObject(triggerData).ToString() }); } } catch (Exception e) { await _recipeManager.AddRecipeInvocation(new RecipeInvocation() { RecipeId = recipeAction.RecipeId, Timestamp = DateTime.Now, RecipeActionId = recipeAction.Id, ActionResult = e.Message, TriggerDataJson = JObject.FromObject(triggerData).ToString() }); } } }
protected override async Task <PlaceOrderViewModel> BuildViewModel(RecipeAction from) { var services = await _externalServiceManager.GetExternalServicesData(new ExternalServicesDataQuery() { Type = new[] { ExchangeService.ExchangeServiceType }, UserId = GetUserId() }); var fromData = from.Get <PlaceOrderData>(); return(new PlaceOrderViewModel { RecipeId = @from.RecipeId, ExternalServiceId = @from.ExternalServiceId, Price = fromData.Price, Amount = fromData.Amount, IsBuy = fromData.IsBuy, IsMargin = fromData.IsMargin, OrderType = fromData.OrderType, StopPrice = fromData.StopPrice, MarketSymbol = fromData.MarketSymbol, ExternalServices = new SelectList(services, nameof(ExternalServiceData.Id), nameof(ExternalServiceData.Name), @from.ExternalServiceId) }); }
public async Task <IActionResult> EditRecipeAction(string id, string recipeActionId, string statusMessage, string recipeActionGroupId) { var recipe = await _recipeManager.GetRecipe(id, _userManager.GetUserId(User)); if (recipe == null) { return(GetNotFoundActionResult()); } RecipeAction recipeAction = null; if (!string.IsNullOrEmpty(recipeActionId)) { recipeAction = recipe.RecipeActions.SingleOrDefault(action => action.Id == recipeActionId); if (recipeAction == null) { return(GetNotFoundActionResult()); } } return(View(new EditRecipeActionViewModel() { RecipeId = id, ActionId = recipeAction?.ActionId, RecipeActionGroupId = recipeActionGroupId, RecipeAction = recipeAction, StatusMessage = statusMessage, Actions = new SelectList(_actionDescriptors, nameof(IActionDescriptor.ActionId), nameof(IActionDescriptor.Name), recipeAction?.ActionId) })); }
public async Task <IActionResult> RemoveRecipeActionPost(string id, string recipeActionId) { var recipe = await _recipeManager.GetRecipe(id, _userManager.GetUserId(User)); if (recipe == null) { return(GetNotFoundActionResult()); } RecipeAction recipeAction = null; if (!string.IsNullOrEmpty(recipeActionId)) { recipeAction = recipe.RecipeActions.SingleOrDefault(action => action.Id == recipeActionId); if (recipeAction == null) { return(GetNotFoundActionResult()); } } await _recipeManager.RemoveRecipeAction(recipeActionId); return(RedirectToAction("EditRecipe", "Recipes", new { id, statusMessage = new StatusMessageModel() { Message = $"Recipe Action removed", Severity = StatusMessageModel.StatusSeverity.Success }.ToString() })); }
protected override async Task <TypedActionHandlerResult <LightningChannel[]> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, GetLightningChannelsData actionData) { using (var serviceScope = DependencyHelper.ServiceScopeFactory.CreateScope()) { var externalService = await recipeAction.GetExternalService(); var service = new LightningNodeService(externalService, serviceScope.ServiceProvider.GetService <NBXplorerClientProvider>(), serviceScope.ServiceProvider.GetService <NBXplorerSummaryProvider>(), serviceScope.ServiceProvider.GetService <SocketFactory>() ); var client = service.ConstructClient(); var result = await client.ListChannels(); return(new TypedActionHandlerResult <LightningChannel[]>() { Executed = true, Result = $"Found {result.Length} channels", TypedData = result }); } }
public async Task <IActionResult> RemoveRecipeAction(string id, string recipeActionId) { var recipe = await _recipeManager.GetRecipe(id, _userManager.GetUserId(User)); if (recipe == null) { return(GetNotFoundActionResult()); } RecipeAction recipeAction = null; if (!string.IsNullOrEmpty(recipeActionId)) { recipeAction = recipe.RecipeActions.SingleOrDefault(action => action.Id == recipeActionId); if (recipeAction == null) { return(GetNotFoundActionResult()); } } return(View(new RemoveRecipeActionViewModel() { RecipeAction = recipeAction })); }
protected override async Task <TypedActionHandlerResult <BroadcastResult> > Execute( Dictionary <string, object> data, RecipeAction recipeAction, SendTransactionData actionData) { var externalService = await recipeAction.GetExternalService(); var walletService = new NBXplorerWalletService(externalService, _nbXplorerPublicWalletProvider, _derivationSchemeParser, _derivationStrategyFactoryProvider, _nbXplorerClientProvider); var wallet = await walletService.ConstructClient(); var walletData = walletService.GetData(); var explorerClient = _nbXplorerClientProvider.GetClient(walletData.CryptoCode); var tx = await wallet.BuildTransaction(actionData.Outputs.Select(output => (Money.Parse(InterpolateString(output.Amount, data)), (IDestination)BitcoinAddress.Create(InterpolateString(output.DestinationAddress, data), explorerClient.Network.NBitcoinNetwork), output.SubtractFeesFromOutput)), walletData.PrivateKeys, actionData.FeeSatoshiPerByte != null ?new FeeRate(Money.Satoshis(actionData.FeeSatoshiPerByte.Value), 1) : null, actionData.Fee.HasValue?new Money(actionData.Fee.Value, MoneyUnit.BTC) : null); var result = await wallet.BroadcastTransaction(tx); return(new NBXplorerActionHandlerResult <BroadcastResult>( _nbXplorerClientProvider.GetClient(walletData.CryptoCode)) { Executed = result.Success, TypedData = result, Result = $"Tx broadcasted, {(result.Success ? "Successful" : "Unsuccessful")}, {result.RPCMessage}, {tx}" }); }
protected override async Task <(RecipeAction ToSave, GetExchangeRateViewModel showViewModel)> BuildModel( GetExchangeRateViewModel viewModel, RecipeAction mainModel) { if (ModelState.IsValid) { var serviceData = await _externalServiceManager.GetExternalServiceData(viewModel.ExternalServiceId, GetUserId()); var exchangeService = new ExchangeService(serviceData); var symbols = (await(await exchangeService.ConstructClient()).GetMarketSymbolsAsync()).ToArray(); if (symbols.Contains(viewModel.MarketSymbol)) { mainModel.ExternalServiceId = viewModel.ExternalServiceId; mainModel.Set <GetExchangeRateData>(viewModel); return(mainModel, null); } ModelState.AddModelError(nameof(GetExchangeRateViewModel.MarketSymbol), $"The market symbols you entered is invalid. Please choose from the following: {string.Join(",", symbols)}"); } var services = await _externalServiceManager.GetExternalServicesData(new ExternalServicesDataQuery() { Type = new[] { ExchangeService.ExchangeServiceType }, UserId = GetUserId() }); viewModel.ExternalServices = new SelectList(services, nameof(ExternalServiceData.Id), nameof(ExternalServiceData.Name), viewModel.ExternalServiceId); return(null, viewModel); }
private async Task <IActionResult> SetItUp(CreateDCAViewModel vm) { var presetName = $"Generated_DCA"; 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() { TriggerId = new TimerTrigger().Id, RecipeId = recipe.Id }; recipeTrigger.Set(new TimerTriggerParameters() { StartOn = vm.StartOn, TriggerEvery = vm.TriggerEvery, TriggerEveryAmount = vm.TriggerEveryAmount }); await _recipeManager.AddOrUpdateRecipeTrigger(recipeTrigger); var recipeActionGroup = new RecipeActionGroup() { RecipeId = recipe.Id }; await _recipeManager.AddRecipeActionGroup(recipeActionGroup); var tradeAction = new RecipeAction() { RecipeId = recipe.Id, RecipeActionGroupId = recipeActionGroup.Id, ActionId = new PlaceOrderDataActionHandler().ActionId, ExternalServiceId = vm.SelectedExchangeServiceId, Order = 0, DataJson = JsonConvert.SerializeObject(new PlaceOrderData() { Amount = vm.FiatAmount.ToString(CultureInfo.InvariantCulture), IsBuy = vm.IsBuy, MarketSymbol = vm.MarketSymbol, OrderType = OrderType.Market }) }; await _recipeManager.AddOrUpdateRecipeAction(tradeAction); return(RedirectToAction("EditRecipe", "Recipes", new { id = recipe.Id, statusMessage = "Preset generated. Recipe is currently disabled for now. Please verify details are correct before enabling!" })); }
public async Task MakeWebRequestActionHandler_Execute_SendHttpRequest() { var handler = new Mock <HttpMessageHandler>(); var factory = handler.CreateClientFactory(); Mock.Get(factory).Setup(x => x.CreateClient(It.IsAny <string>())) .Returns(() => handler.CreateClient()); var actionHandler = new MakeWebRequestActionHandler(factory); var recipeAction = new RecipeAction() { ActionId = actionHandler.ActionId }; recipeAction.Set(new MakeWebRequestData() { ContentType = "application/json", Url = "http://gozo.com", Body = "{}", Method = "POST" }); await actionHandler.Execute(new Dictionary <string, object>(), recipeAction); handler.VerifyRequest(HttpMethod.Post, "http://gozo.com", Times.Once()); }
protected override async Task <(RecipeAction ToSave, SendTransactionViewModel showViewModel)> BuildModel( SendTransactionViewModel viewModel, RecipeAction mainModel) { var services = await _externalServiceManager.GetExternalServicesData(new ExternalServicesDataQuery() { Type = new[] { NBXplorerWalletService.NBXplorerWalletServiceType }, UserId = GetUserId() }); viewModel.ExternalServices = new SelectList(services, nameof(ExternalServiceData.Id), nameof(ExternalServiceData.Name), viewModel.ExternalServiceId); if (viewModel.Action.Equals("add-output", StringComparison.InvariantCultureIgnoreCase)) { viewModel.Outputs.Add(new SendTransactionData.TransactionOutput()); return(null, viewModel); } if (viewModel.Action.StartsWith("remove-output", StringComparison.InvariantCultureIgnoreCase)) { var index = int.Parse(viewModel.Action.Substring(viewModel.Action.IndexOf(":") + 1)); viewModel.Outputs.RemoveAt(index); return(null, viewModel); } if (!viewModel.Outputs.Any()) { ModelState.AddModelError(string.Empty, "Please add at least one transaction output"); } else { var subtractFeesOutputs = viewModel.Outputs.Select((output, i) => (output, i)) .Where(tuple => tuple.Item1.SubtractFeesFromOutput); if (subtractFeesOutputs.Count() > 1) { foreach (var subtractFeesOutput in subtractFeesOutputs) { viewModel.AddModelError(model => model.Outputs[subtractFeesOutput.Item2].SubtractFeesFromOutput, "You can only subtract fees from one output", ModelState); } } } if (ModelState.IsValid) { mainModel.ExternalServiceId = viewModel.ExternalServiceId; mainModel.Set <SendTransactionData>(viewModel); return(mainModel, null); } return(null, viewModel); }
public Task <IViewComponentResult> InvokeAsync(RecipeAction recipeAction) { return(Task.FromResult <IViewComponentResult>(View(new ViewRecipeActionViewModel() { RecipeAction = recipeAction, ExternalServiceData = recipeAction.ExternalService, ActionDescriptor = _actionDescriptors.SingleOrDefault(descriptor => descriptor.ActionId == recipeAction.ActionId) }))); }
protected override Task <ChooseNumericValueViewModel> BuildViewModel(RecipeAction from) { var fromData = from.Get <ChooseNumericValueData>(); return(Task.FromResult(new ChooseNumericValueViewModel { RecipeId = @from.RecipeId, Items = fromData.Items })); }
protected override async Task <ConditionViewModel> BuildViewModel(RecipeAction from) { var fromData = from.Get <ConditionData>(); return(new ConditionViewModel { RecipeId = @from.RecipeId, Condition = fromData.Condition }); }
protected override async Task <(RecipeAction ToSave, ConditionViewModel showViewModel)> BuildModel( ConditionViewModel viewModel, RecipeAction mainModel) { if (ModelState.IsValid) { mainModel.Set <ConditionData>(viewModel); return(mainModel, null); } return(null, viewModel); }
protected override Task <(RecipeAction ToSave, MakeWebRequestViewModel showViewModel)> BuildModel( MakeWebRequestViewModel viewModel, RecipeAction mainModel) { if (ModelState.IsValid) { mainModel.Set <MakeWebRequestData>(viewModel); return(Task.FromResult <(RecipeAction ToSave, MakeWebRequestViewModel showViewModel)>((mainModel, null))); } return(Task.FromResult <(RecipeAction ToSave, MakeWebRequestViewModel showViewModel)>((null, viewModel))); }
private void SetValues(RecipeAction from, SendEmailViewModel to) { to.RecipeId = from.RecipeId; to.ExternalServiceId = from.ExternalServiceId; var fromData = from.Get <SendEmailData>(); to.Body = fromData.Body; to.Subject = fromData.Subject; to.To = fromData.To; to.From = fromData.From; }
private async Task SetValues(RecipeAction from, CreateRecipeViewModel to) { var data = from.Get <CreateRecipeData>(); to.Recipes = new SelectList(await _recipeManager.GetRecipes(new RecipesQuery() { UserId = _userManager.GetUserId(User) }), nameof(BtcTransmuter.Data.Entities.Recipe.Id), nameof(BtcTransmuter.Data.Entities.Recipe.Name), data.RecipeTemplateId); to.RecipeTemplateId = data.RecipeTemplateId; to.Enable = data.Enable; to.RecipeId = from.RecipeId; }
public async Task <ActionHandlerResult> Execute(object triggerData, RecipeAction recipeAction) { if (await CanExecute(triggerData, recipeAction)) { return(await Execute(triggerData, recipeAction, recipeAction.Get <TActionData>())); } return(new ActionHandlerResult() { Executed = false }); }
protected override Task <MakeWebRequestViewModel> BuildViewModel(RecipeAction recipeAction) { var data = recipeAction.Get <MakeWebRequestData>(); return(Task.FromResult(new MakeWebRequestViewModel { Url = data.Url, Body = data.Body, Method = data.Method, ContentType = data.ContentType, RecipeId = recipeAction.RecipeId })); }
private void SetValues(RecipeAction from, PlaceOrderViewModel to) { to.RecipeId = from.RecipeId; to.ExternalServiceId = from.ExternalServiceId; var fromData = from.Get <PlaceOrderData>(); to.Price = fromData.Price; to.Amount = fromData.Amount; to.IsBuy = fromData.IsBuy; to.IsMargin = fromData.IsMargin; to.OrderType = fromData.OrderType; to.StopPrice = fromData.StopPrice; to.MarketSymbol = fromData.MarketSymbol; }
protected override async Task <NBXplorerGetBalanceViewModel> BuildViewModel(RecipeAction from) { var services = await _externalServiceManager.GetExternalServicesData(new ExternalServicesDataQuery() { Type = new[] { NBXplorerWalletService.NBXplorerWalletServiceType }, UserId = GetUserId() }); return(new NBXplorerGetBalanceViewModel { RecipeId = from.RecipeId, ExternalServiceId = from.ExternalServiceId, ExternalServices = new SelectList(services, nameof(ExternalServiceData.Id), nameof(ExternalServiceData.Name), from.ExternalServiceId) }); }
protected override async Task <ToggleRecipeViewModel> BuildViewModel(RecipeAction from) { var data = from.Get <ToggleRecipeData>(); return(new ToggleRecipeViewModel { RecipeId = from.RecipeId, Recipes = new SelectList( await _recipeManager.GetRecipes(new RecipesQuery() { UserId = _userManager.GetUserId(User) }), nameof(BtcTransmuter.Data.Entities.Recipe.Id), nameof(BtcTransmuter.Data.Entities.Recipe.Name), data.TargetRecipeId), TargetRecipeId = data.TargetRecipeId }); }
protected override async Task <GetLightningNodeInfoViewModel> BuildViewModel(RecipeAction from) { var fromData = from.Get <GetLightningNodeInfoData>(); var services = await _externalServiceManager.GetExternalServicesData(new ExternalServicesDataQuery() { Type = new[] { LightningNodeService.LightningNodeServiceType }, UserId = GetUserId() }); return(new GetLightningNodeInfoViewModel { RecipeId = from.RecipeId, ExternalServiceId = from.ExternalServiceId, ExternalServices = new SelectList(services, nameof(ExternalServiceData.Id), nameof(ExternalServiceData.Name), from.ExternalServiceId), }); }
protected override async Task <(RecipeAction ToSave, CreateRecipeViewModel showViewModel)> BuildModel( CreateRecipeViewModel viewModel, RecipeAction mainModel) { if (ModelState.IsValid) { mainModel.Set <CreateRecipeData>(viewModel); return(mainModel, null); } viewModel.Recipes = new SelectList( await _recipeManager.GetRecipes(new RecipesQuery() { UserId = _userManager.GetUserId(User) }), nameof(BtcTransmuter.Data.Entities.Recipe.Id), nameof(BtcTransmuter.Data.Entities.Recipe.Name), viewModel.RecipeTemplateId); return(null, viewModel); }