public void NewPendingTransactionsSubscription_on_NewPending_event_with_null_transaction()
        {
            TxEventArgs txEventArgs = new TxEventArgs(null);

            JsonRpcResult jsonRpcResult = GetNewPendingTransactionsResult(txEventArgs, out _);

            jsonRpcResult.Response.Should().BeNull();
        }
Example #2
0
        private void OnNewPending(object?sender, TxEventArgs args)
        {
            if (Emit == null)
            {
                return;
            }

            Emit((TOut)args.Transaction);
        }
Example #3
0
 private void TxPoolOnNewDiscovered(object sender, TxEventArgs e)
 {
     if (_analyticsConfig.StreamTransactions)
     {
         foreach (IPublisher publisher in _publishers)
         {
             // TODO: probably need to serialize first
             publisher.PublishAsync(e.Transaction);
         }
     }
 }
 private void OnNewPending(object?sender, TxEventArgs e)
 {
     ScheduleAction(() =>
     {
         JsonRpcResult result = CreateSubscriptionMessage(_includeTransactions ? new TransactionForRpc(e.Transaction) : e.Transaction.Hash);
         JsonRpcDuplexClient.SendJsonRpcResult(result);
         if (_logger.IsTrace)
         {
             _logger.Trace($"NewPendingTransactions subscription {Id} printed hash of NewPendingTransaction.");
         }
     });
 }
 private void OnEvicted(object?sender, TxEventArgs e)
 {
     ScheduleAction(() =>
     {
         JsonRpcResult result = CreateSubscriptionMessage(e.Transaction.Hash);
         JsonRpcDuplexClient.SendJsonRpcResult(result);
         if (_logger.IsTrace)
         {
             _logger.Trace($"DroppedPendingTransactions subscription {Id} printed hash of DroppedPendingTransaction.");
         }
     });
 }
 private void OnNewPendingTx(object sender, TxEventArgs e)
 {
     TryProduceNewBlock(CancellationToken.None).ContinueWith(t =>
     {
         if (t.IsFaulted)
         {
             if (Logger.IsError)
             {
                 Logger.Error($"Failed to produce block after receiving transaction {e.Transaction}", t.Exception);
             }
         }
     });
 }
        public void NewPendingTransactionsSubscription_on_NewPending_event_with_null_transactions_hash()
        {
            Transaction transaction = Build.A.Transaction.TestObject;

            transaction.Hash = null;
            TxEventArgs txEventArgs = new TxEventArgs(transaction);

            JsonRpcResult jsonRpcResult = GetNewPendingTransactionsResult(txEventArgs, out var subscriptionId);

            jsonRpcResult.Response.Should().NotBeNull();
            string serialized     = _jsonSerializer.Serialize(jsonRpcResult.Response);
            var    expectedResult = string.Concat("{\"jsonrpc\":\"2.0\",\"method\":\"eth_subscription\",\"params\":{\"subscription\":\"", subscriptionId, "\"}}");

            expectedResult.Should().Be(serialized);
        }
Example #8
0
 private async void OnNewPendingTxAsync(TxEventArgs e)
 {
     _newBlockLock.Wait(TimeSpan.FromSeconds(1));
     try
     {
         if (!await TryProduceNewBlock(CancellationToken.None))
         {
             _newBlockLock.Release();
         }
     }
     catch (Exception exception)
     {
         if (Logger.IsError)
         {
             Logger.Error($"Failed to produce block after receiving transaction {e.Transaction}", exception);
         }
         _newBlockLock.Release();
     }
 }
        private JsonRpcResult GetNewPendingTransactionsResult(TxEventArgs txEventArgs, out string subscriptionId)
        {
            NewPendingTransactionsSubscription newPendingTransactionsSubscription = new NewPendingTransactionsSubscription(_jsonRpcDuplexClient, _txPool, _logManager);
            JsonRpcResult jsonRpcResult = new JsonRpcResult();

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);

            newPendingTransactionsSubscription.JsonRpcDuplexClient.SendJsonRpcResult(Arg.Do <JsonRpcResult>(j =>
            {
                jsonRpcResult = j;
                manualResetEvent.Set();
            }));

            _txPool.NewPending += Raise.EventWith(new object(), txEventArgs);
            manualResetEvent.WaitOne(TimeSpan.FromMilliseconds(100));

            subscriptionId = newPendingTransactionsSubscription.Id;
            return(jsonRpcResult);
        }
Example #10
0
        private void OnNewPendingTransaction(object sender, TxEventArgs e)
        {
            var filters = _filterStore.GetFilters <PendingTransactionFilter>();

            if (filters == null || filters.Length == 0)
            {
                return;
            }

            for (var i = 0; i < filters.Length; i++)
            {
                var filterId     = filters[i].Id;
                var transactions = _pendingTransactions.GetOrAdd(filterId, _ => new List <Keccak>());
                transactions.Add(e.Transaction.Hash);
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Filter with id: '{filterId}' contains {transactions.Count} transactions.");
                }
            }
        }
 private void OnNewPending(object?sender, TxEventArgs e)
 {
     Task.Run(() =>
     {
         JsonRpcResult result = CreateSubscriptionMessage(e.Transaction.Hash);
         JsonRpcDuplexClient.SendJsonRpcResult(result);
         if (_logger.IsTrace)
         {
             _logger.Trace($"NewPendingTransactions subscription {Id} printed hash of NewPendingTransaction.");
         }
     }).ContinueWith(
         t =>
         t.Exception?.Handle(ex =>
     {
         if (_logger.IsDebug)
         {
             _logger.Debug($"NewPendingTransactions subscription {Id}: Failed Task.Run after NewPending event.");
         }
         return(true);
     })
         , TaskContinuationOptions.OnlyOnFaulted
         );
 }
Example #12
0
 private void OnNewPendingTx(object sender, TxEventArgs e)
 {
     OnNewPendingTxAsync(e);
 }
Example #13
0
 private void TxPoolOnNewPending(object?sender, TxEventArgs e)
 {
     TriggerBlockProduction?.Invoke(this, new BlockProductionEventArgs());
 }
Example #14
0
 private void OnNewPending(object?sender, TxEventArgs args)
 {
     Emit((TOut)args.Transaction);
 }
Example #15
0
 private async void OnNewPendingTx(object sender, TxEventArgs e)
 {
     await base.TryProduceNewBlock(CancellationToken.None);
 }
Example #16
0
 private void TxPoolOnNewPending(object?sender, TxEventArgs e)
 {
     IBlockchainBridge bridge = _nethermindApi !.CreateBlockchainBridge();
     // create a bundle
     // submit the bundle to Flashbots MEV-Relay
 }