Abstract userpass concatenation to bitcoind_json_rpc_call helper

This commit is contained in:
Luke Dashjr 2025-01-15 20:20:38 +00:00
commit 6f743b8031
No known key found for this signature in database
GPG Key ID: A291A2C45D0C504A
5 changed files with 13 additions and 6 deletions

View File

@ -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);

View File

@ -41,6 +41,7 @@
#include <jansson.h>
#include <stdbool.h>
#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);
}

View File

@ -39,6 +39,8 @@
#include <curl/curl.h>
#include <jansson.h>
#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

View File

@ -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.

View File

@ -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);
}