示例#1
0
        public async Task <ActionResult> UpdateWorker(int id)
        {
            var pools = await PoolReader.GetPools();

            var worker = await PoolWorkerReader.AdminGetWorker(User.Identity.GetUserId(), id);

            var poolconnection = await PoolReader.GetPoolConnection(worker.AlgoType);

            return(View("UpdateWorkerModal", new AdminPoolWorkerUpdateModel
            {
                Id = id,
                Name = worker.Name,
                AlgoType = worker.AlgoType,
                IsAutoSwitch = worker.IsAutoSwitch,
                Password = worker.Password,
                TargetDifficulty = worker.TargetDifficulty,
                DefaultDiff = poolconnection.DefaultDiff,
                FixedDiffSummary = poolconnection.FixedDiffSummary,
                VarDiffHighSummary = poolconnection.VarDiffHighSummary,
                VarDiffLowSummary = poolconnection.VarDiffLowSummary,
                VarDiffMediumSummary = poolconnection.VarDiffMediumSummary,
                DifficultyOption = PoolExtensions.TargetDifficultyToOption(worker.TargetDifficulty),
                TargetPool = worker.TargetPool,
                Pools = pools.Where(x => x.AlgoType == worker.AlgoType).OrderBy(x => x.Symbol).ToList()
            }));
        }
        public async Task <ActionResult> UpdateConnection(AlgoType algoType)
        {
            var model = await PoolReader.GetPoolConnection(algoType);

            if (model == null)
            {
                return(ViewMessageModal(new ViewMessageModel(ViewMessageType.Danger, "Error", $"Connection #{algoType} not found")));
            }

            var pools = await PoolReader.GetPools();

            return(View("UpdatePoolConnectionModal", new AdminUpdatePoolConnectionModel
            {
                AlgoType = model.AlgoType,
                Host = model.Host,
                Name = model.Name,
                Port = model.Port,
                DefaultDiff = model.DefaultDiff,
                DefaultPool = model.DefaultPool,
                FixedDiffSummary = model.FixedDiffSummary,
                VarDiffHighSummary = model.VarDiffHighSummary,
                VarDiffLowSummary = model.VarDiffLowSummary,
                VarDiffMediumSummary = model.VarDiffMediumSummary,
                Pools = pools.Where(x => x.AlgoType == algoType).OrderBy(x => x.Symbol).ToList()
            }));
        }
        public async Task <PaytopiaPaymentModel> AdminGetPayment(int id)
        {
            using (var context = DataContextFactory.CreateReadOnlyContext())
            {
                var item = await context.PaytopiaPayments
                           .AsNoTracking()
                           .Where(x => x.Id == id)
                           .Select(payment => new PaytopiaPaymentModel
                {
                    Id            = payment.Id,
                    Type          = payment.PaytopiaItem.Type,
                    CurrencyId    = payment.PaytopiaItem.CurrencyId,
                    Amount        = payment.Amount,
                    Status        = payment.Status,
                    UserName      = payment.User.UserName,
                    IsAnonymous   = payment.IsAnonymous,
                    Begins        = payment.Begins,
                    Ends          = payment.Ends,
                    Timestamp     = payment.Timestamp,
                    TransferId    = payment.TransferId,
                    RefundId      = payment.RefundId,
                    ReferenceCode = payment.ReferenceCode,
                    ReferenceId   = payment.ReferenceId,
                    RefundReason  = payment.RefundReason,
                    RequestData   = payment.RequestData,
                }).FirstOrDefaultNoLockAsync().ConfigureAwait(false);

                var currency = await CurrencyReader.GetCurrency(item.CurrencyId).ConfigureAwait(false);

                item.Symbol = currency.Symbol;

                if (item.ReferenceId > 0)
                {
                    if (item.Type == PaytopiaItemType.FeaturedCurrency || item.Type == PaytopiaItemType.LottoSlot || item.Type == PaytopiaItemType.RewardSlot || item.Type == PaytopiaItemType.TipSlot)
                    {
                        var refCurrency = await CurrencyReader.GetCurrency(item.ReferenceId).ConfigureAwait(false);

                        if (refCurrency != null)
                        {
                            item.ReferenceName   = refCurrency.Name;
                            item.ReferenceAlgo   = refCurrency.AlgoType;
                            item.ReferenceSymbol = refCurrency.Symbol;
                        }
                    }
                    else if (item.Type == PaytopiaItemType.FeaturedPool || item.Type == PaytopiaItemType.PoolListing)
                    {
                        var refPool = await PoolReader.GetPool(item.ReferenceId).ConfigureAwait(false);

                        if (refPool != null)
                        {
                            item.ReferenceName   = refPool.Name;
                            item.ReferenceAlgo   = refPool.AlgoType;
                            item.ReferenceSymbol = refPool.Symbol;
                        }
                    }
                }

                return(item);
            }
        }
