コード例 #1
0
ファイル: Program.cs プロジェクト: bwhli/MetrICX
        static public void UpdateBlockStatus(BlockProcessedStatus blockStatus, ICXBlock block)
        {
            if (block != null)
            {
                blockStatus.processingDelaySeconds = Convert.ToInt32((DateTime.UtcNow.AddHours(8) - block.GetTimeStamp()).TotalSeconds);
            }
            blockStatus.processedTimestamp = Google.Cloud.Firestore.Timestamp.GetCurrentTimestamp();

            FirebaseGateway.SetBlockProcessed(blockStatus);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: bwhli/MetrICX
        private static void ProcessBlockInThread(ICXBlock icxBlock)
        {
            //If there are too many thread, wait here for a bit
            while (Process.GetCurrentProcess().Threads.Count > MAX_THREADS)
            {
                Console.Write(".");
                System.Threading.Thread.Sleep(100);
            }

            var newThread = (new System.Threading.Thread((block) =>
            {
                ProcessBlock((ICXBlock)block);
            })
            {
                Name = $"processing height {icxBlock.Height}"
            });

            newThread.Start(icxBlock);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: bwhli/MetrICX
        private static void ProcessBlock(ICXBlock block, long icxBlockHeight = -1)
        {
            BlockProcessedStatus blockStatus = null;
            ICXBlock             icxBlock    = block;
            long blockHeight = 0;

            try
            {
                //Get block height to process

                if (icxBlockHeight > 0)
                {
                    blockHeight = icxBlockHeight;
                }
                else
                {
                    blockHeight = block.Height;
                }

                //Get block info from Firebase
                Console.WriteLine($"Starting to Process Block {blockHeight} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}");
                blockStatus = FirebaseGateway.GetBlockProcessed(blockHeight);
                if (blockStatus == null)
                {
                    blockStatus = new BlockProcessedStatus()
                    {
                        height          = blockHeight,
                        eventsPublished = 0,
                        retryAttempts   = 0
                    };
                }
                else
                {
                    if (blockStatus.completed == true)
                    {
                        Console.WriteLine($"Block {blockHeight} is already completed, exiting");
                        return;
                    }

                    blockStatus.retryAttempts++;
                }

                //Get the ICX Block if it not provided
                if (icxBlockHeight > 0)
                {
                    icxBlock = IconGateway.GetBlockByHeight(icxBlockHeight);
                }

                blockStatus.blockTimestamp = Google.Cloud.Firestore.Timestamp.FromDateTimeOffset(icxBlock.GetTimeStamp().AddHours(-8));

                // Check ISCORE
                var rewards = IconGateway.GetAvailableRewards("hxc147caa988765c13eaa6ca43400c27a0372b9436");
                if (rewards < oldRewards || oldRewards == -1)
                {
                    oldRewards = rewards;
                }
                else if (rewards > oldRewards)
                {
                    blockStatus.eventsPublished++;
                    Console.WriteLine($"ISCORE CHANGED, Pushing event update");
                    publishIScoreChange();
                    oldRewards = rewards;
                }

                var blockTimeStamp = DateTimeOffset.FromUnixTimeMilliseconds(icxBlock.TimeStamp / 1000).AddHours(8);
                var oldNess        = Convert.ToInt32((DateTime.UtcNow.AddHours(8) - icxBlock.GetTimeStamp()).TotalSeconds);

                //What do we do
                Console.WriteLine($"block timestamp {icxBlock.GetTimeStamp()}, oldNess {oldNess} seconds, HEIGHT {icxBlock.Height}, transactions {icxBlock.ConfirmedTransactionList.Count}, eventCount {eventCounter}, retries {blockStatus.retryAttempts} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}");

                foreach (var tx in icxBlock.ConfirmedTransactionList)
                {
                    var txStr = JsonConvert.SerializeObject(tx);

                    if (tx.From != null && tx.From.StartsWith("hx") && tx.To != null && tx.To.StartsWith("hx"))
                    {
                        blockStatus.eventsPublished++;
                        publishTransferMessage(tx);
                    }

                    if (tx.From != null && tx.From.StartsWith("hx") && tx.To != null && tx.To.StartsWith("cx"))
                    {
                        blockStatus.eventsPublished++;
                        var txResult = IconGateway.GetTransactionResult(tx.TxHash);
                        tx.TxResultDetails = txResult;

                        publishContractMethodMessage(tx);
                    }
                }

                blockStatus.completed = true;
                UpdateBlockStatus(blockStatus, icxBlock);
                Console.WriteLine($"COMPLETED {icxBlock.Height} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"EXCEPTION : Error on block {blockHeight} :  {ex.Message} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}");

                blockStatus.completed        = false;
                blockStatus.lastErrorMessage = ex.Message;
                UpdateBlockStatus(blockStatus, icxBlock);
            }
        }