8
8
#include < chainparamsbase.h>
9
9
#include < clientversion.h>
10
10
#include < common/args.h>
11
+ #include < common/messages.h>
11
12
#include < common/system.h>
12
13
#include < compat/compat.h>
13
14
#include < init/common.h>
14
15
#include < interfaces/init.h>
15
16
#include < interfaces/ipc.h>
16
17
#include < logging.h>
18
+ #include < node/sv2_template_provider.h>
17
19
#include < tinyformat.h>
18
20
#include < util/translation.h>
19
21
22
24
#include < signal.h>
23
25
// #include <sys/stat.h>
24
26
#endif
27
+
28
+ using common::InvalidPortErrMsg;
29
+
25
30
static const char * const HELP_USAGE{R"(
26
31
bitcoin-mine is a test program for interacting with bitcoin-node via IPC.
27
32
@@ -38,7 +43,7 @@ static const char* HELP_EXAMPLES{R"(
38
43
bitcoin-mine -regtest
39
44
40
45
# Run with debug output.
41
- bitcoin-mine -regtest -debug
46
+ bitcoin-mine -regtest -debug=sv2 -loglevel=sv2:trace
42
47
)" };
43
48
44
49
const std::function<std::string(const char *)> G_TRANSLATION_FUN = nullptr ;
@@ -114,6 +119,8 @@ MAIN_FUNCTION
114
119
return EXIT_FAILURE;
115
120
}
116
121
122
+ ECC_Context ecc_context{};
123
+
117
124
// Connect to existing bitcoin-node process or spawn new one.
118
125
std::unique_ptr<interfaces::Init> mine_init{interfaces::MakeMineInit (argc, argv)};
119
126
assert (mine_init);
@@ -132,6 +139,25 @@ MAIN_FUNCTION
132
139
std::unique_ptr<interfaces::Mining> mining{node_init->makeMining ()};
133
140
assert (mining);
134
141
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
+
135
161
#ifndef WIN32
136
162
registerSignalHandler (SIGTERM, HandleSIGTERM);
137
163
registerSignalHandler (SIGINT, HandleSIGTERM);
@@ -141,5 +167,9 @@ MAIN_FUNCTION
141
167
UninterruptibleSleep (100ms);
142
168
}
143
169
170
+ tp->Interrupt ();
171
+ tp->StopThreads ();
172
+ tp.reset ();
173
+
144
174
return EXIT_SUCCESS;
145
175
}
0 commit comments