Esempio n. 1
0
        public async Task ParseBlock(AssetDefinitionParseBlockContext context)
        {
            try
            {
                _console.Write(nameof(ParseBlockCommandQueueConsumer), nameof(ParseBlock), context.ToJson(), "Started");
                var block = await _indexerClient.GetBlock(uint256.Parse(context.BlockHash));

                foreach (var transaction in block.Transactions.Where(p => p.HasValidColoredMarker()))
                {
                    var assetDefUrl = transaction.TryGetAssetDefinitionUrl();

                    if (assetDefUrl != null)
                    {
                        await _log.WriteInfoAsync(nameof(ParseBlockCommandQueueConsumer),
                                                  nameof(ParseBlock),
                                                  context.ToJson(),
                                                  $"Found asset definition url {assetDefUrl.AbsoluteUri}");

                        await _assetDefinitionCommandProducer.CreateRetrieveAssetDefinitionCommand(assetDefUrl.AbsoluteUri);
                    }
                }


                await _assetDefinitionParsedBlockRepository.AddBlockAsync(AssetDefinitionParsedBlock.Create(context.BlockHash));

                _console.Write(nameof(ParseBlockCommandQueueConsumer), nameof(ParseBlock), context.ToJson(), "Done");
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(ParseBlockCommandQueueConsumer), nameof(ParseBlock), context.ToJson(), e);
            }
        }
Esempio n. 2
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;
            }
        }