Обновить artemsbc.php
This commit is contained in:
parent
f575cc0737
commit
f1767faee2
39
artemsbc.php
39
artemsbc.php
@ -8,7 +8,7 @@ function artembc_createbc($filename, $namebc, $data=[]) {
|
|||||||
"prevhash"=>"ZeroBlock"
|
"prevhash"=>"ZeroBlock"
|
||||||
]];
|
]];
|
||||||
$temp[0]["data"]["namebc"]=$namebc;
|
$temp[0]["data"]["namebc"]=$namebc;
|
||||||
$temp[0]["hash"]=hash("sha256", json_encode($temp));
|
$temp[0]["hash"]=hash("sha256", json_encode($temp[0]));
|
||||||
return artembc_save($filename, $temp);
|
return artembc_save($filename, $temp);
|
||||||
}
|
}
|
||||||
function artembc_addtransaction($filename, &$transaction, $data) {
|
function artembc_addtransaction($filename, &$transaction, $data) {
|
||||||
@ -47,31 +47,36 @@ function artembc_initblock($filename, &$transaction, $data=[]) {
|
|||||||
"transaction"=>$transaction,
|
"transaction"=>$transaction,
|
||||||
"prevhash"=>$bc[$temp-1]["hash"]
|
"prevhash"=>$bc[$temp-1]["hash"]
|
||||||
];
|
];
|
||||||
};
|
|
||||||
$bc[$temp]["hash"]=hash("sha256", json_encode($bc[$temp]));
|
$bc[$temp]["hash"]=hash("sha256", json_encode($bc[$temp]));
|
||||||
artembc_save($filename, $bc);
|
artembc_save($filename, $bc);
|
||||||
|
$transaction=[];
|
||||||
|
};
|
||||||
return $correct;
|
return $correct;
|
||||||
}
|
}
|
||||||
function artembc_checkbc($filename) {
|
function artembc_checkbc($filename) {
|
||||||
$bc=artembc_load($filename);
|
$bc=artembc_load($filename);
|
||||||
$temp=count($bc);
|
$temp=count($bc);
|
||||||
for ($i = 0, $size = count($bc), $correct2=true; $i < $size; ++$i) {
|
$correct=true;
|
||||||
$transaction=$bc[$i];
|
$correct2=true;
|
||||||
for($i1 = 0, $size = count($transaction), $correct=true; $i1 < $size; ++$i1) {
|
foreach ($bc as $i => $transaction) {
|
||||||
|
foreach ($transaction["transaction"] as $i1 => $v1) {
|
||||||
if (count($transaction["transaction"])>0){
|
if (count($transaction["transaction"])>0){
|
||||||
$block=$transaction["transaction"][$i1];
|
$tmp=[
|
||||||
$hash=hash("sha256", json_encode([
|
"id"=>$v1["id"],
|
||||||
"id"=>$block["id"],
|
"idblock"=>$v1["idblock"],
|
||||||
"idblock"=>$block["idblock"],
|
"time"=>$v1["time"],
|
||||||
"time"=>$block["time"],
|
"data"=>$v1["data"]
|
||||||
"data"=>$block["data"]
|
];
|
||||||
]));
|
$hash=hash("sha256", json_encode($tmp));
|
||||||
if ($block["idblock"] != $temp-1 or $hash != $block["hash"]) {
|
if ($v1["idblock"] != $i or $v1["id"] != $i1 or $hash != $v1["hash"]) {
|
||||||
|
global $correct;
|
||||||
$correct=false;
|
$correct=false;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
unset($i1, $v1);
|
||||||
$hash=hash("sha256", json_encode([
|
$hash=hash("sha256", json_encode([
|
||||||
"id"=>$transaction["id"],
|
"id"=>$transaction["id"],
|
||||||
"time"=>$transaction["time"],
|
"time"=>$transaction["time"],
|
||||||
@ -79,12 +84,14 @@ function artembc_checkbc($filename) {
|
|||||||
"transaction"=>$transaction["transaction"],
|
"transaction"=>$transaction["transaction"],
|
||||||
"prevhash"=>$transaction["prevhash"]
|
"prevhash"=>$transaction["prevhash"]
|
||||||
]));
|
]));
|
||||||
if (/*$hash != $transaction["hash"] or */($transaction["prevhash"] != $bc[$temp-1]["hash"] and $i != 0)) {
|
if ($hash != $transaction["hash"] or ($i != 0 and $transaction["prevhash"] != $bc[$i-1]["hash"])) {
|
||||||
$correct2 = [false, $i];
|
global $correct2;
|
||||||
|
$correct2 = false;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return [$correct, $correct2];
|
unset($i, $v);
|
||||||
|
return $correct and $correct2;
|
||||||
}
|
}
|
||||||
function artembc_getblock($filename, $id) {
|
function artembc_getblock($filename, $id) {
|
||||||
$temp=artembc_load($filename);
|
$temp=artembc_load($filename);
|
||||||
|
Reference in New Issue
Block a user