|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2014 Andrew Smith |
|
|
|
* Copyright 2014-2016 Andrew Smith |
|
|
|
* Copyright 2014 Con Kolivas |
|
|
|
* Copyright 2014 Con Kolivas |
|
|
|
* |
|
|
|
* |
|
|
|
* This program is free software; you can redistribute it and/or modify it |
|
|
|
* This program is free software; you can redistribute it and/or modify it |
|
|
@ -304,28 +304,20 @@ bool btc_valid_address(char *addr) |
|
|
|
return valid; |
|
|
|
return valid; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check for orphan or update confirm count
|
|
|
|
// Check orphan, returns true only if all OK and not an orphan
|
|
|
|
void btc_blockstatus(BLOCKS *blocks) |
|
|
|
bool btc_orphancheck(BLOCKS *blocks) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char hash[TXT_BIG+1]; |
|
|
|
char hash[TXT_BIG+1]; |
|
|
|
char *blockhash; |
|
|
|
char *blockhash; |
|
|
|
int32_t confirms; |
|
|
|
|
|
|
|
size_t len; |
|
|
|
size_t len; |
|
|
|
tv_t now; |
|
|
|
tv_t now; |
|
|
|
bool ok; |
|
|
|
bool ok; |
|
|
|
|
|
|
|
|
|
|
|
setnow(&now); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s() checking %d %s", |
|
|
|
LOGDEBUG("%s() checking %d %s", |
|
|
|
__func__, |
|
|
|
__func__, blocks->height, blocks->blockhash); |
|
|
|
blocks->height, blocks->blockhash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Caller must check this to avoid resending it every time
|
|
|
|
if (blocks->ignore) |
|
|
|
if (blocks->ignore) { |
|
|
|
return false; |
|
|
|
LOGERR("%s() ignored block %d passed", |
|
|
|
|
|
|
|
__func__, blocks->height); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
len = strlen(blocks->blockhash); |
|
|
|
len = strlen(blocks->blockhash); |
|
|
|
if (len != SHA256SIZHEX) { |
|
|
|
if (len != SHA256SIZHEX) { |
|
|
@ -336,7 +328,7 @@ void btc_blockstatus(BLOCKS *blocks) |
|
|
|
* This should never happen */ |
|
|
|
* This should never happen */ |
|
|
|
blocks->ignore = true; |
|
|
|
blocks->ignore = true; |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dbhash2btchash(blocks->blockhash, hash, sizeof(hash)); |
|
|
|
dbhash2btchash(blocks->blockhash, hash, sizeof(hash)); |
|
|
@ -344,7 +336,12 @@ void btc_blockstatus(BLOCKS *blocks) |
|
|
|
blockhash = btc_blockhash(blocks->height); |
|
|
|
blockhash = btc_blockhash(blocks->height); |
|
|
|
// Something's amiss - let it try again later
|
|
|
|
// Something's amiss - let it try again later
|
|
|
|
if (!blockhash) |
|
|
|
if (!blockhash) |
|
|
|
return; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(blockhash) != SHA256SIZHEX) { |
|
|
|
|
|
|
|
free(blockhash); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(blockhash, hash) != 0) { |
|
|
|
if (strcmp(blockhash, hash) != 0) { |
|
|
|
LOGERR("%s() flagging block %d as %s pool=%s btc=%s", |
|
|
|
LOGERR("%s() flagging block %d as %s pool=%s btc=%s", |
|
|
@ -352,6 +349,8 @@ void btc_blockstatus(BLOCKS *blocks) |
|
|
|
blocks_confirmed(BLOCKS_ORPHAN_STR), |
|
|
|
blocks_confirmed(BLOCKS_ORPHAN_STR), |
|
|
|
hash, blockhash); |
|
|
|
hash, blockhash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setnow(&now); |
|
|
|
|
|
|
|
|
|
|
|
ok = blocks_add(NULL, blocks->height, |
|
|
|
ok = blocks_add(NULL, blocks->height, |
|
|
|
blocks->blockhash, |
|
|
|
blocks->blockhash, |
|
|
|
BLOCKS_ORPHAN_STR, EMPTY, |
|
|
|
BLOCKS_ORPHAN_STR, EMPTY, |
|
|
@ -363,6 +362,55 @@ void btc_blockstatus(BLOCKS *blocks) |
|
|
|
if (!ok) |
|
|
|
if (!ok) |
|
|
|
blocks->ignore = true; |
|
|
|
blocks->ignore = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(blockhash); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(blockhash); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check to update confirm count
|
|
|
|
|
|
|
|
void btc_blockstatus(BLOCKS *blocks) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
char hash[TXT_BIG+1]; |
|
|
|
|
|
|
|
char *blockhash; |
|
|
|
|
|
|
|
int32_t confirms; |
|
|
|
|
|
|
|
size_t len; |
|
|
|
|
|
|
|
tv_t now; |
|
|
|
|
|
|
|
bool ok; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s() checking %d %s", |
|
|
|
|
|
|
|
__func__, blocks->height, blocks->blockhash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Caller must check this to avoid resending it every time
|
|
|
|
|
|
|
|
if (blocks->ignore) { |
|
|
|
|
|
|
|
LOGERR("%s() ignored block %d passed", |
|
|
|
|
|
|
|
__func__, blocks->height); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
len = strlen(blocks->blockhash); |
|
|
|
|
|
|
|
if (len != SHA256SIZHEX) { |
|
|
|
|
|
|
|
LOGERR("%s() invalid blockhash size %d (%d) for block %d", |
|
|
|
|
|
|
|
__func__, (int)len, SHA256SIZHEX, blocks->height); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* So we don't keep repeating the message
|
|
|
|
|
|
|
|
* This should never happen */ |
|
|
|
|
|
|
|
blocks->ignore = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbhash2btchash(blocks->blockhash, hash, sizeof(hash)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blockhash = btc_blockhash(blocks->height); |
|
|
|
|
|
|
|
// Something's amiss - let it try again later
|
|
|
|
|
|
|
|
if (!blockhash) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(blockhash) != SHA256SIZHEX) { |
|
|
|
|
|
|
|
free(blockhash); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -373,6 +421,8 @@ void btc_blockstatus(BLOCKS *blocks) |
|
|
|
blocks_confirmed(BLOCKS_42_STR), |
|
|
|
blocks_confirmed(BLOCKS_42_STR), |
|
|
|
confirms, BLOCKS_42_VALUE); |
|
|
|
confirms, BLOCKS_42_VALUE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setnow(&now); |
|
|
|
|
|
|
|
|
|
|
|
ok = blocks_add(NULL, blocks->height, |
|
|
|
ok = blocks_add(NULL, blocks->height, |
|
|
|
blocks->blockhash, |
|
|
|
blocks->blockhash, |
|
|
|
BLOCKS_42_STR, EMPTY, |
|
|
|
BLOCKS_42_STR, EMPTY, |
|
|
@ -384,4 +434,5 @@ void btc_blockstatus(BLOCKS *blocks) |
|
|
|
if (!ok) |
|
|
|
if (!ok) |
|
|
|
blocks->ignore = true; |
|
|
|
blocks->ignore = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
free(blockhash); |
|
|
|
} |
|
|
|
} |
|
|
|