From 016a963cb40805a1d82502206214fea8f0260859 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 12 Feb 2024 18:03:49 +0200 Subject: [PATCH] init block reader --- .gitignore | 3 ++- src/index.php | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e127e2c..703984b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor/ /composer.lock -/config.json \ No newline at end of file +/config.json +/.block \ No newline at end of file diff --git a/src/index.php b/src/index.php index 1f367b4..f3a0f7d 100644 --- a/src/index.php +++ b/src/index.php @@ -26,6 +26,24 @@ $config = json_decode( ) ); +// Init block +$block = 0; + +if (file_exists(__DIR__ . '/../.block')) +{ + $block = (int) file_get_contents( + __DIR__ . '/../.block' + ); +} + +else +{ + file_put_contents( + __DIR__ . '/../.block', + $block + ); +} + // Load dependencies require_once __DIR__ . '/../vendor/autoload.php'; @@ -106,5 +124,23 @@ if (isset($argv[1])) } // Begin crawler +if (false === $blocks = $kevacoin->getBlockCount()) +{ + exit( + _('Could not receive blocks count!') + ); +} -// @TODO \ No newline at end of file +for ($i = $block; $i <= $blocks; $i++) +{ + echo sprintf( + "%d/%d\r", + $i, + $blocks + ); + + file_put_contents( + __DIR__ . '/../.block', + $i + ); +} \ No newline at end of file