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 ;
@@ -110,6 +115,8 @@ MAIN_FUNCTION
110
115
return EXIT_FAILURE;
111
116
}
112
117
118
+ ECC_Context ecc_context{};
119
+
113
120
// Connect to existing bitcoin-node process or spawn new one.
114
121
std::unique_ptr<interfaces::Init> mine_init{interfaces::MakeMineInit (argc, argv)};
115
122
assert (mine_init);
@@ -128,6 +135,25 @@ MAIN_FUNCTION
128
135
std::unique_ptr<interfaces::Mining> mining{node_init->makeMining ()};
129
136
assert (mining);
130
137
138
+ auto tp = std::make_unique<Sv2TemplateProvider>(*mining);
139
+
140
+ uint16_t sv2_port;
141
+ const std::string sv2_port_arg = args.GetArg (" -sv2port" , " " );
142
+
143
+ if (sv2_port_arg.empty ()) {
144
+ sv2_port = BaseParams ().Sv2Port ();
145
+ } else {
146
+ if (!ParseUInt16 (sv2_port_arg, &sv2_port) || sv2_port == 0 ) {
147
+ tfm::format (std::cerr, " %s\n " , InvalidPortErrMsg (" sv2port" , sv2_port_arg).original );
148
+ return EXIT_FAILURE;
149
+ }
150
+ }
151
+
152
+ if (!tp->Start (Sv2TemplateProviderOptions { .port = sv2_port })) {
153
+ tfm::format (std::cerr, " Unable to start Stratum v2 Template Provider" );
154
+ return EXIT_FAILURE;
155
+ }
156
+
131
157
#ifndef WIN32
132
158
registerSignalHandler (SIGTERM, HandleSIGTERM);
133
159
registerSignalHandler (SIGINT, HandleSIGTERM);
@@ -137,5 +163,9 @@ MAIN_FUNCTION
137
163
UninterruptibleSleep (100ms);
138
164
}
139
165
166
+ tp->Interrupt ();
167
+ tp->StopThreads ();
168
+ tp.reset ();
169
+
140
170
return EXIT_SUCCESS;
141
171
}
0 commit comments