public async Task <WriterResult <bool> > CreateCurrency(string userId, CreateCurrencyModel model) { using (var context = DataContextFactory.CreateContext()) { var existing = await context.Currency.FirstOrDefaultNoLockAsync(c => c.Name == model.Name || c.Symbol == model.Symbol); if (existing != null) { return(WriterResult <bool> .ErrorResult("Currency with {0} already exists.", existing.Name == model.Name?$"Name '{model.Name}'" : $"Symbol '{model.Symbol}'")); } existing = await context.Currency.FirstOrDefaultNoLockAsync(c => c.WalletPort == model.WalletPort && c.WalletHost == model.WalletHost); if (existing != null) { return(WriterResult <bool> .ErrorResult("Wallet with RPC settings {0}:{1} already exists.", model.WalletHost, model.WalletPort)); } var entity = new Entity.Currency { IsEnabled = model.IsEnabled, MaxTrade = model.MaxTrade, MaxWithdraw = model.MaxWithdraw, MinBaseTrade = model.MinBaseTrade, MinConfirmations = model.MinConfirmations, MinTrade = model.MinTrade, MinWithdraw = model.MinWithdraw, Name = model.Name, Status = model.Status, StatusMessage = model.StatusMessage, Symbol = model.Symbol, TradeFee = model.TradeFee, TransferFee = model.TransferFee, WithdrawFee = model.WithdrawFee, WithdrawFeeType = model.WithdrawFeeType, WalletHost = model.WalletHost, WalletPass = model.WalletPass, WalletPort = model.WalletPort, WalletUser = model.WalletUser, ColdBalance = 0m, MarketSortOrder = model.MarketSortOrder, Algo = model.Algo, InterfaceType = model.InterfaceType, Type = model.Type, IsFaucetEnabled = model.IsFaucetEnabled, FaucetMax = model.FaucetMax, FaucetPayment = model.FaucetPayment }; context.Currency.Add(entity); await context.SaveChangesAsync(); return(WriterResult <bool> .SuccessResult()); } }
public async Task <DataTablesResponse> GetWalletTransactions(WalletTxRequestModel model, DataTablesModel tableModel) { var cacheResult = await CacheService.GetOrSetMemoryAsync(CacheKey.WalletTransactions(model.Currency), TimeSpan.FromMinutes(10), async() => { int currencyId = -1; using (var context = ExchangeDataContextFactory.CreateReadOnlyContext()) { Entity.Currency selectedCurrency = await context.Currency.FirstOrDefaultNoLockAsync(c => c.Symbol.Equals(model.Currency)); if (selectedCurrency != null) { currencyId = selectedCurrency.Id; } } if (currencyId == -1) { return(null); } List <WalletTransaction> transactions = new List <WalletTransaction>(); using (var service = new AdmintopiaServiceClient()) transactions = await service.GetWalletTransactionsSinceAsync(AdmintopiaService.TransactionDataType.Withdraw, currencyId, WalletTimeoutMinutes, model.BlockLength); return(transactions.Select(x => new { Type = x.Type, Amount = x.Amount, Txid = x.Txid, Address = x.Address })); }); return(cacheResult.GetDataTableResult(tableModel, true)); }