public IActionResult GetSpvWalletInfo(string service, string nodePubKey = null, int node_count = 1) { ConnectedNodeResponse serviceNode; List <ConnectedNodeResponse> otherNodes; var connectResponse = xrouterService.xrConnect(service, node_count); var configReply = xrouterService.xrShowConfigs(); var connectReply = connectResponse.Reply; if (string.IsNullOrWhiteSpace(nodePubKey)) { serviceNode = connectReply.OrderByDescending(n => n.Score).FirstOrDefault(); // split node list otherNodes = connectReply.Where(s => s.NodePubKey != serviceNode.NodePubKey).ToList(); } else { serviceNode = connectReply.Find(s => s.NodePubKey == nodePubKey); otherNodes = connectReply.Where(s => s.NodePubKey != nodePubKey).ToList(); } if (serviceNode == null) { return(StatusCode(StatusCodes.Status500InternalServerError, "Service node not reachable with xrConnect")); } var serviceNodeConfig = configReply.Find(c => c.NodePubKey == serviceNode.NodePubKey); var serviceNodeConfigElements = serviceNodeConfig.Config.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries) .Select(value => value.Split('=')); string serviceNodeHost = null; if (serviceNodeConfigElements.Any(lc => lc[0] == "host")) { serviceNodeHost = serviceNodeConfigElements.FirstOrDefault(e => e[0] == "host")[1]; } string serviceNodePort = null; if (serviceNodeConfigElements.Any(lc => lc[0] == "port")) { serviceNodePort = serviceNodeConfigElements.FirstOrDefault(e => e[0] == "port")[1]; } var serviceName = service.Replace("xr::", ""); var spvConfig = serviceNode.SpvConfigs.Find(c => c.SpvWallet == serviceName); //TODO: Add AutoMapper to replace var viewModel = new SpvWalletResultViewModel { SpvConfig = new SpvConfigViewModel { SpvWallet = spvConfig.SpvWallet, Commands = spvConfig.Commands.Where(c => c.Command != "xrGetConfig").Select(c => new SpvCommandViewModel { Command = c.Command, Disabled = c.Disabled, Fee = c.Fee, PaymentAddress = c.PaymentAddress, RequestLimit = c.RequestLimit, FetchLimit = c.FetchLimit }).ToList() }, Node = new NodeInfoViewModel { Type = (serviceNodePort == "41412" || string.IsNullOrEmpty(serviceNodePort)) ? "Regular" : "Enterprise", Host = serviceNodeHost, Port = serviceNodePort, Banned = serviceNode.Banned, NodePubKey = serviceNode.NodePubKey, PaymentAddress = serviceNode.PaymentAddress, Score = serviceNode.Score }, OtherNodes = otherNodes.Select(n => { var cfg = configReply.Find(c => c.NodePubKey == n.NodePubKey); var cfgElements = new List <string[]>(); if (cfg != null) { cfgElements = cfg.Config.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries) .Select(value => value.Split('=')).ToList(); } string port = null; if (cfgElements.Any(lc => lc[0] == "port")) { port = cfgElements.FirstOrDefault(e => e[0] == "port")[1]; } return(new NodeInfoViewModel { Type = (port == "41412" || string.IsNullOrEmpty(port)) ? "Regular" : "Enterprise", Banned = n.Banned, NodePubKey = n.NodePubKey, PaymentAddress = n.PaymentAddress, Score = n.Score }); }).ToList() }; return(Ok(viewModel)); }
public IActionResult GetSpvWalletInfo(string service, string nodePubKey = null, int node_count = 1) { ConnectedNodeResponse serviceNode; List <ConnectedNodeResponse> otherNodes; var connectReply = this._blocknetService.xrConnect(service, node_count).Reply; var configReply = this._blocknetService.xrShowConfigs(); if (connectReply == null || configReply == null) { return(BadRequest()); } if (string.IsNullOrWhiteSpace(nodePubKey)) { // Randomly choose a service node from the list if no nodePubKey is given var r = new Random(); var index = r.Next(connectReply.Count); serviceNode = connectReply[index]; // split node list //otherNodes = connectReply.Skip(index + 1).ToList(); otherNodes = connectReply.Where(s => s.NodePubKey != nodePubKey).ToList(); } else { serviceNode = connectReply.Find(s => s.NodePubKey == nodePubKey); //otherNodes = connectReply.Skip(connectReply.IndexOf(serviceNode)+1).ToList(); otherNodes = connectReply.Where(s => s.NodePubKey != nodePubKey).ToList(); } var serviceNodeConfig = configReply.Find(c => c.NodePubKey == serviceNode.NodePubKey); var serviceName = service.Replace("xr::", ""); var spvConfig = serviceNode.SpvConfigs.Find(c => c.SpvWallet == serviceName); //TODO: Add AutoMapper to replace this. var viewModel = new SpvWalletResultViewModel { SpvConfig = new SpvConfigViewModel { SpvWallet = spvConfig.SpvWallet, Commands = spvConfig.Commands.Select(c => new SpvCommandViewModel { Command = c.Command, Disabled = c.Disabled, Fee = c.Fee, PaymentAddress = c.PaymentAddress, RequestLimit = c.RequestLimit }).ToList() }, Node = new NodeInfoViewModel { Banned = serviceNode.Banned, NodePubKey = serviceNode.NodePubKey, PaymentAddress = serviceNode.PaymentAddress, Score = serviceNode.Score }, OtherNodes = otherNodes.Select(n => new NodeInfoViewModel { Banned = n.Banned, NodePubKey = n.NodePubKey, PaymentAddress = n.PaymentAddress, Score = n.Score }).ToList() }; return(Ok(viewModel)); }