示例#4
0
        public async Task <IWriterResult> ChangeUserPool(string userId, ChangePoolModel model)
        {
            var currentUser = new Guid(userId);

            using (var context = PoolDataContextFactory.CreateContext())
            {
                var pool = await PoolReader.GetPool(model.PoolId).ConfigureAwait(false);

                if (pool.Status != PoolStatus.OK)
                {
                    return(new WriterResult(false, $"Pool #{model.PoolId} not found."));
                }

                var userWorkers = await context.Worker.Where(x => x.UserId == currentUser && x.AlgoType == pool.AlgoType && x.IsEnabled).ToListNoLockAsync().ConfigureAwait(false);

                foreach (var worker in userWorkers)
                {
                    if (model.AllWorkers || model.SelectedWorkers.Contains(worker.Id))
                    {
                        worker.TargetPool = pool.Symbol;
                    }
                }
                await context.SaveChangesAsync().ConfigureAwait(false);

                var message = model.AllWorkers
                                        ? $"Successfully moved all workers to the {pool.Name}({pool.Symbol}) pool."
                                        : $"Successfully moved selected workers to the {pool.Name}({pool.Symbol}) pool.";
                return(new WriterResult(true, message));
            }
        }
示例#5
0
        public async Task <ActionResult> GetMiners()
        {
            var connections = await PoolReader.GetPoolConnections();

            return(PartialView("_Miners", new Cryptopia.Common.Mineshaft.MinersModel
            {
                Connections = connections
            }));
        }
示例#6
0
        public async Task <ActionResult> CreateWorker()
        {
            var connections = await PoolReader.GetPoolConnections();

            return(View("CreateWorkerModal", new PoolWorkerCreateModel
            {
                AlgoTypes = connections.Select(x => x.AlgoType).Distinct().ToList(),
                Connections = connections
            }));
        }
        public async Task <ActionResult> UpdateWorkerPool(AlgoType algoType)
        {
            var pools = await PoolReader.GetPools();

            return(View("UpdateWorkerPoolModal", new AdminUpdateWorkerPoolModel
            {
                AlgoType = algoType,
                Pools = pools.Where(x => x.AlgoType == algoType).OrderBy(x => x.Symbol).ToList()
            }));
        }
        public async Task <ActionResult> UpdatePool(int id)
        {
            var model = await PoolReader.AdminGetPool(id);

            if (model == null)
            {
                return(ViewMessageModal(new ViewMessageModel(ViewMessageType.Danger, "Error", $"Payment #{id} not found")));
            }

            return(View("UpdatePoolModal", model));
        }
        public async Task <List <PoolListingItemModel> > GetPoolListingItems()
        {
            var pools = await PoolReader.GetPools().ConfigureAwait(false);

            return(pools.Select(x => new PoolListingItemModel
            {
                Id = x.Id,
                Name = $"{x.Symbol} ({x.AlgoType})"
            })
                   .OrderBy(x => x.Name)
                   .ToList());
        }
示例#10
0
        public async Task <ActionResult> UpdateWorkerPool(int id)
        {
            var pools = await PoolReader.GetPools();

            var worker = await PoolWorkerReader.GetWorker(User.Identity.GetUserId(), id);

            return(View("UpdateWorkerPoolModal", new PoolWorkerUpdatePoolModel
            {
                Id = id,
                Name = worker.Name,
                AlgoType = worker.AlgoType,
                TargetPool = worker.TargetPool,
                Pools = pools.Where(x => x.AlgoType == worker.AlgoType && (x.Status == PoolStatus.OK || x.Status == PoolStatus.Expiring)).OrderBy(x => x.Symbol).ToList()
            }));
        }
        public async Task <ActionResult> GettingStarted(int poolId)
        {
            var pool = await PoolReader.GetPool(poolId);

            var connection = await PoolReader.GetPoolConnection(pool.AlgoType);

            return(View("GettingStartedModal", new GettingStartedModel
            {
                PoolId = pool.Id,
                PoolName = pool.Name,
                PoolSymbol = pool.Symbol,
                AlgoType = pool.AlgoType,
                Port = connection.Port,
                StratumUrl = connection.Host
            }));
        }
        public async Task <ActionResult> UpdateSettings()
        {
            var settings = await PoolReader.GetPoolSettings();

            return(View("UpdateSettingsModal", new AdminUpdatePoolSettingsModel
            {
                ProcessorEnabled = settings.ProcessorEnabled,
                HashRateCalculationPeriod = settings.HashRateCalculationPeriod,
                StatisticsPollPeriod = settings.StatisticsPollPeriod,
                PayoutPollPeriod = settings.PayoutPollPeriod,
                SitePayoutPollPeriod = settings.SitePayoutPollPeriod,
                ProfitabilityPollPeriod = settings.ProfitabilityPollPeriod,
                ProfitSwitchEnabled = settings.ProfitSwitchEnabled,
                ProfitSwitchDepthBTC = settings.ProfitSwitchDepthBTC,
                ProfitSwitchDepthLTC = settings.ProfitSwitchDepthLTC
            }));
        }
