From d831937f12fd59f98cdab2401ec15237b19d6a92 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 16 Sep 2024 13:27:52 +0100 Subject: [PATCH 1/2] Extract function to create a random filename. --- nano/secure/utility.cpp | 8 ++++++-- nano/secure/utility.hpp | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/nano/secure/utility.cpp b/nano/secure/utility.cpp index ac974d9f56..a2dabd5e3b 100644 --- a/nano/secure/utility.cpp +++ b/nano/secure/utility.cpp @@ -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 ()); @@ -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); diff --git a/nano/secure/utility.hpp b/nano/secure/utility.hpp index abb70df840..90953eea01 100644 --- a/nano/secure/utility.hpp +++ b/nano/secure/utility.hpp @@ -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); From 057cacd6fd2166f12ac48bd290acadca7f7d0596 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 26 Sep 2024 12:29:38 +0100 Subject: [PATCH 2/2] Extracting block_w_sideband to its own file --- nano/store/CMakeLists.txt | 1 + nano/store/block.hpp | 7 +------ nano/store/block_w_sideband.hpp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 nano/store/block_w_sideband.hpp diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 68cde103a1..19ae4cf2ef 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -2,6 +2,7 @@ add_library( nano_store account.hpp block.hpp + block_w_sideband.hpp component.hpp confirmation_height.hpp db_val.hpp diff --git a/nano/store/block.hpp b/nano/store/block.hpp index 91b60babc2..17f92669d0 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -15,12 +16,6 @@ class block_hash; } namespace nano::store { -class block_w_sideband -{ -public: - std::shared_ptr block; - nano::block_sideband sideband; -}; /** * Manages block storage and iteration */ diff --git a/nano/store/block_w_sideband.hpp b/nano/store/block_w_sideband.hpp new file mode 100644 index 0000000000..e83bd71d5c --- /dev/null +++ b/nano/store/block_w_sideband.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include + +namespace nano +{ +class block; +} +namespace nano::store +{ +class block_w_sideband +{ +public: + std::shared_ptr block; + nano::block_sideband sideband; +}; +}