Browse Source

Begin gbt parsing file with a validate address function

master
Con Kolivas 11 years ago
parent
commit
de0a616250
  1. 2
      src/Makefile.am
  2. 77
      src/gbt.c
  3. 10
      src/gbt.h
  4. 2
      src/libckpool.c

2
src/Makefile.am

@ -5,5 +5,5 @@ libckpool_la_SOURCES = libckpool.c libckpool.h
libckpool_la_LIBADD = @PTHREAD_LIBS@ @MATH_LIBS@ @RT_LIBS@ @JANSSON_LIBS@
bin_PROGRAMS = ckpool
ckpool_SOURCES = ckpool.c ckpool.h
ckpool_SOURCES = ckpool.c ckpool.h gbt.c gbt.h
ckpool_LDADD = libckpool.la

77
src/gbt.c

@ -0,0 +1,77 @@
/*
* Copyright 2011-2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#include "config.h"
#include <string.h>
#include "ckpool.h"
#include "libckpool.h"
static const char *b58chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
bool validate_address(connsock_t *cs, const char *address)
{
json_t *val, *res_val, *valid_val;
char rpc_req[256];
bool ret = false;
int len, i, j;
if (unlikely(!address)) {
LOGWARNING("Null address passed to validate_address");
return ret;
}
len = strlen(address);
if (len < 27 || len > 34) {
LOGWARNING("Invalid address length %d passed to validate_address", len);
return ret;
}
for (i = 0; i < len; i++) {
char c = address[i];
bool found = false;
for (j = 0; j < 58; j++) {
if (c == b58chars[j]) {
found = true;
break;
}
}
if (!found) {
LOGWARNING("Invalid char %.1s passed to validate_address", &c);
return ret;
}
}
snprintf(rpc_req, 256, "{\"method\": \"validateaddress\", \"params\": [\"%s\"]}\n", address);
val = json_rpc_call(cs, rpc_req);
if (!val) {
LOGERR("Failed to get valid json response to validate_address");
return ret;
}
res_val = json_object_get(val, "result");
if (!res_val) {
LOGERR("Failed to get result json response to validate_address");
goto out;
}
valid_val = json_object_get(res_val, "isvalid");
if (!valid_val) {
LOGERR("Failed to get isvalid json response to validate_address");
goto out;
}
if (!json_is_true(valid_val))
LOGWARNING("Bitcoin address %s is NOT valid", address);
else {
LOGDEBUG("Bitcoin address %s IS valid", address);
ret = true;
}
out:
if (val)
json_decref(val);
return ret;
}

10
src/gbt.h

@ -0,0 +1,10 @@
/*
* Copyright 2011-2014 Con Kolivas
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
bool validate_address(connsock_t *cs, const char *address);

2
src/libckpool.c

@ -1119,7 +1119,7 @@ void target_from_diff(uchar *target, double diff)
if (unlikely(diff == 0.0)) {
/* This shouldn't happen but best we check to prevent a crash */
memset(target, 0, 32);
memset(target, 0xff, 32);
return;
}

Loading…
Cancel
Save