Beispiel #1
0
        public static TransactionViewModel Create(ITransaction ninjaTransaction, IReadOnlyDictionary <string, IAssetDefinition> assetDictionary, MixedTransactionType?offchainType = null)
        {
            if (ninjaTransaction == null)
            {
                return(null);
            }

            var bc       = ninjaTransaction.TransactionsByAssets.First(p => !p.IsColored);
            var colored  = ninjaTransaction.TransactionsByAssets.Where(p => p.IsColored).OrderBy(p => p.AssetId);
            var assetDic = AssetDictionary.Create(assetDictionary);

            var result = new TransactionViewModel
            {
                TransactionId = ninjaTransaction.TransactionId,
                IsCoinBase    = ninjaTransaction.IsCoinBase,
                IsColor       = ninjaTransaction.IsColor,
                Block         = BlockViewModel.Create(ninjaTransaction.Block),
                AssetsCount   = ninjaTransaction.TransactionsByAssets.Count(p => p.IsColored),
                IsConfirmed   = ninjaTransaction.Block != null,
                Bitcoin       = BitcoinAsset.Create(ninjaTransaction.Fees, ninjaTransaction.IsCoinBase, bc.TransactionIn.Union(colored.SelectMany(p => p.TransactionIn)), bc.TransactionsOut.Union(colored.SelectMany(p => p.TransactionsOut)), assetDic),
                ColoredAssets = colored.Select(p => ColoredAsset.Create(p, assetDic)),
                InputsCount   = ninjaTransaction.InputsCount,
                OutputsCount  = ninjaTransaction.OutputsCount,
                OffchainType  = offchainType
            };

            return(result);
        }
        public async Task <ActionResult> Index(string id)
        {
            int numBlockHeight;

            if (int.TryParse(id, out numBlockHeight))
            {
                var header = await _blockService.GetBlockHeaderAsync(numBlockHeight.ToString());

                if (header != null)
                {
                    return(RedirectToAction("Index", "Block", new { id = header.Hash }));
                }
            }

            var block = _cachedBlockService.GetBlockAsync(id);

            var lastBlock = _blockService.GetLastBlockHeaderAsync();

            await Task.WhenAll(block, lastBlock);

            if (block.Result != null)
            {
                var result = BlockViewModel.Create(block.Result, lastBlock.Result);

                return(View(result));
            }

            return(View("NotFound"));
        }