@@ -3674,6 +3674,69 @@ UniValue logdvmstate(const JSONRPCRequest &request) {
3674
3674
return {};
3675
3675
}
3676
3676
3677
+ UniValue logdbhashes (const JSONRPCRequest &request) {
3678
+ RPCHelpMan{
3679
+ " logdbhashes" ,
3680
+ " Hash the DVM and EVM databases.\n " ,
3681
+ {},
3682
+ RPCResult{" {\n "
3683
+ " \" height\" : xxxxx, (numeric) The current block height\n "
3684
+ " \" dvmhash\" : \" hash\" (string) The SHA256 hash of the database dump files\n "
3685
+ " }\n " },
3686
+ RPCExamples{HelpExampleCli (" logdbhashes" , " " )},
3687
+ }
3688
+ .Check (request);
3689
+
3690
+ LOCK (cs_main);
3691
+
3692
+ // Flush any pending changes to the DB. Not always written to disk.
3693
+ pcustomcsview->Flush ();
3694
+ pcustomcsDB->Flush ();
3695
+
3696
+ // Get the CDBWrapper instance from CCustomCSView
3697
+ auto db = pcustomcsview->GetStorage ().GetStorageLevelDB ()->GetDB ();
3698
+
3699
+ // Create a CDBIterator
3700
+ auto pcursor = db->NewIterator (leveldb::ReadOptions ());
3701
+
3702
+ // Create a SHA256 hasher
3703
+ CSHA256 hasher;
3704
+
3705
+ // Seek to the beginning of the database
3706
+ pcursor->SeekToFirst ();
3707
+
3708
+ // Iterate over all key-value pairs
3709
+ while (pcursor->Valid ()) {
3710
+ // Get the key and value slices
3711
+ auto keySlice = pcursor->GetKey ();
3712
+ auto valueSlice = pcursor->GetValue ();
3713
+
3714
+ // Feed the key and value into the hasher
3715
+ hasher.Write ((const unsigned char *)keySlice.data (), keySlice.size ());
3716
+ hasher.Write ((const unsigned char *)valueSlice.data (), valueSlice.size ());
3717
+
3718
+ // Move to the next key-value pair
3719
+ pcursor->Next ();
3720
+ }
3721
+
3722
+ // Finalize the hash
3723
+ unsigned char hash[CSHA256::OUTPUT_SIZE];
3724
+ hasher.Finalize (hash);
3725
+
3726
+ // Convert hash to hex string
3727
+ const auto hashHex = HexStr (hash, hash + CSHA256::OUTPUT_SIZE);
3728
+
3729
+ // Get the current block height
3730
+ const auto height = ::ChainActive ().Height ();
3731
+
3732
+ // Prepare result
3733
+ UniValue result (UniValue::VOBJ);
3734
+ result.pushKV (" height" , height);
3735
+ result.pushKV (" dvmhash" , hashHex);
3736
+
3737
+ return result;
3738
+ }
3739
+
3677
3740
static const CRPCCommand commands[] = {
3678
3741
// category name actor (function) params
3679
3742
// ------------- ------------------------ ---------------------- ----------
@@ -3706,6 +3769,7 @@ static const CRPCCommand commands[] = {
3706
3769
{" accounts" , " getlockedtokens" , &getlockedtokens, {" address" } },
3707
3770
{" accounts" , " releaselockedtokens" , &releaselockedtokens, {" releasePart" } },
3708
3771
{" hidden" , " logdvmstate" , &logdvmstate, {" size" } },
3772
+ {" hidden" , " logdbhashes" , &logdbhashes, {" " } },
3709
3773
};
3710
3774
3711
3775
void RegisterAccountsRPCCommands (CRPCTable &tableRPC) {
0 commit comments