Esempio n. 1
0
        public void Withdraw()
        {
            if (Program.currentLoggedInAddress != null)
            {
                Console.Clear();
                Console.WriteLine("Withdraw money at blockchain e-wallet.");
                Console.WriteLine("Please enter the amount to withdraw: ");
                var amount = double.Parse(Console.ReadLine());
                if (amount > Program.currentLoggedInAddress.Balance)
                {
                    Console.WriteLine("Invalid amount, please check again!");
                    return;
                }

                var blockchainTransaction = new BlockchainTransaction
                {
                    TransactionId   = Guid.NewGuid().ToString(),
                    SenderAddress   = Program.currentLoggedInAddress.Address,
                    ReceiverAddress = Program.currentLoggedInAddress.Address,
                    Type            = BlockchainTransaction.TransactionType.WITHDRAW,
                    Amount          = amount,
                    Message         = "Withdraw money at blockchain e-wallet with money: " + amount,
                    CreateAtMlS     = DateTime.Now.Ticks,
                    UpdateAtMlS     = DateTime.Now.Ticks,
                    Status          = BlockchainTransaction.TransactionStatus.DONE
                };
                if (blockchainAddressModel.UpdateBalanceBlockchain(Program.currentLoggedInAddress, blockchainTransaction))
                {
                    Console.WriteLine("Successful transaction.");
                }
            }
            else
            {
                Console.WriteLine("Please login to use this function.");
            }
        }
        public void RutTien()
        {
            if (Program.currentLoggedInAddress != null)
            {
                Console.Clear();
                Console.WriteLine("Tiến hành rút tiền tại ví điện tử Blockchain.");
                Console.WriteLine("Vui lòng nhập số tiền cần rút.");
                var amount = double.Parse(Console.ReadLine());
                if (amount > Program.currentLoggedInAddress.Balance)
                {
                    Console.WriteLine("Số lượng không hợp lệ, vui lòng thử lại.");
                    return;
                }

                var blockchainTransaction = new BlockchainTransaction
                {
                    TransactionId   = Guid.NewGuid().ToString(),
                    SenderAddress   = Program.currentLoggedInAddress.Address,
                    ReceiverAddress = Program.currentLoggedInAddress.Address,
                    Type            = BlockchainTransaction.TransactionType.WITHDRAW,
                    Amount          = amount,
                    Message         = "Tiến hành rút tiền tại ví điện tử Blockchain với số tiền: " + amount,
                    CreateAtMlS     = DateTime.Now.Ticks,
                    UpdateAtMlS     = DateTime.Now.Ticks,
                    Status          = BlockchainTransaction.TransactionStatus.DONE
                };
                if (blockchainAddressModel.UpdateBalanceBlockchain(Program.currentLoggedInAddress, blockchainTransaction))
                {
                    Console.WriteLine("Giao dịch thành công.");
                }
            }
            else
            {
                Console.WriteLine("Vui lòng đăng nhập để sử dụng chức năng này.");
            }
        }