Beispiel #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);
            }
        }