From c51effff5522737db97eb70e181d7593059aeff2 Mon Sep 17 00:00:00 2001 From: artemuhi Date: Thu, 7 Mar 2024 22:18:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- artemsbc.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/artemsbc.php b/artemsbc.php index 2ace13b..83df35a 100644 --- a/artemsbc.php +++ b/artemsbc.php @@ -36,6 +36,7 @@ function artembc_initblock($filename, &$transaction, $data=[]) { ])); if ($block["idblock"] != $temp and $hash != $block["hash"]) { $correct=false; + break; }; }; if ($correct) { @@ -50,7 +51,38 @@ function artembc_initblock($filename, &$transaction, $data=[]) { artembc_save($filename, $bc); return $correct; } -function artembc_checkbc() {} +function artembc_checkbc() { + $bc=artembc_load($filename); + $temp=count($bc); + for ($i = 0, $size = count($bc), $correct2=true; $i < $size; ++$i) { + $transaction=$bc[$i]; + for($i = 0, $size = count($transaction), $correct=true; $i < $size; ++$i) { + $block=$transaction[$i]; + $hash=hash("sha256", json_encode([ + "id"=>$block["id"], + "idblock"=>$block["idblock"], + "time"=>$block["time"], + "data"=>$block["data"] + ])); + if ($block["idblock"] != $temp and $hash != $block["hash"]) { + $correct=false; + break; + }; + }; + $hash=hash("sha256", json_encode([ + "id"=>$block["id"], + "time"=>$block["time"], + "data"=>$block["data"], + "transaction"=>$block["transaction"], + "prevhash"=>$block["prevhash"] + ])); + if ($hash != $transaction["hash"] or ($transaction["prevhash"] != $bc[$temp-1]["hash"] and $transaction["id"] == 0)) { + $correct2 = false; + break; + }; + }; + return $correct and $correct2; +} function artembc_getblock($filename, $id) { $temp=artembc_load($filename); return $temp[$id];