protected void Page_Load(object sender, EventArgs e) { OneTokenTodayCost = TokensDataHelper.GetOneTokensCost(); AvailableTokensCount = TokensDataHelper.GetAvailableTokensCount(); SellTokensCount = 4900000000 - AvailableTokensCount; if (User != null) { UserWalletsList = WalletsHelper.GetUserWallets(User.UserId); UserWalletRURT = UserWalletsList.Where(x => x.CurrencyId == (int)CurrenciesEnum.RURT).FirstOrDefault(); if (UserWalletRURT == null) { UserWalletRURT = new fnGetUserWallets_Result { CurrencyId = (int)CurrenciesEnum.RURT, Value = 0 } } ; UserWalletRENT = UserWalletsList.Where(x => x.CurrencyId == (int)CurrenciesEnum.RENT).FirstOrDefault(); if (UserWalletRENT == null) { UserWalletRENT = new fnGetUserWallets_Result { CurrencyId = (int)CurrenciesEnum.RENT, Value = 0 } } ; } }
public SwitcheoAuthenticationProvider(ApiCredentials credentials, BlockchainType keyType) : base(new ApiCredentials(new PrivateKey(EnsureHexFormat(credentials.PrivateKey.Key, credentials.PrivateKey?.Passphrase)))) { if (this.CanSign) { if (keyType == BlockchainType.Qtum || keyType == BlockchainType.Ethereum) { throw new NotImplementedException(); } try { this.KeyType = keyType; SecureString readablePrivateKey = credentials.PrivateKey.Key; // Decrypting private key if Nep2 format was provided if (WalletsHelper.IsNep2(credentials.PrivateKey.Key)) { readablePrivateKey = Nep2.Decrypt(credentials.PrivateKey.Key.GetString(), credentials.PrivateKey.Passphrase.GetString()).Result.ToHexString().ToSecureString(); } // Extracting wallet informations (public key, script hash, address and fixed address) this.WalletInformations = WalletsHelper.GetWalletInformations(readablePrivateKey, keyType); } catch (Exception) { throw privateKeyException; } } }
private static SecureString EnsureHexFormat(SecureString privateKey, SecureString passphrase = null) { try { //TODO: BlockchainType.Qtum, BlockchainType.Ethereum ... SecureString _privateKey = privateKey; if (WalletsHelper.IsNep2(privateKey) && passphrase != null) { _privateKey = Nep2.Decrypt(privateKey.GetString(), passphrase.GetString()).Result.ToHexString().ToSecureString(); } else { if (privateKey != null && privateKey.Length > 0) { if (!WalletsHelper.IsHex(privateKey.GetString())) { _privateKey = WalletsHelper.ConvertToHex(privateKey); } } } return(_privateKey); } catch (Exception) { throw privateKeyException; } }
public void IsNep2_Should_DetectEncryptedKeys() { SecureString correctNep2Wallet = "6PYWLPXtLHZeqR1vpWtcfSt5Ubwba3Qv1zdeacd7347mBfXABa9WXbe3Yh".ToSecureString(); SecureString incorrectNep2Wallet = "KxmqXqdavQhziXNGborgiqy3JWjCmDHgJpKniMdFdnLHCBmCXnoU".ToSecureString(); Assert.IsTrue(WalletsHelper.IsNep2(correctNep2Wallet)); Assert.IsFalse(WalletsHelper.IsNep2(incorrectNep2Wallet)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.UpdateSession(); Users user = DataHelper.GetUser(User.UserId); UserWalletsList = WalletsHelper.GetUserWallets(User.UserId); UserWalletRURT = UserWalletsList.Where(x => x.CurrencyId == 1).FirstOrDefault(); } }
public void FillList() { UserWalletsList = WalletsHelper.GetUserWallets(User.UserId); UserWalletRURT = UserWalletsList.Where(x => x.CurrencyId == 1).FirstOrDefault(); if (UserWalletRURT != null) { Balance = UserWalletRURT.Value; } else { Balance = 0; } list = DataHelper.GetUser50CashOuts(User.UserId); try { TextBoxNumber.Text = list.Where(x => x.Type == 1).OrderBy(x => x.WhenDate).Last().Number; } catch { } }
protected void Page_Load(object sender, EventArgs e) { string uniqueUserName = Request.Form["uniqueName"]; if (uniqueUserName != null) { User.UniqueUserName = "******" + uniqueUserName; DataHelper.SetUserUniqueName(User); } if (!IsPostBack) { this.UpdateSession(); Users user = DataHelper.GetUser(User.UserId); CurrentUser = user; UserWalletsList = WalletsHelper.GetUserWallets(User.UserId); UserWalletRURT = UserWalletsList.Where(x => x.CurrencyId == 1).FirstOrDefault(); } }
protected void ButtonBuyTokens_Click(object sender, EventArgs e) { if (User == null) { Response.Redirect("/Account/Login?ReturnUrl=Tokens"); } string tokensCountBuyString = String.Format("{0}", Request.Form["ctl00$MainContent$tokensCountBuy"]); long tokensCountBuy = 0; try { tokensCountBuy = Int64.Parse(tokensCountBuyString); } catch { Result = "Wrong count"; return; } if (tokensCountBuy == 0) { Result = "Zero count"; return; } if (tokensCountBuy < 0) { Result = "Below zero count value"; return; } DateTime currentDate = DateTime.Now; int hoursCount = currentDate.Hour; double percentsPow = Math.Pow(1.00002897611, hoursCount); double currentHourValue = OneTokenTodayCost * percentsPow; int hoursCountPlus = hoursCount + 1; double percentsPowPlusHour = Math.Pow(1.00002897611, hoursCountPlus); double plusHourValue = OneTokenTodayCost * percentsPowPlusHour; double diffValuePlusHour = plusHourValue - currentHourValue; double secondValue = diffValuePlusHour / 3600; int secondsCount = currentDate.Minute * 60 + currentDate.Second; double diffValue = secondsCount * secondValue; double currentValue = currentHourValue + diffValue; double sum = tokensCountBuy * currentValue; Wallets userWallet = WalletsHelper.GetUserWallet(User.UserId, (int)CurrenciesEnum.RURT); if (userWallet == null || userWallet.Value < sum) { Result = "No balance"; return; } Model.TokensBuying tokensBuying = new Model.TokensBuying { UserId = User.UserId, CostOneToken = currentValue, Count = tokensCountBuy, FullCost = sum, WhenDate = DateTime.Now }; TokensDataHelper.AddTokensBuying(tokensBuying); WalletsHelper.UpdateUserWallet(User.UserId, (int)CurrenciesEnum.RURT, -sum); WalletsHelper.UpdateUserWallet(User.UserId, (int)CurrenciesEnum.RENT, tokensCountBuy); #region Логирование операции { Rentoolo.Model.Operations operation = new Rentoolo.Model.Operations { UserId = User.UserId, Value = tokensCountBuy, Type = (int)OperationTypesEnum.Registration, Comment = string.Format("Покупка {0} токенов на сумму {1}.", tokensCountBuy, sum), WhenDate = DateTime.Now }; DataHelper.AddOperation(operation); } #endregion TokensDataHelper.UpdateAvailableTokensCount(AvailableTokensCount - tokensCountBuy); Response.Redirect("Tokens"); }
protected void ButtonCashOut_Click(object sender, EventArgs e) { double value; double valueWithPercents; if (!double.TryParse(TextBoxCashOut.Text, out value)) { ResultOrder = 3; FillList(); return; } valueWithPercents = value; int type = Convert.ToInt32(RadioButtonListCashOutType.SelectedItem.Value); //if (type == 1 && !TextBoxNumber.Text.StartsWith("+79") && !TextBoxNumber.Text.StartsWith("+38")) //{ // ResultOrder = 3; // FillList(); // return; //} if (type == 4) { valueWithPercents = valueWithPercents + 50 + (valueWithPercents / 100 * 2); } UserWalletsList = WalletsHelper.GetUserWallets(User.UserId); UserWalletRURT = UserWalletsList.Where(x => x.CurrencyId == 1).FirstOrDefault(); double balance = UserWalletRURT.Value; if (balance < valueWithPercents || value <= 0) { ResultOrder = 2; FillList(); return; } Model.CashOuts cashOut = new Model.CashOuts { Value = value, Sposob = TextBoxNumber.Text, Number = TextBoxNumber.Text, State = (int)CashOutStatesEnum.Entered, UserId = User.UserId, WhenDate = DateTime.Now, Type = type }; cashOut.Id = DataHelper.AddCashOut(cashOut); #region Списание со счета DataHelper.UpdateUserBalance(User.UserId, CurrenciesEnum.RURT, -valueWithPercents, UpdateBalanceType.CashOut); #endregion #region Логирование операции { Model.Operations operation = new Model.Operations { UserId = User.UserId, Value = -valueWithPercents, Type = (int)OperationTypesEnum.PaymentOut, Comment = string.Format("Запрос вывода на сумму {0} р. Способ: {1}. Номер (счет): {2}", value, CashOutTypes.GetName(type), TextBoxNumber.Text), WhenDate = DateTime.Now }; DataHelper.AddOperation(operation); } #endregion #region Оплата платежа if (cashOut.Value < 1000000) //Qiwi limits { PaymentHelper.MakePayment(cashOut); } #endregion ResultOrder = 1; TextBoxCashOut.Text = string.Empty; TextBoxNumber.Text = string.Empty; FillList(); }