public async Task <ActionResult> Index(FaucetViewModel model) { var mvcCaptcha = new MvcCaptcha(nameof(FaucetViewModel)); if (!mvcCaptcha.Validate(model.CaptchaCode)) { ModelState.AddModelError(nameof(model.CaptchaCode), "Invalid captcha"); return(View(model)); } if (!model.To.IsValidEthereumAddressHexFormat()) { ModelState.AddModelError(nameof(model.To), "Invalid address"); return(View(model)); } var rskService = new RskService(); var transaction = await rskService.SendTransaction(model.To, 0.001m); model.TransactionHash = transaction; return(View(model)); }
public async Task <ActionResult> Index(FaucetViewModel faucetViewModel) { if (ModelState.IsValid) { var account = new Account(settings.FunderPrivateKey); var web3 = new Web3(account, settings.EthereumAddress); var balance = await web3.Eth.GetBalance.SendRequestAsync(faucetViewModel.Address); if (Web3.Convert.FromWei(balance.Value) > settings.MaxAmountToFund) { ModelState.AddModelError("address", "Account cannot be funded, already has more than " + settings.MaxAmountToFund + " ether"); return(View(faucetViewModel)); } var txnHash = await web3.Eth.TransactionManager.SendTransactionAsync(account.Address, faucetViewModel.Address, new HexBigInteger(Web3.Convert.ToWei(settings.AmountToFund))); faucetViewModel.TransactionHash = txnHash; faucetViewModel.Amount = settings.AmountToFund; return(View(faucetViewModel)); } else { return(View("Index")); } }
public async Task <ActionResult> Index(FaucetViewModel faucetViewModel) { if (ModelState.IsValid) { var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"; var ethereumAddress = "0x12890d2cce102216644c59dae5baed380d84830c"; var maxAmountToFund = 100; var amountToFund = 10; var account = new Account(privateKey); var web3 = new Web3.Web3(account); var balance = await web3.Eth.GetBalance.SendRequestAsync(faucetViewModel.Address); if (Web3.Web3.Convert.FromWei(balance.Value) > maxAmountToFund) { ModelState.AddModelError("address", "Account cannot be funded, already has more than " + maxAmountToFund + " ether"); return(View(faucetViewModel)); } var txnHash = await web3.Eth.TransactionManager.SendTransactionAsync(account.Address, faucetViewModel.Address, new HexBigInteger(Web3.Web3.Convert.ToWei(amountToFund))); faucetViewModel.TransactionHash = txnHash; faucetViewModel.Amount = amountToFund; return(View(faucetViewModel)); } else { return(View("Index")); } }
public IActionResult Index() { FaucetViewModel model = new FaucetViewModel() { FaucetAddrees = simpleWallet.Address.ToLower(), FaucetBallance = GetBallance() }; return(View(model)); }
public IActionResult Index(FaucetViewModel model) { try { model.Clear(); string userIP = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); if (LastFaucetRequest.ContainsKey(userIP) && LastFaucetRequest[userIP].Add(MinRequestTime) > DateTime.Now) {//we have error throw new ValidationException(model.ErrorMessage = $"Cannot request money form ip: {userIP} untill {LastFaucetRequest[userIP].Add(MinRequestTime)}"); } var transaction = simpleWallet.Sign(model.ReceiverAddrees, 5 * Token.OneToken); var result = MakePost(NodeAddress + "/api/transaction/new", transaction); if (result) { model.SuccessMessage = "Money were send to " + model.ReceiverAddrees; LastFaucetRequest[userIP] = DateTime.Now; } else { model.ErrorMessage = "Transaction not send"; } } catch (ValidationException ex) { model.ErrorMessage = ex.Message; } catch (Exception ex) { model.ErrorMessage = "Error occured. No money. Sorry"; } model.FaucetBallance = GetBallance(); return(View(model)); }