Esempio n. 1
0
 public void Transfer()
 {
     if (Program.currentLoggedInAddress != null)
     {
         Console.WriteLine("Transfer at Blockchain e-wallet.");
         Console.WriteLine("Please enter the address you want to transfer: ");
         var address         = Console.ReadLine();
         var receiverAddress = blockchainAddressModel.GetAddress(address);
         if (receiverAddress == null)
         {
             Console.WriteLine("Money receiving account does not exist or has been locked.");
             return;
         }
         Console.WriteLine("Address to receive money: " + address);
         Console.WriteLine("Enter the amount you want to transfer: ");
         var amount = double.Parse(Console.ReadLine());
         Program.currentLoggedInAddress = blockchainAddressModel.GetAddress(Program.currentLoggedInAddress.Address);
         if (amount > Program.currentLoggedInAddress.Balance)
         {
             Console.WriteLine("Account balance is not enough to make transactions.");
             return;
         }
         Console.WriteLine("Enter transaction content: ");
         var message = Console.ReadLine();
         var blockchainTransaction = new BlockchainTransaction()
         {
             TransactionId   = Guid.NewGuid().ToString(),
             Type            = BlockchainTransaction.TransactionType.TRANSFER,
             Amount          = amount,
             Message         = message,
             CreateAtMlS     = DateTime.Now.Ticks,
             UpdateAtMlS     = DateTime.Now.Ticks,
             Status          = BlockchainTransaction.TransactionStatus.DONE,
             SenderAddress   = Program.currentLoggedInAddress.Address,
             ReceiverAddress = address
         };
         if (blockchainAddressModel.Transfer(Program.currentLoggedInAddress, blockchainTransaction))
         {
             Console.WriteLine("Successful transaction!");
         }
         else
         {
             Console.WriteLine("The transaction failed, please check again.");
         }
     }
 }
Esempio n. 2
0
        public void Transfer()
        {
            if (Program.currentLoggedInAddress != null)
            {
                Console.Clear();
                Console.WriteLine("Tien hanh chuyen tien tai blockchain");
                Console.WriteLine("Nhap so tien can chuyen.");
                decimal amount = decimal.Parse(Console.ReadLine());
                if (amount <= 0)
                {
                    Console.WriteLine("Số lưong khong hop le.");
                    return;
                }

                Console.WriteLine("Nhap address nguoi nhan");
                var receiver    = Console.ReadLine();
                var transaction = new BlockchainTransaction()
                {
                    TransactionId   = Guid.NewGuid().ToString(),
                    SenderAddress   = Program.currentLoggedInAddress.Address,
                    ReceiverAddress = receiver,
                    Amount          = amount,
                    CreatedAtMLS    = DateTime.Now.Ticks,
                    UpdatedAtMLS    = DateTime.Now.Ticks,
                    Status          = 1
                };
                bool result = blockchainAccountModel.Transfer(Program.currentLoggedInAddress, transaction);
                if (result)
                {
                    Console.WriteLine("Thanh cong");
                }
            }
            else
            {
                Console.WriteLine("Vui lòng đăng nhập để sử dụng chức năng này.");
            }
        }