示例#13
0
        public async Task <ActionResult> UpdateWorkerPool(PoolWorkerUpdatePoolModel model)
        {
            if (!ModelState.IsValid)
            {
                var pools = await PoolReader.GetPools();

                model.Pools = pools.Where(x => x.AlgoType == model.AlgoType && (x.Status == PoolStatus.OK || x.Status == PoolStatus.Expiring)).OrderBy(x => x.Symbol).ToList();
                return(View("UpdateWorkerPoolModal", model));
            }

            var result = await PoolWorkerWriter.UpdateWorkerPool(User.Identity.GetUserId(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("UpdateWorkerPoolModal", model));
            }

            return(CloseModal(result));
        }
        public async Task <ActionResult> ChangeUserPool(int poolId)
        {
            var pool = await PoolReader.GetPool(poolId);

            var workers = await PoolWorkerReader.GetWorkers(User.Identity.GetUserId(), pool.AlgoType);

            if (workers.IsNullOrEmpty())
            {
                return(ViewMessageModal(new ViewMessageModel(ViewMessageType.Warning, "No Workers Configured", "You do not have any workers configured, please create a worker in your accounts 'Miners' section")));
            }

            return(View("ChangePoolModal", new ChangePoolModel
            {
                PoolId = pool.Id,
                PoolName = pool.Name,
                PoolSymbol = pool.Symbol,
                AlgoType = pool.AlgoType,
                Workers = workers,
                AllWorkers = true,
                SelectedWorkers = new List <int>()
            }));
        }
示例#15
0
        public async Task <ActionResult> CreateWorker(PoolWorkerCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                var connections = await PoolReader.GetPoolConnections();

                model.AlgoTypes   = connections.Select(x => x.AlgoType).Distinct().ToList();
                model.Connections = connections;
                return(View("CreateWorkerModal", model));
            }

            model.FullName         = string.Format("{0}.{1}", User.Identity.Name, model.Name);
            model.TargetDifficulty = PoolExtensions.OptionToTargetDifficulty(model.DifficultyOption, model.TargetDifficulty);
            var result = await PoolWorkerWriter.CreateWorker(User.Identity.GetUserId(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("CreateWorkerModal", model));
            }

            return(CloseModal(result));
        }
        public async Task <List <FeaturedSlotItemModel> > GetFeaturedPoolSlotItems()
        {
            using (var context = DataContextFactory.CreateReadOnlyContext())
            {
                var slotDetail = await context.PaytopiaPayments
                                 .AsNoTracking()
                                 .Where(x => x.PaytopiaItem.Type == PaytopiaItemType.FeaturedPool && x.Ends > DateTime.UtcNow)
                                 .GroupBy(x => x.ReferenceId)
                                 .ToListNoLockAsync().ConfigureAwait(false);

                var pools = await PoolReader.GetPools().ConfigureAwait(false);

                var results = new List <FeaturedSlotItemModel>();
                foreach (var pool in pools.DistinctBy(x => x.Symbol))
                {
                    var isActive           = false;
                    var slotSummary        = string.Empty;
                    var existingSlotDetail = slotDetail.FirstOrDefault(x => x.Key == pool.Id);
                    if (existingSlotDetail != null && existingSlotDetail.Any())
                    {
                        isActive    = existingSlotDetail.Any(x => x.Begins < DateTime.UtcNow.Date && DateTime.UtcNow.Date < x.Ends);
                        slotSummary = string.Join(",", existingSlotDetail.Select(x => $"Week: {x.Begins.WeekOfYear()} ({x.Begins.ToString("dd/MM/yyyy")} - {x.Ends.ToString("dd/MM/yyyy")})"));
                    }

                    var nextFreeSlot = PaytopiaWriter.GetNextFreeSlot(pool.Id, slotDetail.FirstOrDefault(x => x.Key == pool.Id));
                    results.Add(new FeaturedSlotItemModel
                    {
                        Id            = pool.Id,
                        Name          = pool.Symbol,
                        IsFeatured    = isActive,
                        NextSlotWeek  = nextFreeSlot.Begin.WeekOfYear(),
                        NextSlotBegin = nextFreeSlot.Begin,
                        NextSlotEnd   = nextFreeSlot.End,
                        SlotSummary   = slotSummary
                    });
                }
                return(results);
            }
        }
