@@ -65,6 +65,8 @@ RecursiveMutex cs_db;
65
65
std::map<std::string, std::weak_ptr<BerkeleyEnvironment>> g_dbenvs GUARDED_BY (cs_db); // !< Map from directory name to db environment.
66
66
} // namespace
67
67
68
+ static constexpr auto REVERSE_BYTE_ORDER{std::endian::native == std::endian::little ? 4321 : 1234 };
69
+
68
70
bool WalletDatabaseFileId::operator ==(const WalletDatabaseFileId& rhs) const
69
71
{
70
72
return memcmp (value, &rhs.value , sizeof (value)) == 0 ;
@@ -300,7 +302,11 @@ static Span<const std::byte> SpanFromDbt(const SafeDbt& dbt)
300
302
}
301
303
302
304
BerkeleyDatabase::BerkeleyDatabase (std::shared_ptr<BerkeleyEnvironment> env, fs::path filename, const DatabaseOptions& options) :
303
- WalletDatabase (), env(std::move(env)), m_filename(std::move(filename)), m_max_log_mb(options.max_log_mb)
305
+ WalletDatabase (),
306
+ env (std::move(env)),
307
+ m_byteswap (options.require_format == DatabaseFormat::BERKELEY_SWAP),
308
+ m_filename (std::move(filename)),
309
+ m_max_log_mb (options.max_log_mb)
304
310
{
305
311
auto inserted = this ->env ->m_databases .emplace (m_filename, std::ref (*this ));
306
312
assert (inserted.second );
@@ -389,6 +395,10 @@ void BerkeleyDatabase::Open()
389
395
}
390
396
}
391
397
398
+ if (m_byteswap) {
399
+ pdb_temp->set_lorder (REVERSE_BYTE_ORDER);
400
+ }
401
+
392
402
ret = pdb_temp->open (nullptr , // Txn pointer
393
403
fMockDb ? nullptr : strFile.c_str (), // Filename
394
404
fMockDb ? strFile.c_str () : " main" , // Logical db name
@@ -521,6 +531,10 @@ bool BerkeleyDatabase::Rewrite(const char* pszSkip)
521
531
BerkeleyBatch db (*this , true );
522
532
std::unique_ptr<Db> pdbCopy = std::make_unique<Db>(env->dbenv .get (), 0 );
523
533
534
+ if (m_byteswap) {
535
+ pdbCopy->set_lorder (REVERSE_BYTE_ORDER);
536
+ }
537
+
524
538
int ret = pdbCopy->open (nullptr , // Txn pointer
525
539
strFileRes.c_str (), // Filename
526
540
" main" , // Logical db name
0 commit comments