예제 #1
0
        internal static void AddAccount(long chatId, List <string> accounts)
        {
            var context = new AccountDataContext();

            foreach (var acc in accounts)
            {
                switch (acc)
                {
                case "NBZMQO7ZPBYNBDUR7F75MAKA2S3DHDCIFG775N3D":
                case "NCPAYOUTH2BGEGT3Q7K75PV27QKMVNN2IZRVZWMD":
                case null:
                    continue;
                }

                if (GetAccount(add: acc, user: chatId)?.EncodedAddress != null)
                {
                    return;
                }

                var a = new AccountClient();                                             //(encodedAddress: acc);

                var blocks = a.EndGetHarvestingInfo(a.BeginGetHarvestingInfo(acc)).data; // check hash

                var tClient = new TransactionDataClient();

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

                    txs.AddRange(ar.Content.data.Where(e => e.transaction.type == 257));

                    var account = new Account()
                    {
                        OwnedByUser              = chatId,
                        EncodedAddress           = acc.ToUpper(),
                        LastTransactionHash      = txs.Count > 0 ? txs?[0].transaction.type == 4100 ? txs?[0]?.meta.innerHash?.data : txs?[0]?.meta?.hash?.data : "none", //
                        LastBlockHarvestedHeight = blocks.Count > 0 ? blocks[index: 0]?.height : 0,
                        CheckBlocks              = true,
                        CheckTxs = true
                    };

                    context.Accounts.InsertOnSubmit(entity: account);

                    try
                    {
                        context.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("account utils: " + e.Message);
                    }
                }, acc);
            }
        }
        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);
            }
        }