| 142 | }; |
| 143 | |
| 144 | int main(int argc, char* argv[]) |
| 145 | { |
| 146 | // SETUP: Argument parsing and handling |
| 147 | const bool has_regtest_flag{argc == 3 && std::string(argv[1]) == "-regtest"}; |
| 148 | if (argc < 2 || argc > 3 || (argc == 3 && !has_regtest_flag)) { |
| 149 | std::cerr |
| 150 | << "Usage: " << argv[0] << " [-regtest] DATADIR" << std::endl |
| 151 | << "Display DATADIR information, and process hex-encoded blocks on standard input." << std::endl |
| 152 | << "Uses mainnet parameters by default, regtest with -regtest flag" << std::endl |
| 153 | << std::endl |
| 154 | << "IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING ONLY, AND EXPECTED TO" << std::endl |
| 155 | << " BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl; |
| 156 | return 1; |
| 157 | } |
| 158 | std::filesystem::path abs_datadir{std::filesystem::absolute(argv[argc-1])}; |
| 159 | std::filesystem::create_directories(abs_datadir); |
| 160 | |
| 161 | btck_LoggingOptions logging_options = { |
| 162 | .log_timestamps = true, |
| 163 | .log_time_micros = false, |
| 164 | .log_threadnames = false, |
| 165 | .log_sourcelocations = false, |
| 166 | .always_print_category_levels = true, |
| 167 | }; |
| 168 | |
| 169 | logging_set_options(logging_options); |
| 170 | |
| 171 | Logger logger{std::make_unique<KernelLog>()}; |
| 172 | |
| 173 | ContextOptions options{}; |
| 174 | ChainParams params{has_regtest_flag ? ChainType::REGTEST : ChainType::MAINNET}; |
| 175 | options.SetChainParams(params); |
| 176 | |
| 177 | options.SetNotifications(std::make_shared<TestKernelNotifications>()); |
| 178 | options.SetValidationInterface(std::make_shared<TestValidationInterface>()); |
| 179 | |
| 180 | Context context{options}; |
| 181 | |
| 182 | ChainstateManagerOptions chainman_opts{context, abs_datadir.string(), (abs_datadir / "blocks").string()}; |
| 183 | chainman_opts.SetWorkerThreads(4); |
| 184 | |
| 185 | std::unique_ptr<ChainMan> chainman; |
| 186 | try { |
| 187 | chainman = std::make_unique<ChainMan>(context, chainman_opts); |
| 188 | } catch (std::exception&) { |
| 189 | std::cerr << "Failed to instantiate ChainMan, exiting" << std::endl; |
| 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | std::cout << "Enter the block you want to validate on the next line:" << std::endl; |
| 194 | |
| 195 | for (std::string line; std::getline(std::cin, line);) { |
| 196 | if (line.empty()) { |
| 197 | std::cerr << "Empty line found, try again:" << std::endl; |
| 198 | continue; |
| 199 | } |
| 200 | |
| 201 | auto raw_block{hex_string_to_byte_vec(line)}; |
nothing calls this directly
no test coverage detected