Минус 1 функция и плюс 2 функции

This commit is contained in:
artemuhi 2024-03-07 20:36:43 +03:00
parent 0605d565d2
commit 34c9e63a5d

View File

@ -1,17 +1,5 @@
<?php
class artembc {}
function artembc_init($filename, $lock=true, $max_size=400094) {
$bc=new artembc;
$bc->max_size=$max_size;
$bc->file=fopen($filename, "w+");
if ($lock) {
if (!flock($bc->file, LOCK_EX)) {
return false;
}
}
return $bc;
}
function artembc_createbc($bc, $data=[]) {
function artembc_createbc($filename, $data=[]) {
$temp=[[
"id"=>0,
"time"=>time(),
@ -19,7 +7,7 @@ function artembc_createbc($bc, $data=[]) {
"transaction"=>[]
]];
$temp["hash"]=hash("sha256", json_encode($temp));
return fwrite($bc->file, json_encode($temp), $bc->max_size);
return artembc_save($filename, $temp);
}
function artembc_addtransaction() {}
function artembc_initblock() {}
@ -27,4 +15,10 @@ function artembc_checkbc() {}
function artembc_getblock() {}
function artembc_getbc() {}
function artembc_getnamebc() {}
function artembc_save($filename, $data) {
return file_put_contents($filename, json_encode($data));
}
function artembc_load($filename) {
return json_decode(file_get_contents($filename));
}
?>