Esempio n. 1
0
        public void Run()
        {
            if (running)
            {
                return;
            }

            this.running = true;

            // TODO: The last block should persistent between multiple sessions, in order to not miss any block
            var lastBlock = neo_api.GetBlockHeight() - 1;

            do
            {
                var currentBlock = neo_api.GetBlockHeight();
                if (currentBlock > lastBlock)
                {
                    ProcessIncomingBlock(currentBlock);
                    lastBlock = currentBlock;
                }

                // sleeps 10 seconds in order to wait some time until next block is generated
                Thread.Sleep(10 * 1000);
            } while (running);
        }
Esempio n. 2
0
        public void Run()
        {
            if (running)
            {
                return;
            }

            this.running = true;

            do
            {
                var currentBlock = neo_api.GetBlockHeight();
                if (currentBlock > lastBlock)
                {
                    while (lastBlock < currentBlock)
                    {
                        lastBlock++;
                        ProcessIncomingBlock(lastBlock);
                    }
                }

                // sleeps 10 seconds in order to wait some time until next block is generated
                Thread.Sleep(20 * 1000);
            } while (running);
        }
Esempio n. 3
0
        public void Run(uint previousBlocks)
        {
            if (_running)
            {
                return;
            }
            this._running = true;

            _previousBlocks = previousBlocks;

            // TODO: The last block should persistent between multiple sessions, in order to not miss any block
            var blockHeight  = _api.GetBlockHeight();
            var currentBlock = blockHeight - _previousBlocks;
            int retries      = 0;

            do                                      // a batch of blocks: from currentBlock to blockHeight
            {
                while (currentBlock <= blockHeight) // for each block in this batch
                {
                    if (ProcessIncomingBlock(currentBlock))
                    {
                        currentBlock++;
                        retries = 0;
                    }
                    else
                    {
                        retries++;
                        if (retries > 10)
                        {
                            Console.WriteLine($"Too many retries: skipping block {currentBlock}...");
                            currentBlock++;
                            retries = 0;
                        }
                        else
                        {
                            Console.WriteLine($"Waiting for block... retry {retries}");
                            Thread.Sleep(10 * 1000);
                        }
                    }
                }
                Console.WriteLine($"Waiting for next batch...");
                Thread.Sleep(30 * 1000);
                blockHeight = _api.GetBlockHeight();
            } while (_running);
        }
Esempio n. 4
0
        public static uint FindBlock(NeoAPI api, DateTime date)
        {
            uint min = 0;
            var  max = api.GetBlockHeight();

            var timestamp = date.ToTimestamp();

            return(FindBlock(api, timestamp, min, max));
        }
Esempio n. 5
0
        public void Run(uint blockCount = 0)
        {
            if (running)
            {
                return;
            }

            this.running = true;

            bool forever = (blockCount == 0);

            do
            {
                var currentBlock = neo_api.GetBlockHeight();
                if (currentBlock > lastBlock)
                {
                    while (lastBlock < currentBlock)
                    {
                        ProcessIncomingBlock(lastBlock);
                        lastBlock++;

                        if (!forever)
                        {
                            blockCount--;
                            if (blockCount == 0)
                            {
                                return;
                            }
                        }
                    }
                }

                // sleeps 10 seconds in order to wait some time until next block is generated
                Thread.Sleep(10 * 1000);
            } while (running);
        }