예제 #1
0
        public override async Task GetCombinedRegistryBlocksInfoSinceHeight(ByHeightRequest request, IServerStreamWriter <CombinedRegistryBlockInfo> responseStream, ServerCallContext context)
        {
            IEnumerable <BlockBase> blocks = _syncChainDataService.GetAll(new BlockTypeLowHeightKey(BlockTypes.Synchronization_RegistryCombinationBlock, request.Height));

            foreach (BlockBase blockBase in blocks)
            {
                SynchronizationRegistryCombinedBlock registryCombinedBlock     = blockBase as SynchronizationRegistryCombinedBlock;
                CombinedRegistryBlockInfo            combinedRegistryBlockInfo = new CombinedRegistryBlockInfo
                {
                    SyncBlockHeight             = registryCombinedBlock.SyncBlockHeight,
                    Height                      = registryCombinedBlock.BlockHeight,
                    CombinedRegistryBlocksCount = (uint)registryCombinedBlock.BlockHashes.Length,
                };

                foreach (byte[] hash in registryCombinedBlock.BlockHashes)
                {
                    RegistryFullBlock registryFullBlock = (RegistryFullBlock)_registryChainDataService.Get(new SyncHashKey(registryCombinedBlock.SyncBlockHeight, hash));

                    if (registryFullBlock != null)
                    {
                        combinedRegistryBlockInfo.BlockDescriptors.Add(
                            new FullBlockDescriptor
                        {
                            SyncBlockHeight   = registryCombinedBlock.SyncBlockHeight,
                            Round             = registryFullBlock.BlockHeight,
                            TransactionsCount = (uint)registryFullBlock.TransactionHeaders.Count,
                            BlockHash         = ByteString.CopyFrom(hash)
                        });
                    }
                }

                await responseStream.WriteAsync(combinedRegistryBlockInfo);
            }
        }
예제 #2
0
        public override Task GetTransactionInfos(FullBlockRequest request, IServerStreamWriter <TransactionInfo> responseStream, ServerCallContext context)
        {
            return(Task.Run(async() =>
            {
                RegistryFullBlock registryFullBlock = (RegistryFullBlock)_registryChainDataService.Get(new DoubleHeightKey(request.SyncBlockHeight, request.Round));
                foreach (RegistryRegisterBlock transactionWitness in registryFullBlock.StateWitnesses)
                {
                    try
                    {
                        PacketBase blockBase = _transactionalDataService.Get(new SyncHashKey(transactionWitness.SyncBlockHeight, transactionWitness.ReferencedBodyHash));

                        if (blockBase != null)
                        {
                            await responseStream.WriteAsync(
                                new TransactionInfo
                            {
                                SyncBlockHeight = transactionWitness.SyncBlockHeight,
                                PacketType = (uint)transactionWitness.ReferencedPacketType,
                                BlockType = transactionWitness.ReferencedBlockType,
                                Content = ByteString.CopyFrom(blockBase.RawData.ToArray())
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"Failed to retrieve block for SyncBlockHeight {request.SyncBlockHeight} and Round {request.Round}", ex);
                    }
                }

                foreach (RegistryRegisterUtxoConfidential transactionWitness in registryFullBlock.UtxoWitnesses)
                {
                    try
                    {
                        PacketBase blockBase = _utxoConfidentialDataService.Get(new SyncHashKey(transactionWitness.SyncBlockHeight, transactionWitness.ReferencedBodyHash));

                        if (blockBase != null)
                        {
                            await responseStream.WriteAsync(
                                new TransactionInfo
                            {
                                SyncBlockHeight = transactionWitness.SyncBlockHeight,
                                PacketType = (uint)transactionWitness.ReferencedPacketType,
                                BlockType = transactionWitness.ReferencedBlockType,
                                Content = ByteString.CopyFrom(blockBase.RawData.ToArray())
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"Failed to retrieve block for SyncBlockHeight {request.SyncBlockHeight} and Round {request.Round}", ex);
                    }
                }
            }, context.CancellationToken));
        }
예제 #3
0
        public override Task <TransactionInfo> GetTransactionInfo(TransactionRequest request, ServerCallContext context)
        {
            byte[] hash = request.Hash.ToByteArray();
            try
            {
                PacketBase blockBase = _transactionalDataService.Get(new SyncHashKey(request.SyncBlockHeight, hash));

                if (blockBase != null)
                {
                    return(Task.FromResult(new TransactionInfo
                    {
                        SyncBlockHeight = blockBase.SyncBlockHeight,
                        PacketType = (uint)blockBase.PacketType,
                        BlockType = blockBase.BlockType,
                        Content = ByteString.CopyFrom(blockBase.RawData.ToArray())
                    }));
                }
                else
                {
                    blockBase = _transactionalDataService.Get(new SyncHashKey(request.SyncBlockHeight - 1, hash));
                    if (blockBase != null)
                    {
                        return(Task.FromResult(new TransactionInfo
                        {
                            SyncBlockHeight = blockBase.SyncBlockHeight,
                            PacketType = (uint)blockBase.PacketType,
                            BlockType = blockBase.BlockType,
                            Content = ByteString.CopyFrom(blockBase.RawData.ToArray())
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed to retrieve block for SyncBlockHeight {request.SyncBlockHeight} and ReferencedHash {hash.ToHexString()}", ex);
            }

            return(Task.FromResult(new TransactionInfo()));
        }