diff options
Diffstat (limited to 'src/wallet/migrate.cpp')
-rw-r--r-- | src/wallet/migrate.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/wallet/migrate.cpp b/src/wallet/migrate.cpp index e567cb0f51..f922d99a17 100644 --- a/src/wallet/migrate.cpp +++ b/src/wallet/migrate.cpp @@ -21,17 +21,42 @@ bool BerkeleyRODatabase::Backup(const std::string& dest) const bool BerkeleyROBatch::ReadKey(DataStream&& key, DataStream& value) { - return false; + SerializeData key_data{key.begin(), key.end()}; + const auto it{m_database.m_records.find(key_data)}; + if (it == m_database.m_records.end()) { + return false; + } + auto val = it->second; + value.clear(); + value.write(Span(val)); + return true; } bool BerkeleyROBatch::HasKey(DataStream&& key) { - return false; + SerializeData key_data{key.begin(), key.end()}; + return m_database.m_records.count(key_data) > 0; +} + +BerkeleyROCursor::BerkeleyROCursor(const BerkeleyRODatabase& database, Span<const std::byte> prefix) + : m_database(database) +{ + std::tie(m_cursor, m_cursor_end) = m_database.m_records.equal_range(BytePrefix{prefix}); } DatabaseCursor::Status BerkeleyROCursor::Next(DataStream& ssKey, DataStream& ssValue) { - return DatabaseCursor::Status::FAIL; + if (m_cursor == m_cursor_end) { + return DatabaseCursor::Status::DONE; + } + ssKey.write(Span(m_cursor->first)); + ssValue.write(Span(m_cursor->second)); + m_cursor++; + return DatabaseCursor::Status::MORE; } +std::unique_ptr<DatabaseCursor> BerkeleyROBatch::GetNewPrefixCursor(Span<const std::byte> prefix) +{ + return std::make_unique<BerkeleyROCursor>(m_database, prefix); +} } // namespace wallet |