/// <summary> /// Withdraw coin /// </summary> /// <param name="sender"></param> /// <param name="amount"></param> /// <param name="recipientId"></param> /// <returns></returns> private async Task cmd_Withdraw(ApplicationUser sender, double amount, string recipientId) { RiseManager rm = new RiseManager(); try { if (amount > 0 && !string.IsNullOrEmpty(recipientId)) { await _botService.Client.SendChatActionAsync(sender.TelegramId, ChatAction.Typing); var balance = await rm.AccountBalanceAsync(sender.Address); if (balance >= (amount + 0.1)) { var tx = await rm.CreatePaimentAsync(amount * 100000000, sender.GetSecret(), recipientId); if (tx.success) { await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Successfully sent <b>" + amount + "</b> RISE to " + recipientId, ParseMode.Html); var keyboard = new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("See Transaction", "https://explorer.rise.vision/tx/" + tx.transactionId)); await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Transaction Id:" + tx.transactionId + "", replyMarkup : keyboard); } else { await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Error withdrawing <b>" + amount + "</b> RISE to " + recipientId + " try to reduce the amount...", ParseMode.Html); } } else { await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Not enough RISE to Withdraw <b>" + amount + "</b> RISE balance" + balance + " RISE", ParseMode.Html); } } else { await _botService.Client.SendTextMessageAsync(sender.TelegramId, "Please specify amount and address ex: !withdraw 10 5953135380169360325R", ParseMode.Html); } } catch (Exception ex) { var log = new Log(); log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException); _appdb.Logger.Add(log); _appdb.SaveChangesAsync().Wait(); } }
/// <summary> /// Send Coin /// </summary> /// <param name="message"></param> /// <param name="sender"></param> /// <param name="amount"></param> /// <param name="destusers"></param> /// <param name="bannerMsg"></param> /// <returns></returns> private async Task cmd_Send(Message message, ApplicationUser sender, double amount, IReadOnlyCollection <ApplicationUser> destusers, string bannerMsg = "") { await _botService.Client.SendChatActionAsync(sender.TelegramId, ChatAction.Typing); var amountToSend = amount / destusers.Count; foreach (var destuser in destusers.Where(x => x.Address != null)) { try { var secret = sender.GetSecret(); RiseManager rm = new RiseManager(); var tx = await rm.CreatePaimentAsync(amountToSend * 100000000, secret, destuser.Address); if (tx != null && tx.success) { await _botService.Client.SendTextMessageAsync(destuser.TelegramId, "You received " + amountToSend + " from @" + sender.UserName, ParseMode.Html); var keyboard = new InlineKeyboardMarkup(InlineKeyboardButton.WithUrl("See Transaction", "https://explorer.rise.vision/tx/" + tx.transactionId)); await _botService.Client.SendTextMessageAsync(destuser.TelegramId, "Transaction Id:" + tx.transactionId, replyMarkup : keyboard); } else { var log = new Log(); log.LogMessage("Error processing transaction for " + destuser.UserName + " Id:" + destuser.TelegramId); _appdb.Logger.Add(log); _appdb.SaveChangesAsync().Wait(); } } catch (Exception ex) { var log = new Log(); log.LogMessage(ex.Message + " " + ex.StackTrace + " " + ex.InnerException); _appdb.Logger.Add(log); _appdb.SaveChangesAsync().Wait(); } } var destUsersUsername = string.Join(",", destusers.Select(x => "@" + x.UserName)); await _botService.Client.SendTextMessageAsync(message.Chat.Id, destUsersUsername + " " + bannerMsg + " @" + sender.UserName + " sent you <b>" + Math.Round(amountToSend, 3) + " RISE</b> :)", ParseMode.Html); }