From 875cf683eb86de40c872e5331788e168b3dbffb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 18 Nov 2016 11:41:49 -0300 Subject: [PATCH] test --- src/komodo.h | 1 + src/komodo_bitcoind.h | 37 +++++++++++++++++++++++++------------ src/main.cpp | 12 +++++++++++- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index bdeb33efa..ed05c1a46 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -35,6 +35,7 @@ int32_t gettxout_scriptPubKey(uint8_t *scriptPubkey,int32_t maxsize,uint256 txid,int32_t n); void komodo_event_rewind(struct komodo_state *sp,char *symbol,int32_t height); +void komodo_connectblock(CBlockIndex *pindex,CBlock& block); #include "komodo_structs.h" #include "komodo_globals.h" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index acea87175..544fca79c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -441,6 +441,23 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) else memset(pubkey33,0,33); } +int32_t komodo_blockload(CBlock& block,cBlockIndex *pindex) +{ + block.SetNull(); + // Open history file to read + CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); + if (filein.IsNull()) + return(-1); + // Read block + try { filein >> block; } + catch (const std::exception& e) + { + fprintf(stderr,"readblockfromdisk err B\n"); + return(-1); + } + return(0); +} + void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; @@ -448,18 +465,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - block.SetNull(); - // Open history file to read - CAutoFile filein(OpenBlockFile(pindex->GetBlockPos(),true),SER_DISK,CLIENT_VERSION); - if (filein.IsNull()) - return; - // Read block - try { filein >> block; } - catch (const std::exception& e) - { - fprintf(stderr,"readblockfromdisk err B\n"); - return; - } + komodo_blockload(block,pindex); komodo_block2pubkey33(pubkey33,block); } else @@ -469,6 +475,13 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +void komodo_connectpindex(CBlockIndex *pindex) +{ + CBlock block; + komodo_blockload(block,pindex); + komodo_connectblock(pindex,block); +} + int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int8_t komodo_minerid(int32_t height) diff --git a/src/main.cpp b/src/main.cpp index 50e47689f..b7c528a32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2324,7 +2324,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //FlushStateToDisk(); komodo_connectblock(pindex,*(CBlock *)&block); - + { + static int32_t didinit; + if ( didinit == 0 ) + { + if ( (pindex= chainActive[73673]) != 0 ) + { + komodo_connectpindex(pindex); + } + didiint = 73673 + } + } return true; }