示例#17
0
        public async Task <ActionResult> UpdateWorker(PoolWorkerUpdateModel model)
        {
            if (!ModelState.IsValid)
            {
                var poolconnection = await PoolReader.GetPoolConnection(model.AlgoType);

                model.FixedDiffSummary     = poolconnection.FixedDiffSummary;
                model.VarDiffHighSummary   = poolconnection.VarDiffHighSummary;
                model.VarDiffLowSummary    = poolconnection.VarDiffLowSummary;
                model.VarDiffMediumSummary = poolconnection.VarDiffMediumSummary;
                return(View("UpdateWorkerModal", model));
            }

            model.TargetDifficulty = PoolExtensions.OptionToTargetDifficulty(model.DifficultyOption, model.TargetDifficulty);
            var result = await PoolWorkerWriter.UpdateWorker(User.Identity.GetUserId(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("UpdateWorkerModal", model));
            }

            return(CloseModal(result));
        }
示例#18
0
 public async Task <ActionResult> GetPayouts(DataTablesModel param)
 {
     return(DataTable(await PoolReader.GetPayouts(User.Identity.GetUserId(), param)));
 }
 public async Task <ActionResult> GetPayments(DataTablesModel model)
 {
     return(DataTable(await PoolReader.AdminGetPayouts(User.Identity.GetUserId(), model)));
 }
 public async Task <ActionResult> GetBlocks(DataTablesModel param, int poolId)
 {
     return(DataTable(await PoolReader.GetBlocks(param, poolId)));
 }
        public async Task <MineshaftSummary> GetMineshaftSummary()
        {
            var cacheResult = await CacheService.GetOrSetHybridAsync(CacheKey.MineshaftSummary(), TimeSpan.FromSeconds(10), async() =>
            {
                var poolData = new List <MineshaftSummaryModel>();
                using (var context = PoolDataContextFactory.CreateContext())
                {
                    poolData = await context.Pool
                               .AsNoTracking()
                               .Where(x => x.IsEnabled)
                               .Select(x => new MineshaftSummaryModel
                    {
                        AlgoType    = x.AlgoType,
                        PoolId      = x.Id,
                        Symbol      = x.Symbol,
                        Name        = x.Name,
                        Hashrate    = (double?)x.Statistics.Hashrate ?? 0,
                        Luck        = (double?)x.Blocks.OrderByDescending(b => b.Height).Take(25).Average(b => b.Luck) ?? 0,
                        BlocksFound = x.Blocks.Count,
                        Miners      = (int?)x.UserStatistics.Count(b => b.Hashrate > 0) ?? 0
                    }).ToListNoLockAsync().ConfigureAwait(false);
                }

                var algoPoolData = poolData.GroupBy(x => x.AlgoType)
                                   .Select(x => new
                {
                    AlgoType      = x.Key,
                    TopPool       = x.OrderByDescending(b => b.Hashrate).FirstOrDefault(),
                    TotalHashrate = (double?)x.Sum(b => b.Hashrate) ?? 0
                });

                var now           = DateTime.UtcNow;
                var pools         = await PoolReader.GetPools().ConfigureAwait(false);
                var currencies    = await CurrencyReader.GetCurrencies().ConfigureAwait(false);
                var featuredPools = pools.Any(x => x.FeaturedExpires > now)
                                        ? pools.Where(x => x.FeaturedExpires > now).Select(x => new FeaturedPool(currencies.FirstOrDefault(c => c.CurrencyId == x.CurrencyId)))
                                        : pools.Where(x => x.CurrencyId == 2).Select(x => new FeaturedPool(currencies.FirstOrDefault(c => c.CurrencyId == x.CurrencyId)));

                var totalHashrate = pools.Sum(x => x.Hashrate);
                var topPools      = poolData.OrderByDescending(x => x.Miners).Take(5).ToList();
                var algoInfo      = algoPoolData.Select(x => new AlgoTypeInfo
                {
                    Name          = x.AlgoType.ToString(),
                    AlgoType      = x.AlgoType,
                    TotalHashrate = x.TotalHashrate,
                    TopPoolSymbol = x.TopPool.Symbol
                }).ToList();

                algoInfo.Insert(0, new AlgoTypeInfo
                {
                    Name          = "All Pools",
                    AlgoType      = null,
                    TopPoolSymbol = topPools.FirstOrDefault()?.Symbol,
                    TotalHashrate = totalHashrate
                });

                var model = new MineshaftSummary
                {
                    TotalPools    = pools.Count,
                    TotalHashrate = totalHashrate,
                    AlgoTypes     = algoInfo,
                    TopPools      = topPools,
                    Featured      = featuredPools.ToList()
                };
                return(model);
            }).ConfigureAwait(false);

            return(cacheResult);
        }
 public async Task <ActionResult> GetConnections(DataTablesModel model)
 {
     return(DataTable(await PoolReader.GetPoolConnections(model)));
 }