Ejemplo n.º 1
0
        private static async void Notify(Account a, Transactions.TransactionData t)
        {
            try
            {
                var bot = new TelegramBot(accessToken: ConfigurationManager.AppSettings[name: "accessKey"]);
                var msg = "There is a new " + (t.transaction.type == 257 ? "" : "multisig ") +
                          "transaction on account: \n" +
                          StringUtils.GetResultsWithHyphen(a.EncodedAddress) +
                          "\nhttp://explorer.ournem.com/#/s_account?account=" + a.EncodedAddress +
                          "\nRecipient: \n" +
                          (t.transaction.type == 257
                              ? StringUtils.GetResultsWithHyphen(t.transaction.recipient)
                              : StringUtils.GetResultsWithHyphen(t.transaction.otherTrans.recipient)) +
                          "\nAmount: " + (t.transaction.amount / 1000000) + " XEM";

                var reqAction = new SendMessage(chatId: a.OwnedByUser,
                                                text: msg);
                Console.WriteLine(msg);
                await bot.MakeRequestAsync(request : reqAction);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("blocked"))
                {
                    AccountUtils.DeleteAccountsByUser(a.OwnedByUser);

                    NodeUtils.DeleteUserNodes(a.OwnedByUser);

                    UserUtils.DeleteUser(a.OwnedByUser);
                }
            }
        }
Ejemplo n.º 2
0
        private async Task Nofity(SuperNode node, string msg)
        {
            try
            {
                var reqAction = new SendMessage(chatId: (long)node.OwnedByUser, text: msg);
                await bot.MakeRequestAsync(request : reqAction);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("blocked"))
                {
                    AccountUtils.DeleteAccountsByUser(node.OwnedByUser);

                    NodeUtils.DeleteUserNodes(node.OwnedByUser);

                    UserUtils.DeleteUser(node.OwnedByUser);
                }
            }
        }
        private static async void Notify(Account usrAcc, HarvestingData.Datum hrvData)
        {
            try
            {
                var bot = new TelegramBot(accessToken: ConfigurationManager.AppSettings[name: "accessKey"]);

                var reqAction = new SendMessage(chatId: usrAcc.OwnedByUser, text: "The account: \n" + StringUtils.GetResultsWithHyphen(usrAcc.EncodedAddress) + " harvested a new block. \n" + "http://explorer.ournem.com/#/s_block?height=" + hrvData.height + "\nFees included: " + (hrvData.totalFee / 1000000));

                await bot.MakeRequestAsync(request : reqAction);
            }
            catch (Exception e)
            {
                if (e.Message.Contains("blocked"))
                {
                    AccountUtils.DeleteAccountsByUser(usrAcc.OwnedByUser);

                    NodeUtils.DeleteUserNodes(usrAcc.OwnedByUser);

                    UserUtils.DeleteUser(usrAcc.OwnedByUser);
                }
            }
        }
