Пример #1
0
        public void DebugToConsole(IEnumerable <BCTransaction> transactionList)
        {
            BCTransactionProvider bc       = new BCTransactionProvider();
            BCTransaction         prevItem = null;

            foreach (var item in transactionList)
            {
                bool isValid = true;
                if (prevItem != null)
                {
                    isValid = bc.IsValid(prevItem, item);
                }

                if (isValid == false)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }

                Console.WriteLine($"Transaction Id: {item.TransactionId}");
                Console.WriteLine($"Transaction Previous Id: {item.TransactionPreviousId}");
                Console.WriteLine($"Owner Id: {item.OwnerId}");
                Console.WriteLine($"Date Created: {item.DateCreated}");
                Console.WriteLine($"Transaction amount: {item.Amount}");
                Console.WriteLine($"Balance: {item.Balance}"); Console.WriteLine($"Transaction Hash (simple): {item.TransactionHashSimple}");
                Console.WriteLine($"Transaction Hash (crypto): {item.TransactionHashCrypto}");
                Console.WriteLine("--------------------------------------------");
                Console.ResetColor();

                prevItem = item;
            }
        }
        private void InitializeBCTransactions()
        {
            _bcTransactions = new List <BCTransaction>();

            BCTransaction         newBCTrans;
            BCTransactionProvider bctProvider;

            newBCTrans =
                new BCTransaction {
                TransactionId = "0", OwnerId = "ABC", TransactionPreviousId = "0", DateCreated = Convert.ToDateTime("2019-04-01 14:45"), Amount = 0
            };

            _bcTransactions.Add(newBCTrans);


            //Create some mock transactions
            for (int i = 1; i < _numberOfTransactions + 1; i++)
            {
                bctProvider = new BCTransactionProvider();

                Random random = new Random();

                int randomNumber = random.Next(-500, 500);
                if (randomNumber == 0)
                {
                    randomNumber = random.Next(10, 500);
                }

                newBCTrans = bctProvider.AddTransaction(newBCTrans.TransactionId, newBCTrans.TransactionHashCrypto, i.ToString(), "ABC", DateTime.Now, randomNumber, newBCTrans.Balance);
                _bcTransactions.Add(newBCTrans);
            }
        }
Пример #3
0
        public void SaveToFile(IEnumerable <BCTransaction> transactionList, string filename)
        {
            BCTransactionProvider bc       = new BCTransactionProvider();
            BCTransaction         prevItem = null;

            using (StreamWriter sw = new StreamWriter($@"{filename}"))
            {
                sw.WriteLine("Transaction Id;Transaction Previous Id;Owner Id;Date Created;Transaction amount;Balance;Hash;HashCrypto;IsValid");

                foreach (var item in transactionList)
                {
                    bool isValid = true;
                    if (prevItem != null)
                    {
                        isValid = bc.IsValid(prevItem, item);
                    }
                    sw.WriteLine($"{item.TransactionId};{item.TransactionPreviousId};{item.OwnerId};{item.DateCreated};{item.Amount};{item.Balance};'{item.TransactionHashSimple}';{item.TransactionHashCrypto};{isValid}");

                    prevItem = item;
                }
            }
        }