-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: fornite maggiori informazioni
- Loading branch information
Showing
4 changed files
with
53 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"merkleRoot": "36d12cb8e28699290b0cef1ea5a1fadfd2c6bc4afad02633330e86b197b61884", | ||
"txHash": "0x4de4beaf81e16c53537f1369180ab77a803b4251d8a29a6ee937b5f72af8a0c9", | ||
"timestamp": 1683380719 | ||
} | ||
[ | ||
{ | ||
"merkleRoot": "36d12cb8e28699290b0cef1ea5a1fadfd2c6bc4afad02633330e86b197b61884", | ||
"txHash": "0x4de4beaf81e16c53537f1369180ab77a803b4251d8a29a6ee937b5f72af8a0c9", | ||
"timestamp": 1683380719 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,51 @@ | ||
<?php | ||
|
||
require __DIR__ . '/src/MerkleRoot.php'; | ||
require __DIR__ . '/src/MerkleRootCalculator.php'; | ||
|
||
/** | ||
* Questa funzione carica un file e ne restituisce il contenuto in formato json | ||
* | ||
* @param string $filename | ||
* @return json | ||
*/ | ||
function loadFile($filename){ | ||
// verifico l'esistenza del file | ||
if (file_exists($filename)) { | ||
$json = json_decode(file_get_contents($filename)); | ||
} else { | ||
echo "Il file {$filename} non esiste.\n"; | ||
die(); | ||
} | ||
|
||
// verifico se il file è un json | ||
if ((json_last_error() === JSON_ERROR_NONE) == false) { | ||
echo "Il file {$filename} contiene un errore e non viene riconosciuto.\n"; | ||
die(); | ||
} | ||
return $json; | ||
} | ||
|
||
// carica il json del Qldb | ||
$data_qldb = json_decode(file_get_contents('qldb.json')); | ||
/** | ||
* Inizio della verifica | ||
*/ | ||
echo "Merkle Root Calculator\n\n"; | ||
|
||
// carica il json della Blockchain | ||
$data_blockchain = json_decode(file_get_contents('blockchain.json')); | ||
// carico il contenuto dei file json | ||
$qldb_data = loadFile('qldb.json'); | ||
$blockchain_data = loadFile('blockchain.json'); | ||
|
||
// genero l'array di hash di qldb | ||
foreach ($data_qldb as $data){ | ||
$qldb[] = $data->document_hash; | ||
} | ||
foreach ($qldb_data as $data) $qldb_hashes[] = $data->document_hash; | ||
|
||
// inizializzo la classe | ||
$merkle = new MerkleRoot(); | ||
// prendo solo l'elemento 0 del json della blockchain | ||
$blockchain_data = $blockchain_data[0]; | ||
|
||
// genero il Merkle root con i dati da qldb | ||
$root_qldb = $merkle->root($qldb); | ||
// inizializzo la classe e calcolo il Merkle root con gli hash ricavati dal qldb | ||
$merkle = new MerkleRootCalculator(); | ||
$qldb_root = $merkle->root($qldb_hashes); | ||
|
||
echo "Merkle Root Calculator\n\n"; | ||
echo "Hash Transazione: ". $data_blockchain->txHash ."\n"; | ||
echo "Merkle root da Blockchain: $data_blockchain->merkleRoot\n"; | ||
echo "Merkle root da QLDB: $root_qldb\n"; | ||
echo "Verifica Merkle root: " . ($merkle->verify($qldb, $data_blockchain->merkleRoot) ? 'SUCCESSO' : 'FALLITO') . "\n"; | ||
// stampo il risultato | ||
echo "Merkle root da Blockchain: $blockchain_data->merkleRoot\n"; | ||
echo "Merkle root da QLDB: $qldb_root\n"; | ||
echo "Verifica Merkle root: " . ($merkle->verify($qldb_hashes, $blockchain_data->merkleRoot) ? 'SUCCESSO' : 'FALLITO') . "\n"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* Date: 03.05.2023 | ||
*/ | ||
|
||
class MerkleRoot | ||
class MerkleRootCalculator | ||
{ | ||
/** | ||
* Calcola il Merkle Root | ||
|