Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor utility functions #4745

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nano/secure/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std::filesystem::path nano::working_path (nano::networks network)
return result;
}

std::filesystem::path nano::unique_path (nano::networks network)
std::filesystem::path nano::random_filename ()
{
std::random_device rd;
std::mt19937 gen (rd ());
Expand All @@ -61,8 +61,12 @@ std::filesystem::path nano::unique_path (nano::networks network)
{
random_string += hex_chars[dis (gen)];
}
return std::filesystem::path{ random_string };
}

auto result = working_path (network) / random_string;
std::filesystem::path nano::unique_path (nano::networks network)
{
auto result = working_path (network) / random_filename ();

std::filesystem::create_directories (result);

Expand Down
2 changes: 2 additions & 0 deletions nano/secure/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace nano
std::filesystem::path app_path ();
// OS-specific way of finding a path to a home directory.
std::filesystem::path working_path (nano::networks network = nano::network_constants::active_network);
// Construct a random filename
std::filesystem::path random_filename ();
// Get a unique path within the home directory, used for testing.
// Any directories created at this location will be removed when a test finishes.
std::filesystem::path unique_path (nano::networks network = nano::network_constants::active_network);
Expand Down
1 change: 1 addition & 0 deletions nano/store/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ add_library(
nano_store
account.hpp
block.hpp
block_w_sideband.hpp
component.hpp
confirmation_height.hpp
db_val.hpp
Expand Down
7 changes: 1 addition & 6 deletions nano/store/block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <nano/lib/block_sideband.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/store/block_w_sideband.hpp>
#include <nano/store/component.hpp>
#include <nano/store/iterator.hpp>

Expand All @@ -15,12 +16,6 @@ class block_hash;
}
namespace nano::store
{
class block_w_sideband
{
public:
std::shared_ptr<nano::block> block;
nano::block_sideband sideband;
};
/**
* Manages block storage and iteration
*/
Expand Down
19 changes: 19 additions & 0 deletions nano/store/block_w_sideband.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <nano/lib/block_sideband.hpp>

#include <memory>

namespace nano
{
class block;
}
namespace nano::store
{
class block_w_sideband
{
public:
std::shared_ptr<nano::block> block;
nano::block_sideband sideband;
};
}
Loading