Skip to content

Commit 78b1607

Browse files
committed
Run Template Provider from bitcoin-mine
1 parent 5e87f64 commit 78b1607

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/bitcoin-mine.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
#include <chainparamsbase.h>
99
#include <clientversion.h>
1010
#include <common/args.h>
11+
#include <common/messages.h>
1112
#include <common/system.h>
1213
#include <compat/compat.h>
1314
#include <init/common.h>
1415
#include <interfaces/init.h>
1516
#include <interfaces/ipc.h>
1617
#include <logging.h>
18+
#include <node/sv2_template_provider.h>
1719
#include <tinyformat.h>
1820
#include <util/translation.h>
1921

@@ -22,6 +24,9 @@
2224
#include <signal.h>
2325
// #include <sys/stat.h>
2426
#endif
27+
28+
using common::InvalidPortErrMsg;
29+
2530
static const char* const HELP_USAGE{R"(
2631
bitcoin-mine is a test program for interacting with bitcoin-node via IPC.
2732
@@ -38,7 +43,7 @@ static const char* HELP_EXAMPLES{R"(
3843
bitcoin-mine -regtest
3944
4045
# Run with debug output.
41-
bitcoin-mine -regtest -debug
46+
bitcoin-mine -regtest -debug=sv2 -loglevel=sv2:trace
4247
)"};
4348

4449
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
@@ -114,6 +119,8 @@ MAIN_FUNCTION
114119
return EXIT_FAILURE;
115120
}
116121

122+
ECC_Context ecc_context{};
123+
117124
// Connect to existing bitcoin-node process or spawn new one.
118125
std::unique_ptr<interfaces::Init> mine_init{interfaces::MakeMineInit(argc, argv)};
119126
assert(mine_init);
@@ -132,6 +139,25 @@ MAIN_FUNCTION
132139
std::unique_ptr<interfaces::Mining> mining{node_init->makeMining()};
133140
assert(mining);
134141

142+
auto tp = std::make_unique<Sv2TemplateProvider>(*mining);
143+
144+
uint16_t sv2_port;
145+
const std::string sv2_port_arg = args.GetArg("-sv2port", "");
146+
147+
if (sv2_port_arg.empty()) {
148+
sv2_port = BaseParams().Sv2Port();
149+
} else {
150+
if (!ParseUInt16(sv2_port_arg, &sv2_port) || sv2_port == 0) {
151+
tfm::format(std::cerr, "%s\n", InvalidPortErrMsg("sv2port", sv2_port_arg).original);
152+
return EXIT_FAILURE;
153+
}
154+
}
155+
156+
if (!tp->Start(Sv2TemplateProviderOptions { .port = sv2_port })) {
157+
tfm::format(std::cerr, "Unable to start Stratum v2 Template Provider");
158+
return EXIT_FAILURE;
159+
}
160+
135161
#ifndef WIN32
136162
registerSignalHandler(SIGTERM, HandleSIGTERM);
137163
registerSignalHandler(SIGINT, HandleSIGTERM);
@@ -141,5 +167,9 @@ MAIN_FUNCTION
141167
UninterruptibleSleep(100ms);
142168
}
143169

170+
tp->Interrupt();
171+
tp->StopThreads();
172+
tp.reset();
173+
144174
return EXIT_SUCCESS;
145175
}

0 commit comments

Comments
 (0)