From 61b6f8c75d0e394f6939fe84e14763875d3d9fb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 27 May 2016 00:33:40 -0500 Subject: [PATCH] test --- basilisk/basilisk_bitcoin.c | 24 ++++++++++++++++++++---- iguana/iguana777.h | 2 +- iguana/iguana_accept.c | 2 -- iguana/iguana_blocks.c | 5 ++--- iguana/iguana_bundles.c | 1 - iguana/iguana_tx.c | 2 -- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 76d6a5440..ff9fc071a 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -92,13 +92,29 @@ char *bitcoin_blockhashstr(char *coinstr,char *serverport,char *userpass,int32_t return(blockhashstr); } -bits256 basilisk_blockhash(struct iguana_info *coin,int32_t height) +int32_t basilisk_blockheight(struct iguana_info *coin,bits256 hash2) { - char *blockhashstr; bits256 hash2; + char buf[128],str[65],*blocktxt; cJSON *blockjson; int32_t height=-1; + sprintf(buf,"\"%s\"",bits256_str(str,hash2)); + if ( (blocktxt= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getblock",buf)) != 0 ) + { + if ( (blockjson= cJSON_Parse(blocktxt)) != 0 ) + { + height = jint(blockjson,"height"); + free_json(blockjson); + } + free(blocktxt); + } + return(height); +} + +bits256 basilisk_blockhash(struct iguana_info *coin,bits256 prevhash2) +{ + char *blockhashstr; bits256 hash2; int32_t height; memset(hash2.bytes,0,sizeof(hash2)); - if ( coin->MAXPEERS == 1 ) + if ( (height= basilisk_blockheight(coin,prevhash2)) >= 0 ) { - if ( (blockhashstr= bitcoin_blockhashstr(coin->symbol,coin->chain->serverport,coin->chain->userpass,height)) != 0 ) + if ( (blockhashstr= bitcoin_blockhashstr(coin->symbol,coin->chain->serverport,coin->chain->userpass,height+1)) != 0 ) { hash2 = bits256_conv(blockhashstr); free(blockhashstr); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 9838a261c..535812a8b 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -1015,7 +1015,7 @@ void basilisk_functions(struct iguana_info *coin); char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params); char *bitcoin_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,int64_t satoshis,char *paymentscriptstr,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint32_t locktime); char *bitcoin_blockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height); -bits256 basilisk_blockhash(struct iguana_info *coin,int32_t height); +bits256 basilisk_blockhash(struct iguana_info *coin,bits256 prevhash2); extern int32_t HDRnet,netBLOCKS; diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index a2dd48e26..7dd67ce77 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -299,8 +299,6 @@ int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32 { iguana_blockunconv(&msgB,block,1); len += iguana_rwblock(coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr) + len],&msgB); - if ( coin->MAXPEERS == 1 ) - checkhash2 = basilisk_blockhash(coin,bp->bundleheight + i); flag++; if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 ) { diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index c8639d37c..e76d72821 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -190,6 +190,8 @@ int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct igu bits256 hash2; uint8_t serialized[sizeof(struct iguana_msgblock) + 4096]; *validp = 0; iguana_serialize_block(coin->chain,&hash2,serialized,block); + if ( coin->MAXPEERS == 1 ) + hash2 = basilisk_blockhash(coin,block->RO.prev_block); *validp = (memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0); block->valid = *validp; char str[65]; char str2[65]; @@ -492,9 +494,6 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl //char str[65]; printf("extend? %s.h%d: %.15f vs %.15f ht.%d vs %d\n",bits256_str(str,block->RO.hash2),height,block->PoW,coin->blocks.hwmchain.PoW,height,coin->blocks.hwmchain.height); if ( iguana_blockvalidate(coin,&valid,newblock,0) < 0 || valid == 0 ) return(0); - block->RO.hash2 = basilisk_blockhash(coin,height); - if ( hash2p != 0 ) - *hash2p = block->RO.hash2; block->height = height; block->valid = 1; if ( block->PoW >= hwmchain->PoW ) diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index f3116138e..66290d84c 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -898,7 +898,6 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int datasize = numhashes = numsaved = numrecv = numcached = minrequests = 0; for (bundlei=0; bundlein; bundlei++) { - bp->hashes[bundlei] = basilisk_blockhash(coin,bp->bundleheight + bundlei); if ( bits256_nonz(bp->hashes[bundlei]) != 0 ) { numhashes++; diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 938afbdba..bc532035a 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -231,8 +231,6 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int iguana_blockunconv(&msgB,block,0); msgB.txn_count = block->RO.txn_count; total = iguana_rwblock(coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB); - if ( coin->MAXPEERS == 1 ) - checkhash2 = basilisk_blockhash(coin,bp->bundleheight + bundlei); if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 ) { static int counter;