Ejemplo n.º 1
0
        internal async void TestNodes()
        {
            while (true)
            {
                bot = new TelegramBot(accessToken: ConfigurationManager.AppSettings[name: "accessKey"]);

                var nodes = NodeUtils.GetAllNodes();

                foreach (var n in nodes)
                {
                    Thread.Sleep(500);

                    try
                    {
                        var con = new Connection();

                        con.SetHost(n.IP);

                        con.AutoHost = false;

                        var client = new NodeClient(con);

                        var info = client.EndGetExtendedNodeInfo(client.BeginGetExtendedNodeInfo());

                        if (n.WentOffLine != null)
                        {
                            var nis = new NisClient(con);

                            if (nis.EndGetStatus(nis.BeginGetStatus()).Code != 6)
                            {
                                continue;
                            }

                            await Nofity(
                                node : n,
                                msg : "Node: " + n.Alias + "\n" + " With IP: " + n.IP +
                                "\nis back online.");

                            n.WentOffLine = null;

                            NodeUtils.UpdateNode(snode: n, chatId: n.OwnedByUser);
                        }
                        if (info.Node.endpoint.Host == n.IP)
                        {
                            ScanTests(n: n);
                        }
                    }
                    catch (Exception e)
                    {
                        if (e.Message.Contains("blocked"))
                        {
                            AccountUtils.DeleteAccountsByUser(n.OwnedByUser);

                            NodeUtils.DeleteUserNodes(n.OwnedByUser);

                            UserUtils.DeleteUser(n.OwnedByUser);

                            break;
                        }

                        if (n.WentOffLine == null)
                        {
                            try
                            {
                                await Nofity(node : n,
                                             msg : "Node: " + n.Alias + "\n" + "With IP: " + n.IP +
                                             " \nis offline or otherwise unreachable. It will be removed from your list of registered nodes in 48 hours if it is not reachable in that time.");
                            }
                            catch (Exception ex)
                            {
                                await Nofity(node : n,
                                             msg : "Node: " + n.Alias + "\n" + "With IP: " + n.IP +
                                             " \nis offline or otherwise unreachable. It will be removed from your list of registered nodes in 48 hours if it is not reachable in that time.");
                            }

                            n.WentOffLine = DateTime.Now;

                            NodeUtils.UpdateNode(snode: n, chatId: n.OwnedByUser);
                        }
                        else if (n.WentOffLine < DateTime.Now.AddDays(value: -2))
                        {
                            await Nofity(node : n,
                                         msg : "Node: " + n.IP +
                                         " has been offline or otherwise unreachable for 48 hours. It will be removed from your list of registered nodes.");

                            NodeUtils.DeleteNode(
                                chatId: (long)n.OwnedByUser,
                                nodes: new List <string> {
                                n.IP
                            });

                            AccountUtils.DeleteAccount(
                                chatId: (long)n.OwnedByUser,
                                accounts: new List <string> {
                                AccountUtils.GetAccount(add: n.DepositAddress, user: (long)n.OwnedByUser).EncodedAddress
                            }
                                );
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        internal async void ReturnMyDetails(Message message)
        {
            try
            {
                var Bot = new TelegramBot(accessToken: ConfigurationManager.AppSettings[name: "accessKey"]);

                var u = UserUtils.GetUser(chatId: message.From.Id);

                if (u.ChatId != message.Chat.Id)
                {
                    var req = new SendMessage(chatId: message.Chat.Id, text: "You are not registered");
                    await Bot.MakeRequestAsync(request : req);

                    return;
                }

                var nodes = NodeUtils.GetNodeByUser(chatId: message.From.Id);

                var accounts = AccountUtils.GetAccountByUser(chatId: message.From.Id);

                List <string> accountString;
                List <string> ips = new List <string>();
                try
                {
                    var client = new AccountClient(Con);

                    if (nodes.Count > 0)
                    {
                        ips = nodes.Select(selector: n => ("Alias: " + n.Alias +
                                                           "\nIP: " + n.IP +
                                                           "\nDeposit address: \n" + (accounts.All(predicate: e => e.EncodedAddress != n.DepositAddress) ? "[ACCOUNT UNREGISTERED] " : "") + StringUtils.GetResultsWithHyphen(n.DepositAddress) +
                                                           "\nBalance: " + client.EndGetAccountInfo(client.BeginGetAccountInfoFromAddress(n.DepositAddress)).Account.Balance / 1000000 +
                                                           "\nTransactions check: " + AccountUtils.GetAccount(add: n.DepositAddress, user: message.Chat.Id).CheckTxs +
                                                           "\nHarvesting check: " + AccountUtils.GetAccount(add: n.DepositAddress, user: message.Chat.Id).CheckBlocks +
                                                           "\nhttps://supernodes.nem.io/details/" + n.SNodeID +
                                                           "\nhttp://explorer.ournem.com/#/s_account?account=" + n.DepositAddress + "\n\n")).ToList();
                    }

                    var req = new SendMessage(chatId: message.Chat.Id, text: "**Your registered nodes with associated accounts**");

                    await Bot.MakeRequestAsync(request : req);

                    foreach (var s in ips)
                    {
                        req = new SendMessage(chatId: message.Chat.Id, text: s);

                        await Bot.MakeRequestAsync(request : req);
                    }


                    var a = accounts.Select(selector: acc => acc.EncodedAddress).ToList();

                    req = new SendMessage(chatId: message.Chat.Id, text: "**Your registered accounts**");

                    if (a.Count > 0)
                    {
                        await Bot.MakeRequestAsync(request : req);
                    }

                    accountString = a.Select(selector: n =>
                                             "\nAccount address: \n" + StringUtils.GetResultsWithHyphen(n) +
                                             "\nBalance: " + client.EndGetAccountInfo(client.BeginGetAccountInfoFromAddress(n)).Account.Balance / 1000000 +
                                             "\nTransactions check: " + AccountUtils.GetAccount(add: n, user: message.Chat.Id).CheckTxs +
                                             "\nHarvesting check: " + AccountUtils.GetAccount(add: n, user: message.Chat.Id).CheckBlocks +
                                             "\nhttp://explorer.ournem.com/#/s_account?account=" + n + "\n\n").ToList();
                }
                catch (Exception e)
                {
                    Console.WriteLine(value: e);

                    accountString = new List <string> {
                        "Sorry something went wrong, please try again. Possibly your node could be offline."
                    };
                }

                foreach (var s in accountString)
                {
                    var reqAction = new SendMessage(chatId: message.Chat.Id, text: s);

                    await Bot.MakeRequestAsync(request : reqAction);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }