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"));
        }
        private async Task <AssetCoinholdersViewModel> GetOwnersAsync(string id, int?at)
        {
            var asset = await _assetService.GetAssetAsync(id);

            if (asset != null)
            {
                var summaryTask        = _balanceChangesRepository.GetSummaryAsync(at, asset.AssetIds.ToArray());
                var addressChangesTask = _balanceChangesRepository.GetBlocksWithChanges(asset.AssetIds);
                var lastBlockTask      = _blockService.GetLastBlockHeaderAsync();
                Task <IDictionary <string, double> > addressChangesAtBlockTask;
                Task <IBlockHeader> atBlockInfoTask;
                if (at != null)
                {
                    atBlockInfoTask           = _blockService.GetBlockHeaderAsync(at.ToString());
                    addressChangesAtBlockTask = _balanceChangesRepository.GetAddressQuantityChangesAtBlock(at.Value, asset.AssetIds.ToArray());
                }
                else
                {
                    atBlockInfoTask           = Task.FromResult((IBlockHeader)null);
                    addressChangesAtBlockTask = Task.FromResult((IDictionary <string, double>) new Dictionary <string, double>());
                }

                await Task.WhenAll(addressChangesAtBlockTask, summaryTask, addressChangesTask, lastBlockTask, atBlockInfoTask);

                var result = AssetCoinholdersViewModel.Create(
                    AssetViewModel.Create(asset),
                    summaryTask.Result,
                    at,
                    addressChangesAtBlockTask.Result,
                    addressChangesTask.Result,
                    lastBlockTask.Result,
                    atBlockInfoTask.Result
                    );

                return(result);
            }

            return(null);
        }
        private async Task <ActionResult> BalanceAtBlockInner(string id, int?at)
        {
            var balance = _addressProvider.GetBalanceAsync(id, at);
            var assetDefinitionDictionary = _assetService.GetAssetDefinitionDictionaryAsync();
            var lastBlock      = _blockService.GetLastBlockHeaderAsync();
            var offchainBlocks = _offchainNotificationsService.GetGroups(address: id, openOnly: true,
                                                                         take: MaxOffchainPopoverChannels, offchainOnly: true);
            var isOffchainHub = _offchainNotificationsService.IsHubAsync(id);
            Task <IBlockHeader> atBlockTask;

            if (at != null)
            {
                atBlockTask = _blockService.GetBlockHeaderAsync(at.ToString());
            }
            else
            {
                atBlockTask = Task.FromResult <IBlockHeader>(null);
            }

            await Task.WhenAll(balance, assetDefinitionDictionary, lastBlock, atBlockTask, offchainBlocks, isOffchainHub);

            if (balance.Result != null)
            {
                return(View("Balance", AddressBalanceViewModel.Create(balance.Result,
                                                                      assetDefinitionDictionary.Result,
                                                                      lastBlock.Result,
                                                                      atBlockTask.Result,
                                                                      offchainBlocks.Result,
                                                                      isOffchainHub.Result)));
            }

            if (at != null && atBlockTask.Result == null)
            {
                return(RedirectToAction("BalanceAtBlock", new { id = id, at = lastBlock.Result }));
            }

            return(NotFound());
        }
Exemplo n.º 4
0
        public async Task ParseLast()
        {
            IBlockHeader blockPtr = null;

            try
            {
                _console.Write(nameof(ParseBlocksFunctions), nameof(ParseLast), null, "Started");

                blockPtr = await _blockService.GetLastBlockHeaderAsync();

                while (blockPtr != null &&
                       !await _assetDefinitionParsedBlockRepository
                       .IsBlockExistsAsync(AssetDefinitionParsedBlock.Create(blockPtr.Hash)))
                {
                    _console.Write(nameof(ParseBlocksFunctions),
                                   nameof(ParseLast),
                                   new { blockPtr.Hash, blockPtr.Height }.ToJson(),
                                   $"Add parse block command {blockPtr.Height}");

                    await _parseBlockCommandProducer.CreateParseBlockCommand(blockPtr.Hash);

                    blockPtr = await _blockService.GetBlockHeaderAsync((blockPtr.Height - 1).ToString());
                }

                _console.Write(nameof(ParseBlocksFunctions), nameof(ParseLast), null, "Done");
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(ParseBlocksFunctions),
                                           nameof(ParseLast),
                                           new { blockHash = blockPtr?.Hash }.ToJson(),
                                           e);

                throw;
            }
        }