Example #1
0
        public async Task Subscribe(CancellationToken cancellationToken)
        {
            // http://docs.nethereum.com/en/latest/nethereum-subscriptions-streaming/
            using var streamingClient = new StreamingWebSocketClient(_batBotOptions.BlockchainEndpointWssUrl);
            var subscription = new EthNewPendingTransactionObservableSubscription(streamingClient);

            await _ethereumService.HandleSubscription(streamingClient, subscription, async() => await subscription.SubscribeAsync(), async th =>
            {
                await _messagingService.SendLogMessage($"Pending Transaction Hash: {th}");

                // Don't process transactions (discard) when one is being processed for front running.
                if (_backoffService.BackOff())
                {
                    return;
                }

                await _backoffService.Protect(async() => await _transactionProcessorService.Process(await _ethereumService.GetSwap(th), cancellationToken));
            }, null, cancellationToken);
        }