From 532cff9e559667bf2d2916769db6e8674345a334 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Sun, 26 Oct 2014 13:21:26 -0500 Subject: [PATCH] Fixing issues with wallet. --- rai/core/core.cpp | 18 +++++++++++++----- rai/core/core.hpp | 2 +- rai/test/wallet_test.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/rai/core/core.cpp b/rai/core/core.cpp index e8c83017..42d890a1 100644 --- a/rai/core/core.cpp +++ b/rai/core/core.cpp @@ -478,7 +478,9 @@ password (0, 1024) { leveldb::Options options; options.create_if_missing = true; - auto status (leveldb::DB::Open (options, (path_a / "wallet.ldb").string (), &handle)); + leveldb::DB * db (nullptr); + auto status (leveldb::DB::Open (options, (path_a / "wallet.ldb").string (), &db)); + handle.reset (db); if (status.ok ()) { rai::uint256_union wallet_password_key; @@ -512,6 +514,12 @@ password (0, 1024) wallet_key.clear (); password_l.clear (); } + else + { + auto password_l (derive_key ("")); + password.value_set (password_l); + } + init_a = false; } else { @@ -607,7 +615,7 @@ rai::key_entry & rai::key_iterator::operator -> () rai::key_iterator rai::wallet::begin () { - rai::key_iterator result (handle); + rai::key_iterator result (handle.get ()); for (auto i (0); i < special_count; ++i) { assert (result != end ()); @@ -618,8 +626,8 @@ rai::key_iterator rai::wallet::begin () rai::key_iterator rai::wallet::find (rai::uint256_union const & key) { - rai::key_iterator result (handle, key); - rai::key_iterator end (handle, nullptr); + rai::key_iterator result (handle.get (), key); + rai::key_iterator end (handle.get (), nullptr); if (result != end) { if (result.current.first == key) @@ -639,7 +647,7 @@ rai::key_iterator rai::wallet::find (rai::uint256_union const & key) rai::key_iterator rai::wallet::end () { - return rai::key_iterator (handle, nullptr); + return rai::key_iterator (handle.get (), nullptr); } bool rai::key_iterator::operator == (rai::key_iterator const & other_a) const diff --git a/rai/core/core.hpp b/rai/core/core.hpp index 4746b6ec..a0737ae8 100644 --- a/rai/core/core.hpp +++ b/rai/core/core.hpp @@ -285,7 +285,7 @@ namespace rai { static rai::uint256_union const check_special; static int const special_count; private: - leveldb::DB * handle; + std::unique_ptr handle; }; class operation { diff --git a/rai/test/wallet_test.cpp b/rai/test/wallet_test.cpp index f5479444..7387b8b1 100644 --- a/rai/test/wallet_test.cpp +++ b/rai/test/wallet_test.cpp @@ -330,6 +330,13 @@ TEST (wallet, bad_path) ASSERT_TRUE (init); } +TEST (wallet, correct) +{ + bool init (true); + rai::wallet store (init, boost::filesystem::unique_path ()); + ASSERT_FALSE (init); +} + TEST (wallet, already_open) { auto path (boost::filesystem::unique_path ()); @@ -340,4 +347,21 @@ TEST (wallet, already_open) bool init; rai::wallet store (init, path); ASSERT_TRUE (init); +} + +TEST (wallet, repoen_default_password) +{ + auto path (boost::filesystem::unique_path ()); + { + bool init; + rai::wallet wallet (init, path); + ASSERT_FALSE (init); + ASSERT_TRUE (wallet.valid_password ()); + } + { + bool init; + rai::wallet wallet (init, path); + ASSERT_FALSE (init); + ASSERT_TRUE (wallet.valid_password ()); + } } \ No newline at end of file