Skip to content

Commit 18f1a2a

Browse files
committed
Merge branch 'gen_example_conf'
2 parents 780bae1 + 3a71875 commit 18f1a2a

File tree

8 files changed

+199
-51
lines changed

8 files changed

+199
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ datum_gateway
99

1010
*.conf
1111
*.json
12+
!doc/example_datum_gateway_config.json
1213
.DS_Store
1314
*.orig
1415
*.rej

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.21)
22

33
project(DATUM VERSION 0.2 LANGUAGES C)
44
set(CMAKE_C_STANDARD 23)
5+
6+
include(GNUInstallDirs)
7+
58
add_executable(datum_gateway
69
src/datum_api.c
710
src/datum_blocktemplates.c
@@ -100,3 +103,18 @@ target_compile_options(datum_gateway
100103
${JANSSON_CFLAGS} ${JANSSON_CFLAGS_OTHER}
101104
${SODIUM_CFLAGS} ${SODIUM_CFLAGS_OTHER}
102105
)
106+
107+
set(PREGEN_DOC ${CMAKE_SOURCE_DIR}/doc/example_datum_gateway_config.json)
108+
install(FILES ${PREGEN_DOC} DESTINATION ${CMAKE_INSTALL_DOCDIR})
109+
110+
if(NOT CMAKE_CROSSCOMPILING)
111+
set(GENERATED_DOC ${CMAKE_BINARY_DIR}/CMakeFiles/generated_example_datum_gateway_config.json)
112+
113+
add_custom_command(
114+
TARGET datum_gateway
115+
POST_BUILD
116+
COMMAND ${CMAKE_COMMAND} -DDATUM_GATEWAY=$<TARGET_FILE:datum_gateway> -DGENERATED_DOC=${GENERATED_DOC} -DPREGEN_DOC=${PREGEN_DOC} -P ${PROJECT_SOURCE_DIR}/cmake/script/VerifyExample.cmake
117+
COMMENT "Verifying pre-generated documentation is up-to-date"
118+
VERBATIM
119+
)
120+
endif()

cmake/script/VerifyExample.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
execute_process(
2+
COMMAND ${DATUM_GATEWAY} --example-conf
3+
OUTPUT_VARIABLE CURRENT_EXAMPLE
4+
RESULT_VARIABLE _result
5+
)
6+
if (_result)
7+
message(FATAL_ERROR "${DATUM_GATEWAY} exited with code ${_result}")
8+
endif()
9+
file(WRITE ${GENERATED_DOC} ${CURRENT_EXAMPLE})
10+
file(READ ${PREGEN_DOC} PREGEN_EXAMPLE)
11+
# string(STRIP ${PREGEN_EXAMPLE} PREGEN_EXAMPLE)
12+
# string(STRIP ${CURRENT_EXAMPLE} CURRENT_EXAMPLE)
13+
if(NOT "${CURRENT_EXAMPLE}" STREQUAL "${PREGEN_EXAMPLE}")
14+
message(FATAL_ERROR "${PREGEN_DOC} is outdated. Update it with ${GENERATED_DOC}")
15+
endif()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"bitcoind": {
3+
"rpcuser": "datum",
4+
"rpcpassword": "something only you know",
5+
"rpcurl": "http://localhost:8332",
6+
"notify_fallback": true
7+
},
8+
"stratum": {
9+
"listen_port": 23334
10+
},
11+
"mining": {
12+
"pool_address": "put your own Bitcoin invoice address here",
13+
"coinbase_tag_primary": "DATUM Gateway",
14+
"coinbase_tag_secondary": "DATUM User"
15+
},
16+
"api": {
17+
"admin_password": "",
18+
"listen_port": 7152,
19+
"modify_conf": false
20+
},
21+
"logger": {
22+
"log_to_console": true,
23+
"log_to_file": false,
24+
"log_file": "/var/log/datum.log",
25+
"log_rotate_daily": true,
26+
"log_level_console": 2,
27+
"log_level_file": 1
28+
},
29+
"datum": {
30+
"pool_pass_workers": true,
31+
"pool_pass_full_users": true,
32+
"pooled_mining_only": true
33+
}
34+
}

src/datum_conf.c

Lines changed: 100 additions & 36 deletions
Large diffs are not rendered by default.

src/datum_conf.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@
4545

4646
#include <jansson.h>
4747

48-
#define DATUM_CONF_BOOL 1
49-
#define DATUM_CONF_INT 2
50-
#define DATUM_CONF_STRING 3
51-
#define DATUM_CONF_STRING_ARRAY 4
52-
53-
#define DATUM_CONF_TYPES 5
48+
enum datum_conf_vartype {
49+
DATUM_CONF_BOOL,
50+
DATUM_CONF_INT,
51+
DATUM_CONF_STRING,
52+
DATUM_CONF_STRING_ARRAY,
53+
};
5454

