public static async Task <string> GetDonateAddressAsync() { var address = await BitSendCli.RunAsync("getaccountaddress donate"); return(address.Trim()); }
public static async void StartMonitoring() { while (true) { try { //full var fullResult = await BitSendCli.RunAsync("masternodelist full"); var fullReader = new JsonTextReader(new StringReader(fullResult)); //rank var rankResult = await BitSendCli.RunAsync("masternodelist rank"); var rankReader = new JsonTextReader(new StringReader(rankResult)); var ranks = new List <(string address, int rank)>(); var vinIndexes = new Dictionary <string, int>(); var addressIndexes = new Dictionary <string, int>(); var nodeIds = new HashSet <string>(); while (rankReader.Read()) { if (rankReader.TokenType == JsonToken.PropertyName) { var address = (string)rankReader.Value; var rank = rankReader.ReadAsInt32() ?? 0; ranks.Add((address, rank)); } } while (fullReader.Read()) { if (fullReader.TokenType == JsonToken.PropertyName) { var vin = ((string)fullReader.Value).Trim(); if (vinIndexes.TryGetValue(vin, out var vinIndex)) { vinIndex++; } var nodeId = $"{vin}-{vinIndex}"; nodeIds.Add(nodeId); if (!All.TryGetValue(nodeId, out var masternode)) { masternode = new Masternode { NodeId = nodeId, Vin = vin, VinIndex = vinIndex }; } var info = fullReader.ReadAsString(); var values = info.Split(' ', StringSplitOptions.RemoveEmptyEntries); masternode.Status = values[0]; masternode.Protocol = int.Parse(values[1]); masternode.PubKey = values[2]; var address = values[3]; masternode.Address = address; var portIndex = address.LastIndexOf(':'); if (portIndex > -1) { masternode.IP = address.Substring(0, portIndex); masternode.Port = int.Parse(address.Substring(portIndex + 1)); } var lastSeenSeconds = int.Parse(values[4]); masternode.LastSeen = Unix.GetTimestampFromSeconds(lastSeenSeconds); masternode.ActiveSeconds = int.Parse(values[5]); var activeDuration = TimeSpan.FromSeconds(masternode.ActiveSeconds); masternode.ActiveDuration = $"{activeDuration:%d} days {activeDuration:hh} hours {activeDuration:mm} minutes {activeDuration:ss} seconds"; vinIndexes[masternode.Vin] = vinIndex; masternode.VinIndex = vinIndex; if (addressIndexes.TryGetValue(masternode.Address, out var addressIndex)) { addressIndex++; } addressIndexes[masternode.Address] = addressIndex; var addressRanks = ranks.Where(r => r.address == masternode.Address).ToList(); if (addressRanks.Count > addressIndex) { masternode.Rank = addressRanks[addressIndex].rank; } masternode.LastRefresh = DateTime.UtcNow; All[masternode.NodeId] = masternode; } } var missingIds = All.Keys.Where(k => !nodeIds.Contains(k)).ToList(); foreach (var missingId in missingIds) { All.TryRemove(missingId, out var _); } } catch (Exception e) { Console.WriteLine(e); } if (!IsTestingConnections) { StartTestingConnections(); } if (!IsRetreivingLocations) { StartRetreivingLocations(); } await Task.Delay(TimeSpan.FromMinutes(2)); } }