Skip to content

Commit

Permalink
Merge pull request nanocurrency#4745 from clemahieu/factor_utility_fu…
Browse files Browse the repository at this point in the history
…nctions

Factor utility functions
  • Loading branch information
clemahieu authored Oct 7, 2024
2 parents ab093d5 + 057cacd commit 5e9ca84
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
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;
};
}

0 comments on commit 5e9ca84

Please sign in to comment.