5555
typedef struct {
5656
char category[32];
5757
char name[64];
5858
char description[512];
59-
int var_type;
59+
const char *example;
60+
bool example_default;
61+
enum datum_conf_vartype var_type;
6062
union {
6163
int default_int;
6264
bool default_bool;
@@ -146,6 +148,7 @@ typedef struct {
146148
extern global_config_t datum_config;
147149

148150
int datum_read_config(const char *conffile);
149-
void datum_gateway_help(void);
151+
void datum_gateway_help(const char *argv0);
152+
void datum_gateway_example_conf(void);
150153

151154
#endif

src/datum_gateway.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static char doc[] = "Decentralized Alternative Templates for Universal Mining -
7070
static char args_doc[] = "";
7171
static struct argp_option options[] = {
7272
{"help", '?', 0, 0, "Show custom help", 0},
73+
{"example-conf", 0x100, NULL, 0, "Print an example configuration JSON file", 0},
7374
{"usage", '?', 0, 0, "Show custom help", 0},
7475
{"config", 'c', "FILE", 0, "Configuration JSON file"},
7576
{0}
@@ -83,14 +84,19 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
8384
struct arguments *arguments = state->input;
8485
switch (key) {
8586
case '?': {
86-
datum_gateway_help();
87+
datum_print_banner();
88+
datum_gateway_help(state->argv[0]);
8789
exit(0);
8890
break;
8991
}
9092
case 'c': {
9193
arguments->config_file = arg;
9294
break;
9395
}
96+
case 0x100: // example-conf
97+
datum_gateway_example_conf();
98+
exit(0);
99+
break;
94100
default:
95101
return ARGP_ERR_UNKNOWN;
96102
}
@@ -100,6 +106,14 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
100106
static struct argp argp = {options, parse_opt, args_doc, doc};
101107
// END ARGP Stuff
102108

109+
void datum_print_banner(void) {
110+
printf("\n **************************************************************************\n");
111+
printf(" * DATUM Gateway --- Copyright (c) 2024 Bitcoin Ocean, LLC & Jason Hughes *\n");
112+
printf(" * git commit: %-58s *\n", GIT_COMMIT_HASH);
113+
printf(" **************************************************************************\n\n");
114+
fflush(stdout);
115+
}
116+
103117
void handle_sigusr1(int sig) {
104118
datum_blocktemplates_notifynew(NULL, 0);
105119
}
@@ -119,19 +133,14 @@ int main(const int argc, const char * const * const argv) {
119133
bool rejecting_stratum = false;
120134
uint32_t next_reconnect_attempt_ms = 5000;
121135

122-
printf("\n **************************************************************************\n");
123-
printf(" * DATUM Gateway --- Copyright (c) 2024 Bitcoin Ocean, LLC & Jason Hughes *\n");
124-
printf(" * git commit: %-58s *\n", GIT_COMMIT_HASH);
125-
printf(" **************************************************************************\n\n");
126-
fflush(stdout);
127-
128136
// listen for block notifications
129137
// set this up early so a notification doesn't break our init
130138
sa.sa_handler = handle_sigusr1;
131139
sa.sa_flags = 0;
132140
sigemptyset(&sa.sa_mask);
133141

134142
if (sigaction(SIGUSR1, &sa, NULL) == -1) {
143+
datum_print_banner();
135144
DLOG_FATAL("Could not setup signal handler!");
136145
perror("sigaction");
137146
usleep(100000);
@@ -148,9 +157,11 @@ int main(const int argc, const char * const * const argv) {
148157

149158
arguments.config_file = "datum_gateway_config.json"; // Default config file
150159
if (argp_parse(&argp, argc, datum_deepcopy_charpp(argv), 0, 0, &arguments) != 0) {
160+
datum_print_banner();
151161
DLOG_FATAL("Error parsing arguments. Check --help");
152162
exit(1);
153163
}
164+
datum_print_banner();
154165

155166
if (datum_read_config(arguments.config_file) != 1) {
156167
DLOG_FATAL("Error reading config file. Check --help");

src/datum_gateway.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
#define STRATUM_JOB_INDEX_XOR ((uint16_t)0xC0DE)
5757

58+
void datum_print_banner(void);
59+
5860
extern const char *datum_gateway_config_filename;
5961

6062
extern const char * const *datum_argv;

0 commit comments

Comments
 (0)