Ejemplo n.º 4
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.º 5
0
        private static async void ScanTransactions(Account userAccount)
        {
            try
            {
                var tClient = new TransactionDataClient(Con);

                var request = tClient.BeginGetAllTransactions(ar =>
                {
                    try
                    {
                        var txs = ar.Content.data.Where(e => e.transaction?.otherTrans?.type == 257 || e.transaction?.type == 257).ToList();


                        foreach (var t in txs)
                        {
                            if (userAccount.LastTransactionHash == txs?[0]?.meta.innerHash?.data || userAccount.LastTransactionHash == txs?[0]?.meta?.hash?.data)
                            {
                                userAccount.LastTransactionHash = txs?[0].transaction.type == 4100 ? txs?[0]?.meta.innerHash?.data : txs?[0]?.meta?.hash?.data;

                                break;
                            }


                            if (userAccount.LastTransactionHash == t.meta?.hash?.data || userAccount.LastTransactionHash == t.meta.innerHash.data)
                            {
                                userAccount.LastTransactionHash = txs?[0].transaction.type == 4100 ? txs?[0]?.meta.innerHash?.data : txs?[0]?.meta?.hash?.data;
                                AccountUtils.UpdateAccount(usrAcc: userAccount);

                                break;
                            }

                            if (!userAccount.CheckTxs)
                            {
                                continue;
                            }

                            try
                            {
                                var summary = new AccountTxSummary
                                {
                                    AmountIn         = t.transaction.recipient == userAccount.EncodedAddress ? t.transaction.amount : 0,
                                    AmountOut        = t.transaction.recipient != userAccount.EncodedAddress ? t.transaction.amount : 0,
                                    MonitoredAccount = userAccount.EncodedAddress,
                                    Recipient        = t.transaction.type == 257 ? t.transaction.recipient : t.transaction.otherTrans.recipient,
                                    Sender           = AddressEncoding.ToEncoded(network: 0x68, publicKey: new PublicKey(key: t.transaction.type == 257 ? t.transaction.signer : t.transaction.otherTrans.signer)),
                                    DateOfInput      = DateTime.Now,
                                    OwnedByUser      = userAccount.OwnedByUser
                                };

                                Notify(a: userAccount, t: t);

                                SummaryUtils.AddTxSummary(s: summary);
                            }
                            catch (Exception e)
                            {
                                if (e.Message.Contains("blocked"))
                                {
                                    AccountUtils.DeleteAccountsByUser(userAccount.OwnedByUser);

                                    NodeUtils.DeleteUserNodes(userAccount.OwnedByUser);

                                    UserUtils.DeleteUser(userAccount.OwnedByUser);
                                }
                                else
                                {
                                    Console.WriteLine("Trans scanner line 112: " + e.StackTrace);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(value: e);

                        if (e.Message.Contains("blocked"))
                        {
                            AccountUtils.DeleteAccountsByUser(userAccount.OwnedByUser);

                            NodeUtils.DeleteUserNodes(userAccount.OwnedByUser);

                            UserUtils.DeleteUser(userAccount.OwnedByUser);
                        }
                    }
                }, userAccount.EncodedAddress);

                request.AsyncWaitHandle.WaitOne();
            }
            catch (Exception e)
            {
                Console.WriteLine("Transaction scanner line 136: " + e.StackTrace);
            }
        }
        private static void ScanBlocks(Account userAccount)
        {
            try
            {
                var aClient = new AccountClient(Con);

                aClient.BeginGetHarvestingInfo(ar =>
                {
                    try
                    {
                        if (ar.Content.data != null)
                        {
                            foreach (var t in ar.Content.data)
                            {
                                if (ar.Content.data.Count <= 0 || userAccount.LastBlockHarvestedHeight >= t?.height)
                                {
                                    continue;
                                }

                                userAccount.LastBlockHarvestedHeight = t?.height;

                                AccountUtils.UpdateAccount(
                                    usrAcc: userAccount);

                                var hb = new AccountHarvestedSummary()
                                {
                                    BlockHeight      = t.height,
                                    FeesEarned       = t.totalFee,
                                    MonitoredAccount = userAccount.EncodedAddress,
                                    DateOfInput      = DateTime.Now,
                                    OwnedByUser      = userAccount.OwnedByUser
                                };

                                try
                                {
                                    if (userAccount.CheckBlocks)
                                    {
                                        SummaryUtils.AddHBSummary(s: hb);
                                        Notify(usrAcc: userAccount, hrvData: t);
                                    }
                                }
                                catch (Exception e)
                                {
                                    if (e.Message.Contains("blocked"))
                                    {
                                        AccountUtils.DeleteAccountsByUser(userAccount.OwnedByUser);

                                        NodeUtils.DeleteUserNodes(userAccount.OwnedByUser);

                                        UserUtils.DeleteUser(userAccount.OwnedByUser);
                                    }

                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(value: e);
                    }
                }, userAccount.EncodedAddress);
            }
            catch (Exception e)
            {
                Console.WriteLine(value: e);
            }
        }