Ejemplo n.º 1
0
        public async Task <IActionResult> WordingAsync(
            string id,
            GetBaseRequest request,
            [FromServices] KyubeyContext db,
            [FromServices] TokenRepositoryFactory tokenRepositoryFactory,
            CancellationToken cancellationToken)
        {
            var dbToken = await db.Tokens.FirstOrDefaultAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken);

            if (dbToken == null)
            {
                return(ApiResult(404, "not found this token"));
            }
            var tokenRepository = await tokenRepositoryFactory.CreateAsync(request.Lang);

            var banners = tokenRepository.GetTokenIncubationBannereRelativePaths(id, request.Lang).Select(x => $"/token_assets/" + x).ToList();

            var updates = tokenRepository.GetTokenIncubatorUpdates(id, request.Lang)?.OrderBy(x => x.Time)?.OrderByDescending(x => x.Time).ToList();

            var response = new GetWordingResponse()
            {
                TokenId     = id,
                Description = tokenRepository.GetTokenDescription(id, request.Lang),
                Detail      = tokenRepository.GetTokenIncubationDetail(id, request.Lang),
                Updates     = updates,
                Sliders     = banners
            };

            return(ApiResult(response));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> InfoAsync(
            string id,
            [FromQuery] string username,
            GetBaseRequest request,
            [FromServices] KyubeyContext db,
            [FromServices] TokenRepositoryFactory tokenRepositoryFactory,
            [FromServices] NodeApiInvoker nodeApiInvoker,
            [FromServices] ILogger logger,
            CancellationToken cancellationToken)
        {
            var dbToken = await db.Tokens.FirstOrDefaultAsync(x => x.Id == id && x.Status == TokenStatus.Active, cancellationToken);

            if (dbToken == null)
            {
                return(ApiResult(404, "not found this token"));
            }

            var tokenRepository = await tokenRepositoryFactory.CreateAsync(request.Lang);

            var tokenInfo      = tokenRepository.GetSingle(id);
            var supporterCount = await db.RaiseLogs.Where(x =>
                                                          (x.Timestamp > (tokenInfo.Incubation.Begin_Time ?? DateTime.MinValue) &&
                                                           x.Timestamp < tokenInfo.Incubation.DeadLine) &&
                                                          x.TokenId == dbToken.Id && !x.Account.StartsWith("eosio.")).Select(x => x.Account).Distinct().CountAsync();

            GetSymbolSupplyResponse symbolSupply = null;
            TokenContractPriceModel currentPrice = null;
            var eosBalance   = 0.0;
            var tokenBalance = 0.0;

            try
            {
                symbolSupply = await nodeApiInvoker.GetSymbolSupplyAsync(tokenInfo?.Basic?.Contract?.Transfer, id, cancellationToken);

                currentPrice = await tokenRepository.GetContractPriceAsync(id);

                eosBalance = await nodeApiInvoker.GetCurrencyBalanceAsync(username, "eosio.token", "EOS", cancellationToken);

                tokenBalance = await nodeApiInvoker.GetCurrencyBalanceAsync(username, tokenInfo?.Basic?.Contract?.Transfer, id, cancellationToken);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }

            var whitepaperPath = tokenRepository.GetWhitePaper(id, request.Lang);

            var response = new GetIncubatorInfoResponse()
            {
                CurrentPrice   = currentPrice?.BuyPrice ?? 0,
                EOSBalance     = (decimal)eosBalance,
                TokenBalance   = (decimal)tokenBalance,
                Contract       = tokenInfo.Basic?.Contract?.Pricing ?? tokenInfo.Basic?.Contract?.Transfer,
                BuyMemo        = tokenInfo.Basic?.Contract_Exchange_Info?.Buy_Memo,
                CurrentRaised  = dbToken.Raised,
                IsFavorite     = false,
                Protocol       = tokenInfo.Basic?.Protocol,
                RemainingDay   = tokenInfo?.Incubation?.DeadLine == null ? -999 : Math.Max((tokenInfo.Incubation.DeadLine - DateTime.Now).Days, 0),
                BeginTime      = tokenInfo?.Incubation.Begin_Time,
                DeadLine       = tokenInfo?.Incubation.DeadLine ?? DateTime.MaxValue,
                SupporterCount = supporterCount,
                Target         = tokenInfo?.Incubation?.Goal ?? 0,
                TotalSupply    = (decimal)(symbolSupply?.MaxSupply ?? 0),
                WhitePaper     = whitepaperPath == null ? null : "/token_assets/" + whitepaperPath
            };

            return(ApiResult(response));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> TokenDetails(
            string id,
            GetBaseRequest request,
            [FromServices] KyubeyContext db,
            [FromServices] TokenRepositoryFactory tokenRepositoryFactory,
            [FromServices] NodeApiInvoker nodeApiInvoker,
            [FromServices] ILogger logger,
            CancellationToken cancellationToken
            )
        {
            var todayItem = await db.MatchReceipts.Where(x => x.TokenId == id && x.Time >= DateTime.Now.AddDays(-1)).OrderByDescending(x => x.Time).GroupBy(x => x.TokenId).Select(x => new
            {
                TokenId      = x.Key,
                CurrentPrice = x.FirstOrDefault().UnitPrice,
                MaxPrice     = x.Max(c => c.UnitPrice),
                MinPrice     = x.Min(c => c.UnitPrice),
                Volume       = x.Sum(c => c.IsSellMatch ? c.Bid : c.Ask)
            }).FirstOrDefaultAsync(cancellationToken);

            var lastItem = await db.MatchReceipts.Where(x => x.TokenId == id && x.Time <= DateTime.Now.AddDays(-1)).OrderByDescending(x => x.Time).GroupBy(x => x.TokenId).Select(x => new
            {
                TokenId      = x.Key,
                CurrentPrice = x.FirstOrDefault().UnitPrice
            }).FirstOrDefaultAsync(cancellationToken);

            var tokenRepository = await tokenRepositoryFactory.CreateAsync(request.Lang);

            var token = tokenRepository.GetSingle(id);

            GetSymbolSupplyResponse symbolSupply = null;

            try
            {
                symbolSupply = await nodeApiInvoker.GetSymbolSupplyAsync(token?.Basic?.Contract?.Transfer, id, cancellationToken);
            }
            catch (ArgumentNullException ex)
            {
                logger.LogError(ex.ToString());
            }

            var responseData = new GetTokenDetailResponse()
            {
                Symbol          = token.Id,
                ChangeRecentDay = (todayItem?.CurrentPrice == null || ((lastItem?.CurrentPrice ?? 0) == 0)) ? 0 :
                                  ((todayItem?.CurrentPrice ?? 0) / (lastItem?.CurrentPrice ?? 1) - 1),
                CurrentPrice      = todayItem?.CurrentPrice ?? lastItem?.CurrentPrice ?? 0,
                MaxPriceRecentDay = todayItem?.MaxPrice ?? 0,
                MinPriceRecentDay = todayItem?.MinPrice ?? 0,
                VolumeRecentDay   = todayItem?.Volume ?? 0,
                IsRecommend       = true,
                IconSrc           = $"/token_assets/{token.Id}/icon.png",
                Priority          = token.Priority,
                Description       = tokenRepository.GetTokenDescription(id, request.Lang),
                TotalSupply       = symbolSupply?.MaxSupply ?? 0,
                TotalCirculate    = symbolSupply?.Supply ?? 0,
                Contract          = new GetTokenResultContract()
                {
                    Depot    = token.Basic?.Contract?.Depot,
                    Pricing  = token.Basic?.Contract?.Pricing,
                    Transfer = token.Basic?.Contract?.Transfer
                },
                Website = token.Basic.Website
            };

            return(ApiResult(responseData));
        }