Con Kolivas
11 years ago
4 changed files with 89 additions and 2 deletions
@ -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; |
||||
} |
@ -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); |
Loading…
Reference in new issue