Esempio n. 1
0
        public Transaction[] TryBroadcast()
        {
            uint256[]          knownBroadcasted = null;
            List <Transaction> broadcasted      = new List <Transaction>();

            try
            {
                broadcasted.AddRange(BroadcasterService.TryBroadcast(ref knownBroadcasted));
            }
            catch (Exception ex)
            {
                Logs.Broadcasters.LogError("Exception on Broadcaster");
                Logs.Broadcasters.LogError(ex.ToString());
            }
            try
            {
                broadcasted.AddRange(TrustedBroadcasterService.TryBroadcast(ref knownBroadcasted));
            }
            catch (Exception ex)
            {
                Logs.Broadcasters.LogError("Exception on TrustedBroadcaster");
                Logs.Broadcasters.LogError(ex.ToString());
            }
            return(broadcasted.ToArray());
        }
Esempio n. 2
0
        public void Start(CancellationToken cancellation)
        {
            _Stop = cancellation;
            new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        int lastHeight = 0;
                        while (true)
                        {
                            _Stop.WaitHandle.WaitOne(5000);
                            _Stop.ThrowIfCancellationRequested();

                            var height = BlockExplorerService.GetCurrentHeight();
                            if (height == lastHeight)
                            {
                                continue;
                            }
                            lastHeight = height;
                            try
                            {
                                var transactions = BroadcasterService.TryBroadcast();
                                foreach (var tx in transactions)
                                {
                                    Logger.LogInformation("Broadcaster broadcasted  " + tx.GetHash());
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.LogError("Error while running Broadcaster: " + ex.Message);
                                Logger.LogDebug(ex.StackTrace);
                            }
                            try
                            {
                                var transactions = TrustedBroadcasterService.TryBroadcast();
                                foreach (var tx in transactions)
                                {
                                    Logger.LogInformation("TrustedBroadcaster broadcasted " + tx.GetHash());
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.LogError("Error while running TrustedBroadcaster: " + ex.Message);
                                Logger.LogDebug(ex.StackTrace);
                            }
                        }
                    }
                    catch (OperationCanceledException) { return; }
                    catch (Exception ex)
                    {
                        Logger.LogError("Uncatched exception in BroadcasterJob: " + ex.Message);
                        Logger.LogDebug(ex.StackTrace);
                    }
                }
            }).Start();
        }