public override int GetHashCode()
 {
     unchecked
     {
         return((SendAmount.GetHashCode() * 397) ^ ReceiveAmount.GetHashCode());
     }
 }
Ejemplo n.º 2
0
        private void Send(object obj)
        {
            if (NodeCount == 0)
            {
                MessageBox.Show("You are connected to 0 nodes. Wait until you are connected to at least one node before sending.", "Wallet", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            if (!Regex.IsMatch(SendAddress, "^0x[a-fA-F0-9]{40}$"))
            {
                MessageBox.Show("Send to Address is not a valid address.", "WTC Wallet", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if (SendAmount == null)
            {
                MessageBox.Show("You must enter an amount to send.", "WTC Wallet", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if (SendAmount < 0)
            {
                MessageBox.Show("Negative amounts can not be sent.", "WTC Wallet", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            EnterPassphraseWindow window = new EnterPassphraseWindow();

            window.Owner = Application.Current.MainWindow;
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            EnterPassphraseVM vm = new EnterPassphraseVM(() => window.Close(), PublicKey);

            window.DataContext = vm;
            window.ShowDialog();

            if (!vm.Confirmed)
            {
                return;
            }


            try
            {
                var unlockAccountResult =
                    Task.Run(() => AppVM.Geth.Personal.UnlockAccount.SendRequestAsync(PublicKey, vm.GetPassphrase(), 60)).Result;

                if (!unlockAccountResult)
                {
                    MessageBox.Show("Failed to unlock your wallet.", "WTC Wallet", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    return;
                }



                var amount = SendAmount.Value * (decimal)Math.Pow(10, 18);

                var id = Task.Run(() => AppVM.Geth.Eth.TransactionManager.SendTransactionAsync(PublicKey, SendAddress, new HexBigInteger(new BigInteger(amount)))).Result;



                Transactions.Insert(0, new TransactionVM {
                    Hash = id, Amount = SendAmount.ToString(), To = SendAddress, BlockNumber = "Pending", IsPending = true, Type = "Sent WTC", From = PublicKey, Date = DateTime.Now
                });

                if (SendAddress.ToUpper() == PublicKey.ToUpper())
                {
                    Transactions.Insert(0, new TransactionVM {
                        Hash = id, Amount = SendAmount.ToString(), To = SendAddress, BlockNumber = "Pending", IsPending = true, Type = "Received WTC", From = PublicKey, Date = DateTime.Now
                    });
                }

                Task.Run(() => AppVM.Geth.Personal.LockAccount.SendRequestAsync(PublicKey)).Wait();

                ShowSendSuccess = true;
                SendAmount      = null;
                SendAddress     = String.Empty;

                Task.Run(() =>
                {
                    Thread.Sleep(6000);
                    ShowSendSuccess = false;
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to send the transaction: " + ex.GetBaseException().Message, "WTC Wallet", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }