private static List <NxtTransferable> GetTransferables(IEnumerable <TransferableConfig> currencyConfigs, IEnumerable <TransferableConfig> assetConfigs, INxtConnector nxtConnector) { var transferables = new List <NxtTransferable>(); Task.Run(async() => { foreach (var currencyConfig in currencyConfigs) { transferables.Add(await nxtConnector.GetCurrency(currencyConfig)); } foreach (var assetConfig in assetConfigs) { transferables.Add(await nxtConnector.GetAsset(assetConfig)); } }).Wait(); return(transferables); }
private async Task Withdraw(SlackUser slackUser, SlackIMSession imSession, Match match) { var address = match.Groups[1].Value; var amountToWithdraw = decimal.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture); var unit = string.IsNullOrEmpty(match.Groups[3].Value) ? Nxt.Singleton.Name : match.Groups[3].Value; var transferable = transferables.GetTransferable(unit); var account = await walletRepository.GetAccount(slackUser.Id); if (account == null) { await SlackConnector.SendMessage(imSession.Id, MessageConstants.NoAccount); return; } if (transferable == null && unit.IsNumeric()) { var id = ulong.Parse(unit); try { var asset = await nxtConnector.GetAsset(new TransferableConfig(id, "", "", new List <string>(), new List <TipReaction>())); transferable = asset; } catch (Exception) { try { var currency = await nxtConnector.GetCurrency(new TransferableConfig(id, "", "", new List <string>(), new List <TipReaction>())); transferable = currency; } catch (Exception) { } } } if (!(await VerifyParameters(transferable, unit, account, imSession.Id, amountToWithdraw))) { return; } try { var txId = await nxtConnector.Transfer(account, address, transferable, amountToWithdraw, "withdraw from slack tipper"); await SlackConnector.SendMessage(imSession.Id, MessageConstants.Withdraw(amountToWithdraw, transferable.Name, txId), false); } catch (ArgumentException e) { if (e.Message.Contains("not a valid reed solomon address")) { await SlackConnector.SendMessage(imSession.Id, MessageConstants.InvalidAddress); } else { logger.LogError(0, e, e.Message); throw; } } catch (NxtException e) { logger.LogError(0, e, e.Message); throw; } }