예제 #1
0
        public void Sync()
        {
            try
            {
                // To get an account information from the address.
                var accountClient   = new AccountClient(connection);
                var accountResult   = accountClient.BeginGetAccountInfoFromAddress(Address);
                var accountResponse = accountClient.EndGetAccountInfo(accountResult);

                Balance         = ((double)accountResponse.Account.Balance / 1000000).ToString("N6");
                PublicKey       = accountResponse.Account.PublicKey.Substring(0, 10) + "**********...";
                HarvestedBlocks = accountResponse.Account.HarvestedBlocks;
                Importance      = accountResponse.Account.Importance;
                VestedBalance   = ((double)accountResponse.Account.VestedBalance / 1000000).ToString("N6");

                // To get mosaic information of the account from the address.
                var mosaicClient   = new NamespaceMosaicClient(connection);
                var mosaicResult   = mosaicClient.BeginGetMosaicsOwned(Address);
                var mosaicResponse = mosaicClient.EndGetMosaicsOwned(mosaicResult);

                Mosaics.Clear();

                foreach (var data in mosaicResponse.Data)
                {
                    Mosaics.Add(new Mosaic(data.MosaicId.NamespaceId, data.MosaicId.Name, data.Quantity));
                }
            }
            catch (Exception ex)
            {
            }
        }
        private Task <IMolfarAnswer> ProcessInfoCommand(string address)
        {
            var connection = new Connection();

            connection.SetMainnet();
            var accountClient = new AccountClient(connection);

            var res = accountClient.BeginGetAccountInfoFromAddress(address);

            res.AsyncWaitHandle.WaitOne();
            var data = accountClient.EndGetAccountInfo(res);

            var answer = new MolfarMultirowAnswer();

            answer.AddRow($"Address: {data.Account.Address}");
            answer.AddRow($"Balance: {data.Account.Balance}");
            answer.AddRow($"Vasted : {data.Account.VestedBalance}");

            return(Task.FromResult(answer as IMolfarAnswer));
        }
예제 #3
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);
            }
        }