Пример #1
0
        public string SearchCommand(string input)
        {
            try
            {
                if (Address.IsValidAddress(input)) //maybe is address
                {
                    return($"address/{input}");
                }

                //token
                var token = new TokenQueries(_context).QueryToken(input.ToUpperInvariant());
                if (token != null)// token
                {
                    return($"token/{token.Symbol}");
                }

                //app
                var app = new AppQueries(_context).QueryApp(input);
                if (app != null)
                {
                    return($"app/{app.Id}");
                }

                //chain
                var chain = new ChainQueries(_context).QueryChain(input);
                if (chain != null)
                {
                    return($"chain/{chain.Address}");
                }

                //hash
                if (Hash.TryParse(input, out var hash))
                {
                    var tx = new TransactionQueries(_context).QueryTransaction(input);
                    if (tx != null)
                    {
                        return($"tx/{tx.Hash}");
                    }

                    var block = new BlockQueries(_context).QueryBlock(input);
                    if (block != null)
                    {
                        return($"block/{block.Hash}");
                    }
                }

                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return("/home");
            }
        }
Пример #2
0
        public ChainViewModel GetChain(string chainInput)
        {
            var chainQuery = new ChainQueries(_context);
            var repoChain  = chainQuery.QueryChainIncludeBlocksAndTxs(chainInput);
            var chainList  = chainQuery.QueryChains().ToList();

            if (repoChain == null)
            {
                return(null);
            }

            return(ChainViewModel.FromChain(chainList, repoChain));
        }
Пример #3
0
        public List <SimpleChainViewModel> GetChains()
        {
            var chainQuery  = new ChainQueries(_context);
            var chainVmList = new List <SimpleChainViewModel>();

            var allChains = chainQuery.SimpleQueryChains().ToList();

            foreach (var chain in allChains)
            {
                chainVmList.Add(chain);
            }

            return(chainVmList);
        }
Пример #4
0
        public HomeViewModel GetLastestInfo()
        {
            var blockQuery = new BlockQueries(_context);
            var txsQuery   = new TransactionQueries(_context);
            var chainQuery = new ChainQueries(_context);

            var blocks       = blockQuery.QueryLastBlocks(14);
            var transactions = txsQuery.QueryLastTransactions(15);
            var blocksVm     = blocks.Select(BlockHomeViewModel.FromBlock).ToList();

            var txsVm = transactions.Select(TransactionHomeViewModel.FromTransaction).ToList();

            // tx history chart calculation
            var repTxs = txsQuery.QueryLastTransactions(1000, null);

            var chart = new Dictionary <string, uint>();

            foreach (var transaction in repTxs)
            {
                var      block     = transaction.Block;
                DateTime chartTime = new Timestamp(block.Timestamp);
                var      chartKey  = $"{chartTime.Day}/{chartTime.Month}";

                if (chart.ContainsKey(chartKey))
                {
                    chart[chartKey] += 200;
                }
                else
                {
                    chart[chartKey] = 1;
                }
            }

            int  totalChains       = chainQuery.QueryChainCount;
            uint height            = chainQuery.QueryChain("main").Height;
            int  totalTransactions = txsQuery.QueryTotalChainTransactionCount();

            var vm = new HomeViewModel
            {
                Blocks            = blocksVm,
                Transactions      = txsVm,
                Chart             = chart,
                TotalTransactions = totalTransactions,
                TotalChains       = totalChains,
                BlockHeight       = height,
            };

            return(vm);
        }
Пример #5
0
        public async Task <MarketplaceViewModel> GetAuctions(string chain, int currentPage, int pageSize = AppSettings.PageSize, string tokenSymbol = null)
        {
            var tokenQueries = new TokenQueries(_context);
            var chainQueries = new ChainQueries(_context);
            var tokenList    = tokenQueries.QueryTokens();

            var chains = chainQueries.QueryChains();
            List <AuctionDto> auctions = new List <AuctionDto>();

            var auction = await _phantasmaRpcService.GetAuctions.SendRequestAsync(chain, "", currentPage, pageSize);

            auctions.AddRange(auction.AuctionsList);

            return(MarketplaceViewModel.FromAuctionList(auctions, tokenList));
        }
Пример #6
0
        public async Task <List <string> > GetChainsWithMarketsAndActiveAuctions()
        {
            var chainQueries     = new ChainQueries(_context);
            var chainsWithMarket = chainQueries.QueryChains()
                                   .Where(p => p.Contracts.Any(c => c == "market"))
                                   .Select(p => p.Name).ToList();

            List <string> chainList = new List <string>();

            foreach (var chain in chainsWithMarket) //check if they have auctions
            {
                var auctions = await _phantasmaRpcService.GetAuctionCount.SendRequestAsync(chain);

                if (auctions > 0)
                {
                    chainList.Add(chain);
                }
            }

            return(chainList);
        }