Ejemplo n.º 1
0
        private async Task BroadcastBlockAsync(BlockWithTransactions blockWithTransactions)
        {
            if (_blockStreamCall == null)
            {
                _blockStreamCall = _client.BlockBroadcastStream(new Metadata {
                    { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                });
            }

            try
            {
                await _blockStreamCall.RequestStream.WriteAsync(blockWithTransactions);
            }
            catch (RpcException)
            {
                _blockStreamCall.Dispose();
                _blockStreamCall = null;

                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task SendBlockAsync(BlockWithTransactions blockWithTransactions)
        {
            if (!IsConnected)
            {
                return;
            }

            if (_blockStreamCall == null)
            {
                _blockStreamCall = _client.BlockBroadcastStream();
            }

            try
            {
                await _blockStreamCall.RequestStream.WriteAsync(blockWithTransactions);
            }
            catch (RpcException e)
            {
                _blockStreamCall.Dispose();
                _blockStreamCall = null;

                HandleFailure(e, $"Error during block broadcast: {blockWithTransactions.Header.GetHash()}.");
            }
        }