Example #1
0
        public void Load(string accountName, string onionAddress)
        {
            _accountName      = accountName;
            this.OnionAddress = onionAddress;

            OnionHandler handler = new OnionHandler();


            // seems that rpc getbalance delivers wrong amounts.. Check explorer.deeponion.org instead.
            //this.TotalAmount = handler.GetAccountBalance(_accountName);
            this.TotalAmount = OnionPriceChecker.GetAddressBalance(onionAddress);

            this.DollarValue = OnionPriceChecker.GetOnionUSD() * this.TotalAmount;

            this.Fees = (decimal)0.001;
            this.MaxAmountSpendable = (this.TotalAmount > this.Fees) ? this.TotalAmount - this.Fees : 0;

            this.Transactions = handler.ListTransactions(_accountName, 20, 0);

            this.Transactions = this.Transactions.OrderByDescending(x => x.Time).ToList();

            foreach (var item in this.Transactions)
            {
                if (item.Category == "send")
                {
                    // TODO: Calculate the actual fees
                    item.Amount = item.Amount - (decimal)0.001;
                }
            }
        }
Example #2
0
        public ActionResult Send(string address, string amount)
        {
            decimal amountParsed = 0;

            if (string.IsNullOrEmpty(this.CurrentUser.AccountName))
            {
                TempData["ErrorMessage"] = "Authentication Error!";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            if (string.IsNullOrEmpty(address))
            {
                TempData["ErrorMessage"] = "Did you enter a receiver address?";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            if (string.IsNullOrEmpty(amount))
            {
                TempData["ErrorMessage"] = "Did you enter an amount?";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            if (!decimal.TryParse(amount, out amountParsed))
            {
                amount = amount.Replace(".", ",");
                if (!decimal.TryParse(amount, out amountParsed))
                {
                    TempData["ErrorMessage"] = "Did you enter a correct amount?";
                    return(RedirectToAction("Dancefloor", "Home"));
                }
            }

            OnionHandler handler = new OnionHandler();

            // seems that rpc getbalance delivers wrong amounts.. Check explorer.deeponion.org instead.
            //decimal amountSpendable = handler.GetAccountBalance(this.CurrentUser.AccountName);
            decimal amountSpendable = OnionPriceChecker.GetAddressBalance(this.CurrentUser.OnionAddress);

            // TODO Calculate actual fees
            amountSpendable = (amountSpendable > (decimal)0.001) ? amountSpendable - (decimal)0.001 : 0;

            if (amountParsed > amountSpendable)
            {
                TempData["ErrorMessage"] = "Insufficient funds! You cannot send more than " + amountSpendable + " Onions!";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            try
            {
                string transactionID = handler.SendOnions(this.CurrentUser.AccountName, address, amountParsed);
                TempData["SuccessMessage"] = "Onions successfully sent!";
            }
            catch (Exception ex)
            {
                Logger.Error("OnionController->Send: " + ex.Message);
                TempData["ErrorMessage"] = "Oops, something went wrong! Please try again or contact support.";
            }

            return(RedirectToAction("Dancefloor", "Home"));
        }
Example #3
0
        public ActionResult Donation(decimal?amount)
        {
            if (string.IsNullOrEmpty(this.CurrentUser.AccountName) || !amount.HasValue && amount.Value > 0)
            {
                TempData["ErrorMessage"] = "Please enter a valid donation amount.";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            OnionHandler handler = new OnionHandler();

            // seems that rpc getbalance delivers wrong amounts.. Check explorer.deeponion.org instead.
            //decimal amountSpendable = handler.GetAccountBalance(this.CurrentUser.AccountName);
            decimal amountSpendable = OnionPriceChecker.GetAddressBalance(this.CurrentUser.OnionAddress);



            if (amount.Value > amountSpendable)
            {
                TempData["ErrorMessage"] = "Insufficient funds! You cannot donate more than " + amountSpendable + " Onions!";
                return(RedirectToAction("Dancefloor", "Home"));
            }

            try
            {
                if (handler.Move(this.CurrentUser.AccountName, ConfigurationManager.AppSettings["DonationAccountName"].ToString(), amount.Value))
                {
                    TempData["SuccessMessage"] = "We received your donation of " + amount.Value + " Onions. Thank you so much!";
                }
                else
                {
                    TempData["ErrorMessage"] = "Ooops, something went wrong. Thanks for the good intentions.";
                }
            }
            catch (Exception ex)
            {
                Logger.Error("OnionController->Donation: " + ex.Message);
                TempData["ErrorMessage"] = "Ooops, something went wrong. Thanks for the good intentions.";
            }

            return(RedirectToAction("Dancefloor", "Home"));
        }
Example #4
0
        public ActionResult Register(IndexModel data)
        {
            if (!ModelState.IsValid)
            {
                return(View(data));
            }

            if (data.RegisterPassword != data.RegisterRepeatPassword)
            {
                TempData["ErrorMessage"]  = "Passwords do not match.";
                TempData["RegisterEmail"] = data.RegisterEmail;
                return(RedirectToAction("Index"));
            }

            if (!data.RegisterAcceptTOS)
            {
                TempData["ErrorMessage"]  = "Please accept terms of service.";
                TempData["RegisterEmail"] = data.RegisterEmail;
                return(RedirectToAction("Index"));
            }

            OnionWalletEntities entities = new OnionWalletEntities();

            OnionUser existing = entities.OnionUsers.FirstOrDefault(x => x.Email == data.RegisterEmail.ToLower());

            if (existing != null)
            {
                TempData["ErrorMessage"]  = "Email already exists!";
                TempData["RegisterEmail"] = data.RegisterEmail;
                return(RedirectToAction("Index"));
            }

            OnionUser user = new OnionUser();

            user.InitGUIDs();

            user.Email = data.RegisterEmail;
            user.SetPassword(data.RegisterPassword);
            user.IsMailing    = data.RegisterIsMailing;
            user.OnionAddress = "gugus";
            user.IsActive     = true;
            user.CreateDate   = DateTime.Now;

            entities.OnionUsers.Add(user);
            entities.SaveChanges();

            string subject = "OnionWallet Email confirmation";
            string body    = "Hi" + Environment.NewLine + Environment.NewLine + "You have successfully created your Web OnionWallet on onionwallet.ch!" + Environment.NewLine + Environment.NewLine;

            body = body + "Please click the link below to activate your wallet:" + Environment.NewLine + Environment.NewLine;
            body = body + ConfigurationManager.AppSettings["BaseURL"].ToString() + "/mailconfirmation/" + user.EmailConfirmationGUID.ToString() + Environment.NewLine + Environment.NewLine;
            body = body + "Thanks and enjoy the Onion Party!";

            new Thread(() =>
            {
                OnionWalletEntities threadEntities = new OnionWalletEntities();

                try
                {
                    OnionUser threadUser = threadEntities.OnionUsers.FirstOrDefault(x => x.GUID == user.GUID);

                    OnionHandler onionHandler = new OnionHandler();
                    threadUser.OnionAddress   = onionHandler.CreateAccount(user.GUID.ToString());
                    threadEntities.SaveChanges();
                }
                catch (Exception ex)
                {
                    Log log        = new Log();
                    log.CreateDate = DateTime.Now;
                    log.Level      = 1;
                    log.Message    = ex.Message;
                    log.Type       = (int)LogTypeEnum.Error;
                    log.UserID     = 0;
                    threadEntities.Logs.Add(log);
                    threadEntities.SaveChanges();
                }
            }).Start();

            new Thread(() =>
            {
                try
                {
                    GmailHandler.SendMail(user.Email, subject, body);
                }
                catch (Exception ex)
                {
                    OnionWalletEntities threadEntities = new OnionWalletEntities();
                    Log log        = new Log();
                    log.CreateDate = DateTime.Now;
                    log.Level      = 1;
                    log.Message    = ex.Message;
                    log.Type       = (int)LogTypeEnum.Error;
                    log.UserID     = 0;
                    threadEntities.Logs.Add(log);
                    threadEntities.SaveChanges();
                }
            }).Start();

            TempData["SuccessMessage"] = "Party ticket booked! Please click link in confirmation email and log in to access your wallet. Check your spam folder, if you can't find the email.";

            return(RedirectToAction("Index"));
        }