diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 03997362c..f84bc358a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -351,21 +351,20 @@ void NSPV_spentinfo_purge(struct NSPV_spentinfo *ptr) // on fullnode: // NSPV_get... functions need to return the exact serialized length, which is the size of the structure minus size of pointers, plus size of allocated data +#include "notarisationdb.h" + uint256 NSPV_getnotarization_txid(int32_t *ntzheightp,int32_t height) { - uint256 ntztxid; - if ( ntzheightp == 0 ) // search consecutive blocks + uint256 txid; Notarisation nota; char *symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? "KMD" : ASSETCHAINS_SYMBOL; + memset(&txid,0,sizeof(txid)); + *ntzheightp = 0; + int32_t matchedHeight = ScanNotarisationsDB(height,symbol,1440,nota); + if ( matchedHeight != 0 ) { - *ntzheightp = height + 1; - // iterate + *ntzheightp = matchedHeight; + txid = nota.first; } - else - { - // check *ntzheightp - } - // find notarization for height, return its txid and set *ntzheightp - fprintf(stderr,"implement NSPV_getnotarization_txid\n"); - return(ntztxid); + return(txid); } int32_t NSPV_getinfo(struct NSPV_inforesp *ptr) diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 201743dbd..b148deccf 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -135,3 +135,30 @@ int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Not } return 0; } + +int ScanNotarisationsDB2(int height, std::string symbol, int scanLimitBlocks, Notarisation& out) +{ + int32_t i,maxheight,ht; + maxheight = chainActive.Height(); + if ( height < 0 || height > maxheight ) + return false; + for (i=0; i maxheight ) + break; + NotarisationsInBlock notarisations; + uint256 blockHash = *chainActive[ht]->phashBlock; + if ( !GetBlockNotarisations(blockHash,notarisations) ) + continue; + BOOST_FOREACH(Notarisation& nota,notarisations) + { + if ( strcmp(nota.second.symbol,symbol.data()) == 0 ) + { + out = nota; + return(ht); + } + } + } + return 0; +} diff --git a/src/notarisationdb.h b/src/notarisationdb.h index 38b7b3671..af5d4df28 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -24,6 +24,7 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); void WriteBackNotarisations(const NotarisationsInBlock notarisations, CDBBatch &batch); void EraseBackNotarisations(const NotarisationsInBlock notarisations, CDBBatch &batch); int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out); +int ScanNotarisationsDB2(int height, std::string symbol, int scanLimitBlocks, Notarisation& out); bool IsTXSCL(const char* symbol); #endif /* NOTARISATIONDB_H */