diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1133bfb7d..4b4b3510a 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -24,12 +24,6 @@ // need to validate incoming data and update only if it is valid and more recent // make sure to sanity check all vector lengths on receipt -// bugs: -// got txproof response 1562526470 size.2112 a9ea92a1bbc68ae850b4bedabcbe60132844e5791ba2678bcba520910f1ad0c6 ht.1432768 -// got ntzs response 1562526471 size.209 bbf7ac47c67b5f84ddeffa5621dae6a9c3e5e8fad59cfc7359be2aa2937bd135 prev.1432750, 8255451aa5a5f8ba8f06ea8f4f83879f346bfd782d72c16d034693d123aa4b68 next.1432760 -// NSPV_gettransaction retval would have been -22 - - #ifndef KOMODO_NSPV_H #define KOMODO_NSPV_H @@ -223,7 +217,8 @@ struct NSPV_inforesp { struct NSPV_ntz notarization; uint256 blockhash; - int32_t height,pad32; + int32_t height,hdrheight; + struct NSPV_equihdr H; }; int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp *ptr) @@ -232,7 +227,8 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += NSPV_rwntz(rwflag,&serialized[len],&ptr->notarization); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->blockhash),(uint8_t *)&ptr->blockhash); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); + len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index db86348a0..c2e4b4e52 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -32,7 +32,9 @@ int32_t NSPV_notarization_find(struct NSPV_ntzargs *args,int32_t height,int32_t int32_t ntzheight = 0; uint256 hashBlock; CTransaction tx; Notarisation nota; char *symbol; std::vector opret; symbol = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; memset(args,0,sizeof(*args)); - if ( (args->txidht= (dir < 0 ? ScanNotarisationsDB : ScanNotarisationsDB2)(height,symbol,1440,nota)) == 0 ) + if ( dir > 0 ) + height += 10; + if ( (args->txidht= ScanNotarisationsDB(height,symbol,1440,nota)) == 0 ) return(-1); args->txid = nota.first; if ( !GetTransaction(args->txid,tx,hashBlock,false) || tx.vout.size() < 2 ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 533e3f8b8..4b791880b 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -105,7 +105,27 @@ UniValue NSPV_ntz_json(struct NSPV_ntz *ptr) return(result); } -UniValue _NSPV_getinfo_json(struct NSPV_inforesp *ptr) +UniValue NSPV_header_json(struct NSPV_equihdr *hdr,int32_t height) +{ + UniValue item(UniValue::VOBJ); + item.push_back(Pair("height",(int64_t)height)); + item.push_back(Pair("blockhash",NSPV_hdrhash(hdr).GetHex())); + item.push_back(Pair("hashPrevBlock",hdr->hashPrevBlock.GetHex())); + item.push_back(Pair("hashMerkleRoot",hdr->hashMerkleRoot.GetHex())); + item.push_back(Pair("nTime",(int64_t)hdr->nTime)); + item.push_back(Pair("nBits",(int64_t)hdr->nBits)); + return(item); +} + +UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; iheight)); result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); + result.push_back(Pair("hdr",NSPV_header_json(&ptr->H))); return(result); } @@ -165,23 +186,6 @@ UniValue NSPV_ntzs_json(struct NSPV_ntzsresp *ptr) return(result); } -UniValue NSPV_headers_json(struct NSPV_equihdr *hdrs,int32_t numhdrs,int32_t height) -{ - UniValue array(UniValue::VARR); int32_t i; - for (i=0; i>1) != 0 ) { - //fprintf(stderr,"issue getinfo\n"); - if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + for (i=0; i>1); - } slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_UTXOS; msg[len++] = slen; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c7ce08054..9ab477e3e 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -383,8 +383,10 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages { if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) { + int32_t reqht = 0; len = 0; msg[len++] = NSPV_INFO; + len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); } } diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index e13276960..0aac30799 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -972,7 +972,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) return EncodeViewingKey(vk); } -UniValue NSPV_getinfo_json(); +UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); UniValue NSPV_addressutxos(char *coinaddr); @@ -987,9 +987,12 @@ extern std::string NSPV_address; UniValue nspv_getinfo(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() != 0 ) - throw runtime_error("nspv_getinfo\n"); - return(NSPV_getinfo_json()); + int32_t reqht = 0; + if ( fHelp || params.size() > 1 ) + throw runtime_error("nspv_getinfo [hdrheight]\n"); + if ( params.size() == 0 ) + reqht = atoi((char *)params[0].get_str().c_str()); + return(NSPV_getinfo_req(reqht)); } UniValue nspv_logout(const UniValue& params, bool fHelp)