@@ -74,77 +74,16 @@ static const std::set<std::string> log_levels
74
74
namespace cbdc ::generate_config {
75
75
76
76
config_generator::config_generator (std::string& _template_config_file,
77
- const size_t _start_port,
78
- std::string _build_dir)
77
+ const size_t _start_port)
79
78
: m_template_config_file(_template_config_file),
80
79
m_current_port (_start_port) {
81
80
// Get Project root dir and build dir
82
81
std::filesystem::path build_dir = std::filesystem::current_path ();
83
- if (_build_dir.at (_build_dir.size () - 1 ) == ' /' ) {
84
- _build_dir.erase (_build_dir.end () - 1 );
85
- }
86
82
// This config generator class assumes project root is "opencbdc-tx"
87
- while (build_dir.has_parent_path ()) {
88
- if (build_dir.filename () != " opencbdc-tx" ) {
89
- build_dir = build_dir.parent_path ();
90
- } else {
91
- m_project_root_dir = build_dir;
92
- std::string delimiter = " /" ;
93
- std::string tmp_str = _build_dir;
94
- size_t pos = 0 ;
95
- std::string token;
96
- while ((pos = tmp_str.find (' /' )) != std::string::npos) {
97
- token = tmp_str.substr (0 , pos);
98
- build_dir = build_dir.append (token);
99
- tmp_str.erase (0 , pos + delimiter.length ());
100
- }
101
- token = tmp_str.substr (0 , pos);
102
- build_dir = build_dir.append (token);
103
- tmp_str.erase (0 , pos + delimiter.length ());
104
- m_build_dir = build_dir;
105
- std::cerr << " Build directory determined to be "
106
- << m_build_dir.string () << std::endl;
107
- std::cerr << " Project Root directory determined to be "
108
- << m_project_root_dir.string () << std::endl;
109
- break ;
110
- }
111
- }
112
- template_file_is_valid = true ;
113
83
if (!std::filesystem::exists (m_template_config_file)) {
114
- template_file_is_valid = false ;
115
- std::filesystem::path temp_config_tools_dir = m_project_root_dir;
116
- temp_config_tools_dir.append (" config" ).append (" tools" );
117
- std::filesystem::path temp_build_config_tools_dir = m_build_dir;
118
- temp_build_config_tools_dir.append (" config" ).append (" tools" );
119
- std::cerr << " Warning: File provided, " << m_template_config_file
120
- << " , does not exist. Attempting to copy it from its "
121
- " original location, "
122
- << temp_config_tools_dir.string () << " to "
123
- << temp_build_config_tools_dir.string () << std::endl;
124
- copy_templates_to_build_dir ();
125
- // Try to use newly copied template files
126
- std::string delimiter = " /" ;
127
- std::string tmp_str = m_template_config_file;
128
- size_t pos = 0 ;
129
- std::string template_filename;
130
- while ((pos = tmp_str.find (' /' )) != std::string::npos) {
131
- template_filename = tmp_str.substr (0 , pos);
132
- tmp_str.erase (0 , pos + delimiter.length ());
133
- }
134
- template_filename = tmp_str.substr (0 , pos);
135
- std::filesystem::path full_template_path_and_filename
136
- = temp_build_config_tools_dir.append (template_filename);
137
- if (std::filesystem::exists (full_template_path_and_filename)) {
138
- m_template_config_file
139
- = full_template_path_and_filename.string ();
140
- template_file_is_valid = true ;
141
- std::cerr << " Successfully copied " << template_filename
142
- << " from " << temp_config_tools_dir.string ()
143
- << " to " << temp_build_config_tools_dir.string ()
144
- << " . Using "
145
- << full_template_path_and_filename.string ()
146
- << " as template file." << std::endl;
147
- }
84
+ m_template_file_is_valid = false ;
85
+ std::cerr << " template file cannot be found at "
86
+ << _template_config_file << std::endl;
148
87
}
149
88
}
150
89
@@ -749,7 +688,7 @@ namespace cbdc::generate_config {
749
688
// Cumulative return message
750
689
std::string return_msg;
751
690
752
- if (!template_file_is_valid ) {
691
+ if (!m_template_file_is_valid ) {
753
692
std::filesystem::path temp_build_dir = m_build_dir;
754
693
temp_build_dir.append (" config" ).append (" tools" );
755
694
return_msg += " File provided, " + m_template_config_file
@@ -855,9 +794,17 @@ namespace cbdc::generate_config {
855
794
}
856
795
// add support for pre-seeding
857
796
// only has effect if pre-seeding is active
858
- std::pair<std::string, std::string> key_pair = create_key_pair ();
859
- set_param_to_config_file (seed_privkey, key_pair.first );
860
- write_generated_config_to_file ();
797
+ const auto seed_begin
798
+ = get_param_from_template_file (seed_from, config_map);
799
+ const auto seed_end
800
+ = get_param_from_template_file (seed_to, config_map);
801
+ if (!std::holds_alternative<std::string>(seed_begin)
802
+ && !std::holds_alternative<std::string>(seed_end)
803
+ && std::get<size_t >(seed_begin) != std::get<size_t >(seed_end)) {
804
+ std::pair<std::string, std::string> key_pair = create_key_pair ();
805
+ set_param_to_config_file (seed_privkey, key_pair.first );
806
+ write_generated_config_to_file ();
807
+ }
861
808
return_msg += " SUCCESS" ;
862
809
return return_msg;
863
810
}
0 commit comments