コード例 #1
0
        public IActionResult Search(string Search)
        {
            if (string.IsNullOrEmpty(Search))
            {
                return(View());
            }
            var         coins = mainCoins.GetCoin();
            ClientBlock blk;
            ClientBlock blkUnconfirmed;
            String      blkHashUnconfirmed;
            GetRawTransactionResponseMongo transaction;
            GetOmniTransactionResponse     assetTransactionUnconfirmed;
            GetRawTransactionResponse      transactionUnconfirmed;
            object addr;

            uint   blockHeight;
            string blockHash = Search;

            if (uint.TryParse(Search, out blockHeight))
            {
                blk = mainCoins.GetBlockByIdMongo(blockHeight);
                if (blk != null)
                {
                    return(RedirectToAction("block", new { block = blk.Height }));
                }
            }
            else if (blockHash.Length == 64)
            {
                blk = mainCoins.GetAssetBlockMongo(blockHash);
                if (blk != null)
                {
                    return(RedirectToAction("block", new { block = blk.Hash }));
                }
            }

            if (Search.Length == 64)
            {
                transaction = mainCoins.GetRawTransactionMongo(Search);
                if (transaction != null)
                {
                    return(RedirectToAction("transaction", new { transaction = transaction.TxId }));
                }
            }
            if (coins.AddrLen.Any(a => a == Search.Length))
            {
                addr = mainCoins.SearchAddressInfo(Search);
                if (addr != null)
                {
                    return(RedirectToAction("address", new { address = Search }));
                }
            }

            if (blockHeight > 0)
            {
                try
                {
                    blkHashUnconfirmed = mainCoins.GetBlockHashByHeight(blockHeight);
                    if (blkHashUnconfirmed != null)
                    {
                        return(RedirectToAction("block", new { block = blockHeight }));
                    }
                }
                catch
                {
                    // silent
                }
            }
            else if (blockHash.Length == 64)
            {
                try
                {
                    blkUnconfirmed = mainCoins.GetBlockByHash(blockHash);
                    if (blkUnconfirmed != null)
                    {
                        return(RedirectToAction("block", new { block = blkUnconfirmed.Hash }));
                    }
                }
                catch
                {
                    //silent
                }
            }
            if (Search.Length == 64)
            {
                try
                {
                    assetTransactionUnconfirmed = mainCoins.GetRawTransactionAsset(Search);
                    if (assetTransactionUnconfirmed != null)
                    {
                        return(RedirectToAction("transaction", new { transaction = assetTransactionUnconfirmed.txid }));
                    }
                }
                catch
                {
                    // silent
                }
                try
                {
                    transactionUnconfirmed = mainCoins.GetRawTransaction(Search);
                    if (transactionUnconfirmed != null)
                    {
                        return(RedirectToAction("transaction", new { transaction = Search }));
                    }
                }
                catch
                {
                    // silent
                }
            }

            if (coins.AddrLen.Any(a => a == Search.Length) && mainCoins.IsValidAddres(Search))
            {
                return(Redirect("~/address/" + Search));
            }

            return(View());
        }