diff --git a/src/datum_blocktemplates.c b/src/datum_blocktemplates.c index 21d0a65..ceff6e9 100644 --- a/src/datum_blocktemplates.c +++ b/src/datum_blocktemplates.c @@ -349,7 +349,7 @@ void *datum_gateway_fallback_notifier(void *args) { while(1) { snprintf(req, sizeof(req), "{\"jsonrpc\":\"1.0\",\"id\":\"%"PRIu64"\",\"method\":\"getbestblockhash\",\"params\":[]}", current_time_millis()); - gbbh = json_rpc_call(tcurl, datum_config.bitcoind_rpcurl, datum_config.bitcoind_rpcuserpass, req); + gbbh = bitcoind_json_rpc_call(tcurl, &datum_config, req); if (gbbh) { res_val = json_object_get(gbbh, "result"); if (!res_val) { @@ -415,7 +415,7 @@ void *datum_gateway_template_thread(void *args) { // fetch latest template snprintf(gbt_req, sizeof(gbt_req), "{\"method\":\"getblocktemplate\",\"params\":[{\"rules\":[\"segwit\"]}],\"id\":%"PRIu64"}",(uint64_t)((uint64_t)time(NULL)<<(uint64_t)8)|(uint64_t)(i&255)); - gbt = json_rpc_call(tcurl, datum_config.bitcoind_rpcurl, datum_config.bitcoind_rpcuserpass, gbt_req); + gbt = bitcoind_json_rpc_call(tcurl, &datum_config, gbt_req); if (!gbt) { DLOG_ERROR("Could not fetch new template from %s!", datum_config.bitcoind_rpcurl); diff --git a/src/datum_jsonrpc.c b/src/datum_jsonrpc.c index 9bda530..00a8e0f 100644 --- a/src/datum_jsonrpc.c +++ b/src/datum_jsonrpc.c @@ -41,6 +41,7 @@ #include #include +#include "datum_conf.h" #include "datum_jsonrpc.h" #include "datum_utils.h" @@ -232,3 +233,7 @@ err_out: json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, const char *rpc_req) { return json_rpc_call_full(curl, url, userpass, rpc_req, NULL); } + +json_t *bitcoind_json_rpc_call(CURL * const curl, global_config_t * const cfg, const char * const rpc_req) { + return json_rpc_call(curl, cfg->bitcoind_rpcurl, datum_config.bitcoind_rpcuserpass, rpc_req); +} diff --git a/src/datum_jsonrpc.h b/src/datum_jsonrpc.h index c564e07..3d84576 100644 --- a/src/datum_jsonrpc.h +++ b/src/datum_jsonrpc.h @@ -39,6 +39,8 @@ #include #include +#include "datum_conf.h" + #ifndef JSON_INTEGER_IS_LONG_LONG # error "Jansson 2.0 with long long support required!" #endif @@ -63,5 +65,6 @@ struct upload_buffer { json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass, const char *rpc_req); char *basic_http_call(CURL *curl, const char *url); +json_t *bitcoind_json_rpc_call(CURL *curl, global_config_t *cfg, const char *rpc_req); #endif diff --git a/src/datum_stratum.c b/src/datum_stratum.c index 3f282e9..960a18e 100644 --- a/src/datum_stratum.c +++ b/src/datum_stratum.c @@ -2183,7 +2183,7 @@ int assembleBlockAndSubmit(uint8_t *block_header, uint8_t *coinbase_txn, size_t } // make the call! - r = json_rpc_call(tcurl, datum_config.bitcoind_rpcurl, datum_config.bitcoind_rpcuserpass, submitblock_req); + r = bitcoind_json_rpc_call(tcurl, &datum_config, submitblock_req); curl_easy_cleanup(tcurl); if (!r) { // oddly, this means success here. diff --git a/src/datum_submitblock.c b/src/datum_submitblock.c index 4971c64..d076e99 100644 --- a/src/datum_submitblock.c +++ b/src/datum_submitblock.c @@ -53,9 +53,8 @@ void preciousblock(CURL *curl, char *blockhash) { json_t *json; char rpc_data[384]; - // TODO: Move these types of things to the conf file snprintf(rpc_data, sizeof(rpc_data), "{\"method\":\"preciousblock\",\"params\":[\"%s\"],\"id\":1}", blockhash); - json = json_rpc_call(curl, datum_config.bitcoind_rpcurl, datum_config.bitcoind_rpcuserpass, rpc_data); + json = bitcoind_json_rpc_call(curl, &datum_config, rpc_data); if (!json) return; json_decref(json); @@ -67,7 +66,7 @@ void datum_submitblock_doit(CURL *tcurl, char *url, const char *submitblock_req, char *s = NULL; // TODO: Move these types of things to the conf file if (!url) { - r = json_rpc_call(tcurl, datum_config.bitcoind_rpcurl, datum_config.bitcoind_rpcuserpass, submitblock_req); + r = bitcoind_json_rpc_call(tcurl, &datum_config, submitblock_req); } else { r = json_rpc_call(tcurl, url, NULL, submitblock_req); }