From 6cb639c2b7ffa7e0e37638d9f4ebc126bc09e057 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 01:49:05 -1100 Subject: [PATCH 01/56] nspv_listtransactions initial --- src/komodo_nSPV.h | 59 ++++++++++++++++++++++++++++++++++- src/komodo_nSPV_defs.h | 19 ++++++++++++ src/komodo_nSPV_fullnode.h | 62 +++++++++++++++++++++++++++++++++++++ src/komodo_nSPV_superlite.h | 40 +++++++++++++++++++++++- src/net.h | 2 +- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcdump.cpp | 21 +++++++++++++ 8 files changed, 202 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 67bfd6bb0..22bf48244 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -17,7 +17,7 @@ // todo: // myprivkey, scrub all destination buffers -// oversized tx +// new p2p messages: getrawmempool, getaddresstxids // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs @@ -139,6 +139,63 @@ void NSPV_utxosresp_copy(struct NSPV_utxosresp *dest,struct NSPV_utxosresp *ptr) } } +int32_t NSPV_rwtxidresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidresp *ptr) +{ + int32_t len = 0; + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->satoshis),&ptr->satoshis); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); + return(len); +} + +int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsresp *ptr) +{ + int32_t i,len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->numtxids),&ptr->numtxids); + if ( ptr->numtxids != 0 ) + { + if ( ptr->txids == 0 ) + ptr->txids = (struct NSPV_txidresp *)calloc(sizeof(*ptr->txids),ptr->numtxids); // relies on uint16_t being "small" to prevent mem exhaustion + for (i=0; inumtxids; i++) + len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]); + } + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad8),&ptr->pad8); + if ( rwflag != 0 ) + { + memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); + len += sizeof(ptr->coinaddr); + } + else + { + memcpy(ptr->coinaddr,&serialized[len],sizeof(ptr->coinaddr)); + len += sizeof(ptr->coinaddr); + } + return(len); +} + +void NSPV_txidsresp_purge(struct NSPV_txidsresp *ptr) +{ + if ( ptr != 0 ) + { + if ( ptr->txids != 0 ) + free(ptr->txids); + memset(ptr,0,sizeof(*ptr)); + } +} + +void NSPV_txidsresp_copy(struct NSPV_txidsresp *dest,struct NSPV_txidsresp *ptr) +{ + *dest = *ptr; + if ( ptr->txids != 0 ) + { + dest->txids = (uint256 *)malloc(ptr->numtxids * sizeof(*ptr->txids)); + memcpy(dest->txids,ptr->txids,ptr->numtxids * sizeof(*ptr->txids)); + } +} + int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) { int32_t len = 0; diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 31c53fa22..a50d10d77 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -39,6 +39,10 @@ #define NSPV_SPENTINFORESP 0x0b #define NSPV_BROADCAST 0x0c #define NSPV_BROADCASTRESP 0x0d +#define NSPV_TXIDS 0x0e +#define NSPV_TXIDSRESP 0x0f +#define NSPV_MEMPOOL 0x10 +#define NSPV_MEMPOOLRESP 0x11 int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); @@ -73,6 +77,21 @@ struct NSPV_utxosresp uint16_t numutxos; uint8_t CCflag,pad8; }; +struct NSPV_txidresp +{ + uint256 txid; + int64_t satoshis; + int32_t vout,height; +}; + +struct NSPV_txidsresp +{ + struct NSPV_txidresp *txids; + char coinaddr[64]; + int32_t nodeheight; + uint16_t numtxids; uint8_t CCflag,pad8; +}; + struct NSPV_ntz { uint256 blockhash,txid,othertxid; diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9e44df3a7..d480fa821 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -185,6 +185,39 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC return(0); } +int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC) +{ + int32_t maxlen,txheight,n = 0,len = 0; + std::vector > addressIndex; + SetCCtxids(addressIndex,coinaddr,isCC); + maxlen = MAX_BLOCK_SIZE(tipheight) - 512; + maxlen /= sizeof(*ptr->txids); + strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); + ptr->CCflag = isCC; + if ( (ptr->numtxids= (int32_t)addressIndex.size()) >= 0 && ptr->numtxids < maxlen ) + { + ptr->nodeheight = chainActive.LastTip()->GetHeight(); + ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids,sizeof(*ptr->txids)); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + { + ptr->txids[n].txid = it->first.txhash; + ptr->txids[n].vout = (int32_t)it->first.index; + ptr->txids[n].satoshis = (int64_t)it->second; + ptr->txids[n].height = (int64_t)it->first.blockHeight; + n++; + } + if ( len < maxlen ) + { + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); + return(len); + } + } + if ( ptr->txids != 0 ) + free(ptr->txids); + memset(ptr,0,sizeof(*ptr)); + return(0); +} + uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint256 txid) { uint8_t *rawtx = 0; @@ -394,6 +427,35 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } } } + else if ( request[0] == NSPV_TXIDS ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_txidsresp T; char coinaddr[64]; + if ( len < 64 && (request[1] == len-2 || request[1] == len-3) ) + { + uint8_t isCC = 0; + memcpy(coinaddr,&request[2],request[1]); + coinaddr[request[1]] = 0; + if ( request[1] == len-3 ) + isCC = (request[len-1] != 0); + if ( isCC != 0 ) + fprintf(stderr,"%s isCC.%d\n",coinaddr,isCC); + memset(&T,0,sizeof(T)); + if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC)) > 0 ) + { + response.resize(1 + slen); + response[0] = NSPV_TXIDSRESP; + if ( NSPV_rwtxidsresp(1,&response[1],&T) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_txidsresp_purge(&T); + } + } + } + } else if ( request[0] == NSPV_NTZS ) { if ( timestamp > pfrom->prevtimes[ind] ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 259f9cbc3..b63d19064 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -31,6 +31,7 @@ char NSPV_wifstr[64],NSPV_pubkeystr[67],NSPV_lastpeer[128]; std::string NSPV_address; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; +struct NSPV_txidsresp NSPV_txidsresult; struct NSPV_spentinfo NSPV_spentresult; struct NSPV_ntzsresp NSPV_ntzsresult; struct NSPV_ntzsproofresp NSPV_ntzsproofresult; @@ -158,7 +159,12 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_UTXOSRESP: NSPV_utxosresp_purge(&NSPV_utxosresult); NSPV_rwutxosresp(0,&response[1],&NSPV_utxosresult); - fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); // update utxos list + fprintf(stderr,"got utxos response %u size.%d\n",timestamp,(int32_t)response.size()); + break; + case NSPV_TXIDSRESP: + NSPV_txidsresp_purge(&NSPV_txidsresult); + NSPV_rwtxidsresp(0,&response[1],&NSPV_txidsresult); + fprintf(stderr,"got txids response %u size.%d\n",timestamp,(int32_t)response.size()); break; case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); @@ -553,6 +559,38 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) return(result); } +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag) +{ + UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; + if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) + return(NSPV_txidsresp_json(&NSPV_txidsresult)); + NSPV_txidsresp_purge(&NSPV_txidsresult); + if ( bitcoin_base58decode(msg,coinaddr) != 25 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid address")); + return(result); + } + slen = (int32_t)strlen(coinaddr); + msg[len++] = NSPV_TXIDS; + msg[len++] = slen; + memcpy(&msg[len],coinaddr,slen), len += slen; + msg[len++] = (CCflag != 0); + for (iter=0; iter<3; iter++); + if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) + { + for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) + return(NSPV_txidsresp_json(&NSPV_txidsresult)); + } + } else sleep(1); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","no txid result")); + return(result); +} + UniValue NSPV_notarizations(int32_t reqheight) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N,*ptr; diff --git a/src/net.h b/src/net.h index 0b8dcd901..2fa4e31b1 100644 --- a/src/net.h +++ b/src/net.h @@ -276,7 +276,7 @@ public: int64_t nLastRecv; int64_t nTimeConnected; int64_t nTimeOffset; - uint32_t prevtimes[8]; + uint32_t prevtimes[16]; CAddress addr; std::string addrName; CService addrLocal; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1c8a65fe5..51c43cbe4 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -420,6 +420,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_getinfo", &nspv_getinfo, true }, { "nSPV", "nspv_login", &nspv_login, true }, { "nSPV", "nspv_listunspent", &nspv_listunspent, true }, + { "nSPV", "nspv_listtransactions",&nspv_listtransactions, true }, { "nSPV", "nspv_spentinfo", &nspv_spentinfo, true }, { "nSPV", "nspv_notarizations", &nspv_notarizations, true }, { "nSPV", "nspv_hdrsproof", &nspv_hdrsproof, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 0e8c9db11..0450ce016 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -467,6 +467,7 @@ extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp); extern UniValue nspv_getinfo(const UniValue& params, bool fHelp); extern UniValue nspv_login(const UniValue& params, bool fHelp); +extern UniValue nspv_listtransactions(const UniValue& params, bool fHelp); extern UniValue nspv_listunspent(const UniValue& params, bool fHelp); extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); extern UniValue nspv_notarizations(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 82e44190c..43cd53e4a 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,6 +975,7 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag); UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); @@ -1029,6 +1030,26 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) else throw runtime_error("nspv_listunspent address [isCC]\n"); } +UniValue nspv_listtransactions(const UniValue& params, bool fHelp) +{ + int32_t CCflag = 0; + if ( fHelp || params.size() > 2 ) + throw runtime_error("nspv_listtransactions address [isCC]\n"); + if ( params.size() == 0 ) + { + if ( NSPV_address.size() != 0 ) + return(NSPV_addresstxids((char *)NSPV_address.c_str(),0)); + else throw runtime_error("nspv_listtransactions address [isCC]\n"); + } + if ( params.size() >= 1 ) + { + if ( params.size() == 2 ) + CCflag = atoi((char *)params[1].get_str().c_str()); + return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag)); + } + else throw runtime_error("nspv_listtransactions address [isCC]\n"); +} + UniValue nspv_spentinfo(const UniValue& params, bool fHelp) { uint256 txid; int32_t vout; From a3b643151e19d64787ec45a801c0a2ff7c546f6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 01:57:56 -1100 Subject: [PATCH 02/56] txids_json --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 8 ++++---- src/komodo_nSPV_superlite.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 22bf48244..317e517ce 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -191,7 +191,7 @@ void NSPV_txidsresp_copy(struct NSPV_txidsresp *dest,struct NSPV_txidsresp *ptr) *dest = *ptr; if ( ptr->txids != 0 ) { - dest->txids = (uint256 *)malloc(ptr->numtxids * sizeof(*ptr->txids)); + dest->txids = (struct NSPV_txidresp *)malloc(ptr->numtxids * sizeof(*ptr->txids)); memcpy(dest->txids,ptr->txids,ptr->numtxids * sizeof(*ptr->txids)); } } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d480fa821..6d073acfa 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -188,15 +188,15 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC) { int32_t maxlen,txheight,n = 0,len = 0; - std::vector > addressIndex; + std::vector > txids; SetCCtxids(addressIndex,coinaddr,isCC); - maxlen = MAX_BLOCK_SIZE(tipheight) - 512; + ptr->nodeheight = chainActive.LastTip()->GetHeight(); + maxlen = MAX_BLOCK_SIZE(ptr->nodeheight) - 512; maxlen /= sizeof(*ptr->txids); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; - if ( (ptr->numtxids= (int32_t)addressIndex.size()) >= 0 && ptr->numtxids < maxlen ) + if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen ) { - ptr->nodeheight = chainActive.LastTip()->GetHeight(); ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids,sizeof(*ptr->txids)); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b63d19064..9c90fc2c1 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -401,6 +401,34 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) return(result); } +UniValue NSPV_txidresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) +{ + UniValue array(UniValue::VARR); int32_t i; + for (i=0; iutxos,ptr->numutxos))); + result.push_back(Pair("address",ptr->coinaddr)); + result.push_back(Pair("isCC",ptr->CCflag)); + result.push_back(Pair("height",(int64_t)ptr->nodeheight)); + result.push_back(Pair("numtxids",(int64_t)ptr->numutxos)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); + return(result); +} + UniValue NSPV_ntzsresp_json(struct NSPV_ntzsresp *ptr) { UniValue result(UniValue::VOBJ); From 6bf2a78f1d2d709fe3e285f1c90663424b434475 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 01:59:36 -1100 Subject: [PATCH 03/56] Syntax --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 9c90fc2c1..3d68a9a60 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -401,7 +401,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) return(result); } -UniValue NSPV_txidresp_json(struct NSPV_utxoresp *utxos,int32_t numutxos) +UniValue NSPV_txidresp_json(struct NSPV_txidresp *utxos,int32_t numutxos) { UniValue array(UniValue::VARR); int32_t i; for (i=0; iutxos,ptr->numutxos))); + result.push_back(Pair("txids",NSPV_txidresp_json(ptr->txids,ptr->numtxids))); result.push_back(Pair("address",ptr->coinaddr)); result.push_back(Pair("isCC",ptr->CCflag)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); From 7c5bc6a6c71f922c173e5e6f2cdcc632ed46d8cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 02:00:47 -1100 Subject: [PATCH 04/56] Syntax --- src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_superlite.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 6d073acfa..9a56546f4 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -189,7 +189,7 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC { int32_t maxlen,txheight,n = 0,len = 0; std::vector > txids; - SetCCtxids(addressIndex,coinaddr,isCC); + SetCCtxids(txids,coinaddr,isCC); ptr->nodeheight = chainActive.LastTip()->GetHeight(); maxlen = MAX_BLOCK_SIZE(ptr->nodeheight) - 512; maxlen /= sizeof(*ptr->txids); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 3d68a9a60..661b40e75 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -424,7 +424,7 @@ UniValue NSPV_txidsresp_json(struct NSPV_txidsresp *ptr) result.push_back(Pair("address",ptr->coinaddr)); result.push_back(Pair("isCC",ptr->CCflag)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); - result.push_back(Pair("numtxids",(int64_t)ptr->numutxos)); + result.push_back(Pair("numtxids",(int64_t)ptr->numtxids)); result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } From 184e6c6c0f0910e72cbaa055a02c060b8733d25f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 02:35:33 -1100 Subject: [PATCH 05/56] nSPV support for CCtxids --- src/cc/CCtx.cpp | 6 ++++++ src/komodo_nSPV_wallet.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5799f0b18..64fadd63f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -334,6 +334,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } void NSPV_CCunspents(std::vector > &unspentOutputs,char *coinaddr,bool ccflag); +void NSPV_CCtxids(std::vector > &txids,char *coinaddr,bool ccflag); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool ccflag) { @@ -362,6 +363,11 @@ void SetCCunspents(std::vector > &addressIndex,char *coinaddr,bool ccflag) { int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector > addresses; + if ( KOMODO_NSPV != 0 ) + { + NSPV_CCtxids(addressIndex,coinaddr,ccflag); + return; + } n = (int32_t)strlen(coinaddr); addrstr.resize(n+1); ptr = (char *)addrstr.data(); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index d7ff5e1a7..df9fa1e36 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -468,10 +468,40 @@ void NSPV_utxos2CCunspents(struct NSPV_utxosresp *ptr,std::vector > &txids) +{ + CAddressIndexKey key; int64_t value; int32_t i,type; uint160 hashBytes; std::string addrstr(ptr->coinaddr); + if ( ptr->txids != NULL && ptr->numtxids > 0 ) + { + CBitcoinAddress address(addrstr); + if ( address.GetIndexKey(hashBytes, type, ptr->CCflag) == 0 ) + { + fprintf(stderr,"couldnt get indexkey\n"); + return; + } + for (i = 0; i < ptr->numtxids; i ++) + { + key.type = type; + key.hashBytes = hashBytes; + key.txhash = ptr->txids[i].txid; + key.index = ptr->txids[i].vout; + key.blockHeight = ptr->txids[i].height; + value = ptr->txids[i].satoshis; + txids.push_back(std::make_pair(key, value)); + } + } +} + void NSPV_CCunspents(std::vector > &outputs,char *coinaddr,bool ccflag) { NSPV_addressutxos(coinaddr,ccflag); NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs); } +void NSPV_CCtxids(std::vector > &txids,char *coinaddr,bool ccflag) +{ + NSPV_addresstxids(coinaddr,ccflag); + NSPV_txids2CCtxids(&NSPV_txidsresult,txids); +} + #endif // KOMODO_NSPVWALLET_H From 3bd2a963f84013d0be0e1956a9c8daf20c30311d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 03:11:12 -1100 Subject: [PATCH 06/56] +print --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 5d6f2722b..7eef97d38 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2144,6 +2144,7 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'c'; if ( ASSETCHAINS_MARMARA != 0 ) extraptr[extralen++] = ASSETCHAINS_MARMARA; +fprintf(stderr,"extralen.%d before disable bits\n",extralen); if ( nonz > 0 ) { memcpy(&extraptr[extralen],disablebits,sizeof(disablebits)); From 264d494d83ebae5131d03deadf5a826b81f89d46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 03:17:13 -1100 Subject: [PATCH 07/56] Test fix coquimagic --- src/komodo_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7eef97d38..f248df36d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1908,13 +1908,15 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_CC != 0 ) { + uint8_t prevCCi = 0; ASSETCHAINS_CCLIB = GetArg("-ac_cclib",""); Split(GetArg("-ac_ccenable",""), sizeof(ccenables)/sizeof(*ccenables), ccenables, 0); for (i=nonz=0; i<0x100; i++) { - if ( ccenables[i] != 0 ) + if ( ccenables[i] != prevCCi && ccenables[i] != 0 ) { nonz++; + prevCCi = ccenables[i]; fprintf(stderr,"%d ",(uint8_t)(ccenables[i] & 0xff)); } } From ff034b0c1286ee3852175a89bf8b56f416fe6435 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 03:27:02 -1100 Subject: [PATCH 08/56] 0 ) { From 95fb3ae324d5f2863a551241797048abafa09d51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:07:32 -1100 Subject: [PATCH 09/56] Skip count --- src/komodo_nSPV_fullnode.h | 84 ++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9a56546f4..6540f75d0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -139,7 +139,7 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) } else return(-1); } -int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC) // check mempool +int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC,int32_t skipcount) // check mempool { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; @@ -155,28 +155,31 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos,sizeof(*ptr->utxos)); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - ptr->utxos[n].txid = it->first.txhash; - ptr->utxos[n].vout = (int32_t)it->first.index; - ptr->utxos[n].satoshis = it->second.satoshis; - ptr->utxos[n].height = it->second.blockHeight; - if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) + // if gettxout is != null to handle mempool { - ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[n].txid,ptr->utxos[n].vout,ptr->utxos[n].height,ptr->utxos[n].satoshis,tipheight); - interest += ptr->utxos[n].extradata; + if ( n >= skipcount ) + { + ptr->utxos[n].txid = it->first.txhash; + ptr->utxos[n].vout = (int32_t)it->first.index; + ptr->utxos[n].satoshis = it->second.satoshis; + ptr->utxos[n].height = it->second.blockHeight; + if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) + { + ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[n].txid,ptr->utxos[n].vout,ptr->utxos[n].height,ptr->utxos[n].satoshis,tipheight); + interest += ptr->utxos[n].extradata; + } + total += it->second.satoshis; + } + n++; } - total += it->second.satoshis; - n++; } if ( len < maxlen ) { len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); //fprintf(stderr,"getaddressutxos for %s -> n.%d:%d total %.8f interest %.8f len.%d\n",coinaddr,n,ptr->numutxos,dstr(total),dstr(interest),len); - if ( n == ptr->numutxos ) - { - ptr->total = total; - ptr->interest = interest; - return(len); - } + ptr->total = total; + ptr->interest = interest; + return(len); } } if ( ptr->utxos != 0 ) @@ -185,7 +188,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC return(0); } -int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC) +int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount) { int32_t maxlen,txheight,n = 0,len = 0; std::vector > txids; @@ -197,20 +200,21 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC ptr->CCflag = isCC; if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen ) { + // scan mempool add to end ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids,sizeof(*ptr->txids)); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - ptr->txids[n].txid = it->first.txhash; - ptr->txids[n].vout = (int32_t)it->first.index; - ptr->txids[n].satoshis = (int64_t)it->second; - ptr->txids[n].height = (int64_t)it->first.blockHeight; + if ( n >= skipcount ) + { + ptr->txids[n].txid = it->first.txhash; + ptr->txids[n].vout = (int32_t)it->first.index; + ptr->txids[n].satoshis = (int64_t)it->second; + ptr->txids[n].height = (int64_t)it->first.blockHeight; + } n++; } - if ( len < maxlen ) - { - len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); - return(len); - } + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); + return(len); } if ( ptr->txids != 0 ) free(ptr->txids); @@ -403,17 +407,22 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_utxosresp U; char coinaddr[64]; - if ( len < 64 && (request[1] == len-2 || request[1] == len-3) ) + if ( len < 64 && (request[1] == len-3 || request[1] == len-7) ) { - uint8_t isCC = 0; + int32_t skipcount = 0; uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; if ( request[1] == len-3 ) isCC = (request[len-1] != 0); + else + { + isCC = (request[len-5] != 0); + iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount); + } if ( isCC != 0 ) - fprintf(stderr,"%s isCC.%d\n",coinaddr,isCC); + fprintf(stderr,"%s isCC.%d skipcount.%d\n",coinaddr,isCC,skipcount); memset(&U,0,sizeof(U)); - if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC)) > 0 ) + if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC,skipcount)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; @@ -432,17 +441,22 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_txidsresp T; char coinaddr[64]; - if ( len < 64 && (request[1] == len-2 || request[1] == len-3) ) + if ( len < 64 && (request[1] == len-3 || request[1] == len-7) ) { - uint8_t isCC = 0; + int32_t skipcount = 0; uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; if ( request[1] == len-3 ) isCC = (request[len-1] != 0); - if ( isCC != 0 ) - fprintf(stderr,"%s isCC.%d\n",coinaddr,isCC); + else + { + isCC = (request[len-5] != 0); + iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount); + } + //if ( isCC != 0 ) + fprintf(stderr,"%s isCC.%d skipcount.%d\n",coinaddr,isCC,skipcount); memset(&T,0,sizeof(T)); - if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC)) > 0 ) + if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_TXIDSRESP; From ae446fb014f835978552fb01762a268faa32db4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:24:17 -1100 Subject: [PATCH 10/56] Skipcount --- src/komodo_nSPV_superlite.h | 4 +++- src/wallet/rpcdump.cpp | 36 ++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 661b40e75..23108b6f9 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -554,7 +554,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight) return(0); } -UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); @@ -572,6 +572,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); + len += iguana_rwnum(1,&msg[len],sizeof(skipflag),&skipflag); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { @@ -604,6 +605,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); + len += iguana_rwnum(1,&msg[len],sizeof(skipflag),&skipflag); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 43cd53e4a..849d4fb33 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,8 +975,8 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); -UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag); -UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag); +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount); +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); @@ -1012,42 +1012,46 @@ UniValue nspv_login(const UniValue& params, bool fHelp) UniValue nspv_listunspent(const UniValue& params, bool fHelp) { - int32_t CCflag = 0; - if ( fHelp || params.size() > 2 ) - throw runtime_error("nspv_listunspent address [isCC]\n"); + int32_t skipcount = 0,CCflag = 0; + if ( fHelp || params.size() > 3 ) + throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) return(NSPV_addressutxos((char *)NSPV_address.c_str(),0)); - else throw runtime_error("nspv_listunspent address [isCC]\n"); + else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); } if ( params.size() >= 1 ) { - if ( params.size() == 2 ) + if ( params.size() >= 2 ) CCflag = atoi((char *)params[1].get_str().c_str()); - return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag)); + if ( params.size() == 3 ) + skipcount = atoi((char *)params[2].get_str().c_str()); + return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag,skipcount)); } - else throw runtime_error("nspv_listunspent address [isCC]\n"); + else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); } UniValue nspv_listtransactions(const UniValue& params, bool fHelp) { - int32_t CCflag = 0; - if ( fHelp || params.size() > 2 ) - throw runtime_error("nspv_listtransactions address [isCC]\n"); + int32_t skipcount = 0,CCflag = 0; + if ( fHelp || params.size() > 3 ) + throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) return(NSPV_addresstxids((char *)NSPV_address.c_str(),0)); - else throw runtime_error("nspv_listtransactions address [isCC]\n"); + else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); } if ( params.size() >= 1 ) { - if ( params.size() == 2 ) + if ( params.size() >= 2 ) CCflag = atoi((char *)params[1].get_str().c_str()); - return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag)); + if ( params.size() == 3 ) + skipcount = atoi((char *)params[2].get_str().c_str()); + return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount)); } - else throw runtime_error("nspv_listtransactions address [isCC]\n"); + else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); } UniValue nspv_spentinfo(const UniValue& params, bool fHelp) From d8701e533045e143fbe7ae9d1347b2257e3e0c88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:25:47 -1100 Subject: [PATCH 11/56] Pass in skip count --- src/komodo_nSPV_wallet.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index df9fa1e36..102cce534 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -343,7 +343,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) - NSPV_addressutxos(srcaddr,0); + NSPV_addressutxos(srcaddr,0,0); if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); @@ -434,7 +434,7 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 ) { - NSPV_addressutxos(coinaddr,CCflag); + NSPV_addressutxos(coinaddr,CCflag,0); NSPV_utxosresp_purge(&ptr->U); NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult); } @@ -494,13 +494,13 @@ void NSPV_txids2CCtxids(struct NSPV_txidsresp *ptr,std::vector > &outputs,char *coinaddr,bool ccflag) { - NSPV_addressutxos(coinaddr,ccflag); + NSPV_addressutxos(coinaddr,ccflag,0); NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs); } void NSPV_CCtxids(std::vector > &txids,char *coinaddr,bool ccflag) { - NSPV_addresstxids(coinaddr,ccflag); + NSPV_addresstxids(coinaddr,ccflag,0); NSPV_txids2CCtxids(&NSPV_txidsresult,txids); } From b30cd972aa3b5920c03397584d8daebd74621140 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:26:58 -1100 Subject: [PATCH 12/56] Syntax --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 23108b6f9..b70cf4020 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -588,7 +588,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipflag) return(result); } -UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag) +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipflag) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) From fa4342635a53b440c66501720e4c720332649afd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:28:45 -1100 Subject: [PATCH 13/56] ,0 --- src/wallet/rpcdump.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 849d4fb33..00bf59975 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1018,7 +1018,7 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addressutxos((char *)NSPV_address.c_str(),0)); + return(NSPV_addressutxos((char *)NSPV_address.c_str(),0,0)); else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); } if ( params.size() >= 1 ) @@ -1040,7 +1040,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addresstxids((char *)NSPV_address.c_str(),0)); + return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0)); else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); } if ( params.size() >= 1 ) From d18da6dbbbcb3e310bc3fbedc519a4886dfbf66a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:31:35 -1100 Subject: [PATCH 14/56] Skip count --- src/komodo_nSPV_superlite.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b70cf4020..fb66e15e7 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -554,7 +554,7 @@ uint32_t NSPV_blocktime(int32_t hdrheight) return(0); } -UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipflag) +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); @@ -572,7 +572,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipflag) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); - len += iguana_rwnum(1,&msg[len],sizeof(skipflag),&skipflag); + len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { @@ -588,7 +588,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipflag) return(result); } -UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipflag) +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) @@ -605,7 +605,8 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipflag) msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); - len += iguana_rwnum(1,&msg[len],sizeof(skipflag),&skipflag); + len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); + fprintf(stderr,"skipcount.%d\n",skipcount); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { From 58064943d2e497944829670cc4bdab36eadeb34f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:36:47 -1100 Subject: [PATCH 15/56] +print --- src/komodo_nSPV_fullnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 6540f75d0..67099191a 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -441,7 +441,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req if ( timestamp > pfrom->prevtimes[ind] ) { struct NSPV_txidsresp T; char coinaddr[64]; - if ( len < 64 && (request[1] == len-3 || request[1] == len-7) ) + if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7) ) { int32_t skipcount = 0; uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); @@ -467,7 +467,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } NSPV_txidsresp_purge(&T); } - } + } else fprintf(stderr,"len.%d req1.%d\n",len,request[1]); } } else if ( request[0] == NSPV_NTZS ) From d8d30ad85f8038716e4f34394a6e24be6ac5a9cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:43:04 -1100 Subject: [PATCH 16/56] Test --- src/komodo_nSPV_superlite.h | 4 ++-- src/wallet/rpcdump.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index fb66e15e7..7adb86ced 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -558,7 +558,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); - if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag ) + if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); NSPV_utxosresp_purge(&NSPV_utxosresult); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) @@ -591,7 +591,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) { UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; - if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) + if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag && skipcount == NSPV_txidsresult.skipcount ) return(NSPV_txidsresp_json(&NSPV_txidsresult)); NSPV_txidsresp_purge(&NSPV_txidsresult); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 00bf59975..5fb646579 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1049,6 +1049,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) CCflag = atoi((char *)params[1].get_str().c_str()); if ( params.size() == 3 ) skipcount = atoi((char *)params[2].get_str().c_str()); + fprintf(stderr,"call txids cc.%d skip.%d\n",CCflag,skipcount); return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount)); } else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); From e238396c104d4e00927a1cf91bf846592885b90c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:45:57 -1100 Subject: [PATCH 17/56] skipcount --- src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_defs.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 317e517ce..e9d87091c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -105,7 +105,7 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad8),&ptr->pad8); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount); if ( rwflag != 0 ) { memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); @@ -162,7 +162,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad8),&ptr->pad8); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount); if ( rwflag != 0 ) { memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index a50d10d77..597c3bdd0 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -74,7 +74,7 @@ struct NSPV_utxosresp char coinaddr[64]; int64_t total,interest; int32_t nodeheight; - uint16_t numutxos; uint8_t CCflag,pad8; + uint16_t numutxos; uint8_t CCflag,skipcount; }; struct NSPV_txidresp @@ -89,7 +89,7 @@ struct NSPV_txidsresp struct NSPV_txidresp *txids; char coinaddr[64]; int32_t nodeheight; - uint16_t numtxids; uint8_t CCflag,pad8; + uint16_t numtxids; uint8_t CCflag,skipcount; }; struct NSPV_ntz From a35f98b35bd8b02c19b106fe2e6fee654fad0bbb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 04:58:52 -1100 Subject: [PATCH 18/56] Fullnode return proper skip counted data --- src/komodo_nSPV_fullnode.h | 42 +++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 67099191a..f572c2c1f 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -141,38 +141,45 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC,int32_t skipcount) // check mempool { - int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; + int64_t total = 0,interest=0; uint32_t locktime; int32_t ind=0,tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr,isCC); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; + if ( skipcount < 0 ) + skipcount = 0l if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); ptr->nodeheight = tipheight; - ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos,sizeof(*ptr->utxos)); + if ( skipcount >= ptr->numutxos ) + skipcount = ptr->numutxos-1; + ptr->skipcount = skipcount; + ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos-skipcount,sizeof(*ptr->utxos)); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { // if gettxout is != null to handle mempool { if ( n >= skipcount ) { - ptr->utxos[n].txid = it->first.txhash; - ptr->utxos[n].vout = (int32_t)it->first.index; - ptr->utxos[n].satoshis = it->second.satoshis; - ptr->utxos[n].height = it->second.blockHeight; + ptr->utxos[ind].txid = it->first.txhash; + ptr->utxos[ind].vout = (int32_t)it->first.index; + ptr->utxos[ind].satoshis = it->second.satoshis; + ptr->utxos[ind].height = it->second.blockHeight; if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) { - ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[n].txid,ptr->utxos[n].vout,ptr->utxos[n].height,ptr->utxos[n].satoshis,tipheight); - interest += ptr->utxos[n].extradata; + ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[ind].txid,ptr->utxos[ind].vout,ptr->utxos[ind].height,ptr->utxos[ind].satoshis,tipheight); + interest += ptr->utxos[ind].extradata; } + ind++; total += it->second.satoshis; } n++; } } + ptr->numutxos = ind; if ( len < maxlen ) { len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->utxos)*ptr->numutxos - sizeof(ptr->utxos)); @@ -190,7 +197,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount) { - int32_t maxlen,txheight,n = 0,len = 0; + int32_t maxlen,txheight,ind=0,n = 0,len = 0; std::vector > txids; SetCCtxids(txids,coinaddr,isCC); ptr->nodeheight = chainActive.LastTip()->GetHeight(); @@ -198,21 +205,28 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC maxlen /= sizeof(*ptr->txids); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; + if ( skipcount < 0 ) + skipcount = 0l if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen ) { // scan mempool add to end - ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids,sizeof(*ptr->txids)); + if ( skipcount >= ptr->numtxids ) + skipcount = ptr->numtxids-1; + ptr->skipcount = skipcount; + ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids-skipcount,sizeof(*ptr->txids)); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { if ( n >= skipcount ) { - ptr->txids[n].txid = it->first.txhash; - ptr->txids[n].vout = (int32_t)it->first.index; - ptr->txids[n].satoshis = (int64_t)it->second; - ptr->txids[n].height = (int64_t)it->first.blockHeight; + ptr->txids[ind].txid = it->first.txhash; + ptr->txids[ind].vout = (int32_t)it->first.index; + ptr->txids[ind].satoshis = (int64_t)it->second; + ptr->txids[ind].height = (int64_t)it->first.blockHeight; + ind++; } n++; } + ptr->numtxids = ind; len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); return(len); } From 7aefc2899f789b2abd2d0b47911481eddae8ba81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 05:00:33 -1100 Subject: [PATCH 19/56] -print --- src/komodo_nSPV_superlite.h | 6 +++++- src/wallet/rpcdump.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 7adb86ced..29d2015b3 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -560,6 +560,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) //fprintf(stderr,"utxos %s NSPV addr %s\n",coinaddr,NSPV_address.c_str()); if ( NSPV_utxosresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); + if ( skipcount < 0 ) + skipcount = 0; NSPV_utxosresp_purge(&NSPV_utxosresult); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { @@ -593,6 +595,8 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; if ( NSPV_txidsresult.nodeheight >= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag && skipcount == NSPV_txidsresult.skipcount ) return(NSPV_txidsresp_json(&NSPV_txidsresult)); + if ( skipcount < 0 ) + skipcount = 0; NSPV_txidsresp_purge(&NSPV_txidsresult); if ( bitcoin_base58decode(msg,coinaddr) != 25 ) { @@ -606,7 +610,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); - fprintf(stderr,"skipcount.%d\n",skipcount); + //fprintf(stderr,"skipcount.%d\n",skipcount); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 5fb646579..fbca72fda 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1049,7 +1049,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) CCflag = atoi((char *)params[1].get_str().c_str()); if ( params.size() == 3 ) skipcount = atoi((char *)params[2].get_str().c_str()); - fprintf(stderr,"call txids cc.%d skip.%d\n",CCflag,skipcount); + //fprintf(stderr,"call txids cc.%d skip.%d\n",CCflag,skipcount); return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount)); } else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); From ea16319e47d9fe9934c523479a5d76be14144be8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 05:05:34 -1100 Subject: [PATCH 20/56] ; --- src/komodo_nSPV_fullnode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index f572c2c1f..1300e87c6 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -149,7 +149,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; if ( skipcount < 0 ) - skipcount = 0l + skipcount = 0; if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); @@ -206,7 +206,7 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; if ( skipcount < 0 ) - skipcount = 0l + skipcount = 0; if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen ) { // scan mempool add to end From a099933fb846b64c4649e11afc6573051d136cb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 07:25:00 -1100 Subject: [PATCH 21/56] +print --- src/cc/faucet.cpp | 2 +- src/komodo_nSPV.h | 5 +++-- src/komodo_nSPV_superlite.h | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index fd3a8f60f..6306a4797 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -170,7 +170,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; - } else fprintf(stderr,"nValue too small or already spent in mempool\n"); + } else fprintf(stderr,"nValue %.8f too small or already spent in mempool\n",(double)nValue/COIN); } else fprintf(stderr,"couldnt get tx\n"); } return(totalinputs); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index e9d87091c..048655b9c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -17,11 +17,12 @@ // todo: // myprivkey, scrub all destination buffers -// new p2p messages: getrawmempool, getaddresstxids +// new p2p messages: getrawmempool and support myIsutxo_spentinmempool and mytxid_inmempool +// change skipcount to int32_t +// make req for utxo/txid more sane? // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs - // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) // bug: under load, fullnode was returning all 0 nServices diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 29d2015b3..bf8eab78d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -587,6 +587,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) } else sleep(1); result.push_back(Pair("result","error")); result.push_back(Pair("error","no utxos result")); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -623,6 +624,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) } else sleep(1); result.push_back(Pair("result","error")); result.push_back(Pair("error","no txid result")); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } From 6b0361381a2177a8e733c7b700eacbb71f5959a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 07:33:03 -1100 Subject: [PATCH 22/56] +print --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 6306a4797..5e5034574 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -157,7 +157,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub vout = (int32_t)it->first.index; if ( it->second.satoshis < threshold ) continue; - //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); + char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); // no need to prevent dup if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { @@ -170,7 +170,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) break; - } else fprintf(stderr,"nValue %.8f too small or already spent in mempool\n",(double)nValue/COIN); + } else fprintf(stderr,"vout.%d nValue %.8f too small or already spent in mempool\n",vout,(double)nValue/COIN); } else fprintf(stderr,"couldnt get tx\n"); } return(totalinputs); From fdd07613e34abe27b4d9fbd344bffdbd581e1e3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 07:35:24 -1100 Subject: [PATCH 23/56] +print --- src/cc/faucet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 5e5034574..8ee7977c3 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -35,6 +35,7 @@ int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v { if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) return(tx.vout[v].nValue); + else fprintf(stderr,"dest.%s vs (%s)\n",destaddr,cp->unspendableCCaddr); } return(0); } From 04732c1299009b88281d3e0ff69c03116fdcd4ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 07:39:02 -1100 Subject: [PATCH 24/56] Exception --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 8ee7977c3..b1dd579f1 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -35,7 +35,7 @@ int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v { if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) return(tx.vout[v].nValue); - else fprintf(stderr,"dest.%s vs (%s)\n",destaddr,cp->unspendableCCaddr); + //else fprintf(stderr,"dest.%s vs (%s)\n",destaddr,cp->unspendableCCaddr); } return(0); } @@ -162,7 +162,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub // no need to prevent dup if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { - if ( (nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ( KOMODO_NSPV != 0 || ((nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From 575b65ab106ea0d1edf20c359dc84a89ee979818 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 07:45:56 -1100 Subject: [PATCH 25/56] Revert err check --- src/script/script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index c821cd3bc..aeeca24e6 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -385,9 +385,9 @@ bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector> vParams; - if ( pCCSubScript != 0 ) + //if ( pCCSubScript != 0 ) return IsPayToCryptoCondition(pCCSubScript, vParams); - else return(false); + //else return(false); } bool CScript::IsPayToCryptoCondition() const From 37a9a0b8a8e2a88d01a6c1a40903605e9b8aa83b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 07:49:00 -1100 Subject: [PATCH 26/56] -print --- src/cc/CCtx.cpp | 17 ++++++++++------- src/cc/faucet.cpp | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 64fadd63f..3afe682c4 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -284,13 +284,16 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran } } uint256 sighash = SignatureHash(CCPubKey(cond), mtx, i, SIGHASH_ALL,utxovalues[i],consensusBranchId, &txdata); - int32_t z; - for (z=0; z<32; z++) - fprintf(stderr,"%02x",privkey[z]); - fprintf(stderr," privkey, "); - for (z=0; z<32; z++) - fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); - fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); + if ( 0 ) + { + int32_t z; + for (z=0; z<32; z++) + fprintf(stderr,"%02x",privkey[z]); + fprintf(stderr," privkey, "); + for (z=0; z<32; z++) + fprintf(stderr,"%02x",((uint8_t *)sighash.begin())[z]); + fprintf(stderr," sighash [%d] %.8f %x\n",i,(double)utxovalues[i]/COIN,consensusBranchId); + } if ( cc_signTreeSecp256k1Msg32(cond,privkey,sighash.begin()) != 0 ) { mtx.vin[i].scriptSig = CCSig(cond); diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index b1dd579f1..e2fc360a8 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,11 +158,11 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub vout = (int32_t)it->first.index; if ( it->second.satoshis < threshold ) continue; - char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); + //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); // no need to prevent dup if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { - if ( KOMODO_NSPV != 0 || ((nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) ) + if ( (nValue= IsFaucetvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From c5f6fd77a3a33fd89f5f2b9e29895421cc2bbbcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Jul 2019 08:16:45 -1100 Subject: [PATCH 27/56] Vin when -payment --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_superlite.h | 4 +++- src/script/script.cpp | 4 +--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 048655b9c..1f404c243 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -16,9 +16,9 @@ // todo: -// myprivkey, scrub all destination buffers // new p2p messages: getrawmempool and support myIsutxo_spentinmempool and mytxid_inmempool // change skipcount to int32_t +// myprivkey, scrub all destination buffers // make req for utxo/txid more sane? // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index bf8eab78d..de454f4b1 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -409,8 +409,10 @@ UniValue NSPV_txidresp_json(struct NSPV_txidresp *utxos,int32_t numutxos) UniValue item(UniValue::VOBJ); item.push_back(Pair("height",(int64_t)utxos[i].height)); item.push_back(Pair("txid",utxos[i].txid.GetHex())); - item.push_back(Pair("vout",(int64_t)utxos[i].vout)); item.push_back(Pair("value",(double)utxos[i].satoshis/COIN)); + if ( utxos[i].satoshis > 0 ) + item.push_back(Pair("vout",(int64_t)utxos[i].vout)); + else item.push_back(Pair("vin",(int64_t)utxos[i].vout)); array.push_back(item); } return(array); diff --git a/src/script/script.cpp b/src/script/script.cpp index aeeca24e6..475acdfd5 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -385,9 +385,7 @@ bool CScript::IsPayToCryptoCondition(CScript *pCCSubScript, std::vector> vParams; - //if ( pCCSubScript != 0 ) - return IsPayToCryptoCondition(pCCSubScript, vParams); - //else return(false); + return IsPayToCryptoCondition(pCCSubScript, vParams); } bool CScript::IsPayToCryptoCondition() const From c0eada0781ef236fa7869d7ddb163fb7c9c85324 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Jul 2019 22:46:02 -1100 Subject: [PATCH 28/56] nSPV hardfork change of utxos/txids structures --- src/komodo_gateway.h | 1 + src/komodo_nSPV.h | 4 ++-- src/komodo_nSPV_defs.h | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0093cd38a..b067a0b5e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -654,6 +654,7 @@ const char *banned_txids[] = //"6cc1d0495170bc0e11fd3925297623562e529ea1336b66ea61f8a1159041aed2", //"250875424cece9bcd98cb226b09da7671625633d6958589e3a462bad89ad87cc", // missed //"ea8659011de52f4dac42cda12326064b7b5013b8492f88e33159884ca299aa05", // missed + //"ce567928b5490a17244167af161b1d8dd6ff753fef222fe6855d95b2278a35b3", // missed }; int32_t komodo_checkvout(int32_t vout,int32_t k,int32_t indallvouts) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1f404c243..4edad6682 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -17,7 +17,7 @@ // todo: // new p2p messages: getrawmempool and support myIsutxo_spentinmempool and mytxid_inmempool -// change skipcount to int32_t + // myprivkey, scrub all destination buffers // make req for utxo/txid more sane? @@ -157,7 +157,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres if ( ptr->numtxids != 0 ) { if ( ptr->txids == 0 ) - ptr->txids = (struct NSPV_txidresp *)calloc(sizeof(*ptr->txids),ptr->numtxids); // relies on uint16_t being "small" to prevent mem exhaustion + ptr->txids = (struct NSPV_txidresp *)calloc(sizeof(*ptr->txids),ptr->numtxids); for (i=0; inumtxids; i++) len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]); } diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 597c3bdd0..46a0fc982 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -73,8 +73,8 @@ struct NSPV_utxosresp struct NSPV_utxoresp *utxos; char coinaddr[64]; int64_t total,interest; - int32_t nodeheight; - uint16_t numutxos; uint8_t CCflag,skipcount; + int32_t nodeheight,skipcount; + uint16_t numutxos,CCflag; }; struct NSPV_txidresp @@ -88,8 +88,8 @@ struct NSPV_txidsresp { struct NSPV_txidresp *txids; char coinaddr[64]; - int32_t nodeheight; - uint16_t numtxids; uint8_t CCflag,skipcount; + int32_t nodeheight,skipcount; + uint16_t numtxids,CCflag; }; struct NSPV_ntz From c4489e98ac4bab5b2ce6035cfa8da65aa50d5ecf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Jul 2019 23:34:25 -1100 Subject: [PATCH 29/56] Pad32 --- src/komodo_nSPV.h | 3 +++ src/komodo_nSPV_defs.h | 4 ++-- src/komodo_nSPV_fullnode.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 4edad6682..c17e593a2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -105,6 +105,7 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->interest),&ptr->interest); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount); if ( rwflag != 0 ) @@ -162,6 +163,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount); if ( rwflag != 0 ) @@ -174,6 +176,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres memcpy(ptr->coinaddr,&serialized[len],sizeof(ptr->coinaddr)); len += sizeof(ptr->coinaddr); } +fprintf(stderr,"rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 46a0fc982..40fbea8e4 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -73,7 +73,7 @@ struct NSPV_utxosresp struct NSPV_utxoresp *utxos; char coinaddr[64]; int64_t total,interest; - int32_t nodeheight,skipcount; + int32_t nodeheight,skipcount,pad32; uint16_t numutxos,CCflag; }; @@ -88,7 +88,7 @@ struct NSPV_txidsresp { struct NSPV_txidresp *txids; char coinaddr[64]; - int32_t nodeheight,skipcount; + int32_t nodeheight,skipcount,pad32; uint16_t numtxids,CCflag; }; diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 1300e87c6..d58bf64ca 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -472,6 +472,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&T,0,sizeof(T)); if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount)) > 0 ) { +fprintf(stderr,"slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_TXIDSRESP; if ( NSPV_rwtxidsresp(1,&response[1],&T) == slen ) From 161cc59072c5379d0032021876bc2703302b1878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Jul 2019 23:50:58 -1100 Subject: [PATCH 30/56] +print --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index de454f4b1..eae964123 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -164,7 +164,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_TXIDSRESP: NSPV_txidsresp_purge(&NSPV_txidsresult); NSPV_rwtxidsresp(0,&response[1],&NSPV_txidsresult); - fprintf(stderr,"got txids response %u size.%d\n",timestamp,(int32_t)response.size()); + fprintf(stderr,"got txids response %u size.%d %s CC.%d num.%d\n",timestamp,(int32_t)response.size(),NSPV_txidsresult.coinaddr,NSPV_txidsresult.CCflag,NSPV_txidsresult.numtxids); break; case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); @@ -583,7 +583,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag ) + if ( (NSPV_inforesult.height == 0 || NSPV_utxosresult.nodeheight >= NSPV_inforesult.height) && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); } } else sleep(1); @@ -620,7 +620,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) + if ( (NSPV_inforesult.height == 0 || NSPV_txidsresult.nodeheight >= NSPV_inforesult.height) && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag ) return(NSPV_txidsresp_json(&NSPV_txidsresult)); } } else sleep(1); From abcc70d9fe953eb14c22b9637eada2f04a70d694 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 00:11:12 -1100 Subject: [PATCH 31/56] -print --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index c17e593a2..b90c75dc8 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -176,7 +176,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres memcpy(ptr->coinaddr,&serialized[len],sizeof(ptr->coinaddr)); len += sizeof(ptr->coinaddr); } -fprintf(stderr,"rwlen.%d\n",len); +//fprintf(stderr,"rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index d58bf64ca..421b976b7 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -472,7 +472,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&T,0,sizeof(T)); if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount)) > 0 ) { -fprintf(stderr,"slen.%d\n",slen); +//fprintf(stderr,"slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_TXIDSRESP; if ( NSPV_rwtxidsresp(1,&response[1],&T) == slen ) From 28e10d71bf453a85b0929950a1d324d8ff28ff76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:04:19 -1100 Subject: [PATCH 32/56] First version of mempool request --- src/komodo_nSPV.h | 55 ++++++++++++++- src/komodo_nSPV_defs.h | 12 ++++ src/komodo_nSPV_fullnode.h | 133 +++++++++++++++++++++++++++++------- src/komodo_nSPV_superlite.h | 42 +++++++++++- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcdump.cpp | 21 ++++++ 7 files changed, 236 insertions(+), 29 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index b90c75dc8..541eeb8d2 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -18,13 +18,12 @@ // new p2p messages: getrawmempool and support myIsutxo_spentinmempool and mytxid_inmempool -// myprivkey, scrub all destination buffers - -// make req for utxo/txid more sane? // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs +// Myprivkey(uint8_t *privkey), scrub all destination privkey buffers // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) +// make req for utxo/txid more sane? (optional) // bug: under load, fullnode was returning all 0 nServices #ifndef KOMODO_NSPV_H @@ -200,6 +199,56 @@ void NSPV_txidsresp_copy(struct NSPV_txidsresp *dest,struct NSPV_txidsresp *ptr) } } +int32_t NSPV_rwmempoolresp(int32_t rwflag,uint8_t *serialized,struct NSPV_mempoolresp *ptr) +{ + int32_t i,len = 0; + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->numtxids),&ptr->numtxids); + if ( ptr->numtxids != 0 ) + { + if ( ptr->txids == 0 ) + ptr->txids = (uint256 *)calloc(sizeof(*ptr->txids),ptr->numtxids); + for (i=0; inumtxids; i++) + len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]); + } + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->funcid),&ptr->funcid); + if ( rwflag != 0 ) + { + memcpy(&serialized[len],ptr->coinaddr,sizeof(ptr->coinaddr)); + len += sizeof(ptr->coinaddr); + } + else + { + memcpy(ptr->coinaddr,&serialized[len],sizeof(ptr->coinaddr)); + len += sizeof(ptr->coinaddr); + } + fprintf(stderr,"NSPV_rwmempoolresp rwlen.%d\n",len); + return(len); +} + +void NSPV_mempoolresp_purge(struct NSPV_mempoolresp *ptr) +{ + if ( ptr != 0 ) + { + if ( ptr->txids != 0 ) + free(ptr->txids); + memset(ptr,0,sizeof(*ptr)); + } +} + +void NSPV_mempoolresp_copy(struct NSPV_mempoolresp *dest,struct NSPV_mempoolresp *ptr) +{ + *dest = *ptr; + if ( ptr->txids != 0 ) + { + dest->txids = (uint256 *)malloc(ptr->numtxids * sizeof(*ptr->txids)); + memcpy(dest->txids,ptr->txids,ptr->numtxids * sizeof(*ptr->txids)); + } +} + int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) { int32_t len = 0; diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 40fbea8e4..ddba19cb6 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -43,6 +43,10 @@ #define NSPV_TXIDSRESP 0x0f #define NSPV_MEMPOOL 0x10 #define NSPV_MEMPOOLRESP 0x11 +#define NSPV_MEMPOOL_ALL 0 +#define NSPV_MEMPOOL_ADDRESS 1 +#define NSPV_MEMPOOL_ISSPENT 2 +#define NSPV_MEMPOOL_INMEMPOOL 3 int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); @@ -92,6 +96,14 @@ struct NSPV_txidsresp uint16_t numtxids,CCflag; }; +struct NSPV_mempoolresp +{ + uint256 *txids; + char coinaddr[64]; + int32_t nodeheight,vout,pad32; + uint16_t numtxids; uint8_t CCflag,funcid; +}; + struct NSPV_ntz { uint256 blockhash,txid,othertxid; diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 421b976b7..09f8df4d2 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -157,26 +157,29 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC if ( skipcount >= ptr->numutxos ) skipcount = ptr->numutxos-1; ptr->skipcount = skipcount; - ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos-skipcount,sizeof(*ptr->utxos)); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + if ( ptr->numutxos-skipcount > 0 ) { - // if gettxout is != null to handle mempool + ptr->utxos = (struct NSPV_utxoresp *)calloc(ptr->numutxos-skipcount,sizeof(*ptr->utxos)); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( n >= skipcount ) + // if gettxout is != null to handle mempool { - ptr->utxos[ind].txid = it->first.txhash; - ptr->utxos[ind].vout = (int32_t)it->first.index; - ptr->utxos[ind].satoshis = it->second.satoshis; - ptr->utxos[ind].height = it->second.blockHeight; - if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) + if ( n >= skipcount ) { - ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[ind].txid,ptr->utxos[ind].vout,ptr->utxos[ind].height,ptr->utxos[ind].satoshis,tipheight); - interest += ptr->utxos[ind].extradata; + ptr->utxos[ind].txid = it->first.txhash; + ptr->utxos[ind].vout = (int32_t)it->first.index; + ptr->utxos[ind].satoshis = it->second.satoshis; + ptr->utxos[ind].height = it->second.blockHeight; + if ( ASSETCHAINS_SYMBOL[0] == 0 && it->second.satoshis >= 10*COIN ) + { + ptr->utxos[n].extradata = komodo_accrued_interest(&txheight,&locktime,ptr->utxos[ind].txid,ptr->utxos[ind].vout,ptr->utxos[ind].height,ptr->utxos[ind].satoshis,tipheight); + interest += ptr->utxos[ind].extradata; + } + ind++; + total += it->second.satoshis; } - ind++; - total += it->second.satoshis; + n++; } - n++; } } ptr->numutxos = ind; @@ -209,22 +212,24 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC skipcount = 0; if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen ) { - // scan mempool add to end if ( skipcount >= ptr->numtxids ) skipcount = ptr->numtxids-1; ptr->skipcount = skipcount; - ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids-skipcount,sizeof(*ptr->txids)); - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + if ( ptr->numtxids-skipcount > 0 ) { - if ( n >= skipcount ) + ptr->txids = (struct NSPV_txidresp *)calloc(ptr->numtxids-skipcount,sizeof(*ptr->txids)); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - ptr->txids[ind].txid = it->first.txhash; - ptr->txids[ind].vout = (int32_t)it->first.index; - ptr->txids[ind].satoshis = (int64_t)it->second; - ptr->txids[ind].height = (int64_t)it->first.blockHeight; - ind++; + if ( n >= skipcount ) + { + ptr->txids[ind].txid = it->first.txhash; + ptr->txids[ind].vout = (int32_t)it->first.index; + ptr->txids[ind].satoshis = (int64_t)it->second; + ptr->txids[ind].height = (int64_t)it->first.blockHeight; + ind++; + } + n++; } - n++; } ptr->numtxids = ind; len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); @@ -236,6 +241,52 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC return(0); } +/*struct NSPV_mempoolresp +{ + uint256 *txids; + char coinaddr[64]; + int32_t nodeheight; + uint16_t numtxids; uint8_t CCflag,funcid; +}; + +#define NSPV_MEMPOOL_ALL 0 +#define NSPV_MEMPOOL_ADDRESS 1 +#define NSPV_MEMPOOL_ISSPENT 2 +#define NSPV_MEMPOOL_INMEMPOOL 3 + */ + +int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid) +{ + +} + +int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) +{ + std::vector txids; int32_t i,len = 0; + ptr->nodeheight = chainActive.LastTip()->GetHeight(); + strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); + ptr->CCflag = isCC; + ptr->txid = txid; + ptr->vout = vout; + ptr->funcid = funcid; + NSPV_mempoolfuncs(txids,coinaddr,isCC,funcid,txid); + if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 ) + { + if ( ptr->numtxids > 0 ) + { + ptr->txids = (uint256 *)calloc(ptr->numtxids,sizeof(*ptr->txids)); + for (i=0; inumtxids; i++) + iguana_rwbignum(0,&txids[i],sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); + } + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); + return(len); + } + if ( ptr->txids != 0 ) + free(ptr->txids); + memset(ptr,0,sizeof(*ptr)); + return(0); +} + uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint256 txid) { uint8_t *rawtx = 0; @@ -383,7 +434,7 @@ int32_t NSPV_getspentinfo(struct NSPV_spentinfo *ptr,uint256 txid,int32_t vout) void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request { - int32_t len,slen,ind,reqheight; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); + int32_t len,slen,ind,reqheight,n; std::vector response; uint32_t timestamp = (uint32_t)time(NULL); if ( (len= request.size()) > 0 ) { if ( (ind= request[0]>>1) >= sizeof(pfrom->prevtimes)/sizeof(*pfrom->prevtimes) ) @@ -485,6 +536,38 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req } else fprintf(stderr,"len.%d req1.%d\n",len,request[1]); } } + else if ( request[0] == NSPV_MEMPOOL ) + { + if ( timestamp > pfrom->prevtimes[ind] ) + { + struct NSPV_mempoolresp M; char coinaddr[64]; + if ( len < sizeof(M)+64 ) + { + int32_t vout; uint256 txid; uint8_t funcid,isCC = 0; + n = 1; + len += iguana_rwnum(0,&request[len],sizeof(funcid),&funcid); + len += iguana_rwnum(0,&request[len],sizeof(vout),&vout); + len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); + slen = request[len++]; + memcpy(coinaddr,&request[len],slen), len += slen; + //if ( isCC != 0 ) + fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout); + memset(&M,0,sizeof(M)); + if ( (slen= NSPV_mempooltxids(&M,coinaddr,isCC,funcid,txid,vout)) > 0 ) + { + fprintf(stderr,"NSPV_mempooltxids slen.%d\n",slen); + response.resize(1 + slen); + response[0] = NSPV_MEMPOOLRESP; + if ( NSPV_rwmempoolresp(1,&response[1],&M) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_mempoolresp_purge(&T); + } + } else fprintf(stderr,"len.%d req1.%d\n",len,request[1]); + } + } else if ( request[0] == NSPV_NTZS ) { if ( timestamp > pfrom->prevtimes[ind] ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index eae964123..ba763f191 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -32,6 +32,7 @@ std::string NSPV_address; struct NSPV_inforesp NSPV_inforesult; struct NSPV_utxosresp NSPV_utxosresult; struct NSPV_txidsresp NSPV_txidsresult; +struct NSPV_mempoolresp NSPV_mempoolresult; struct NSPV_spentinfo NSPV_spentresult; struct NSPV_ntzsresp NSPV_ntzsresult; struct NSPV_ntzsproofresp NSPV_ntzsproofresult; @@ -166,7 +167,12 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r NSPV_rwtxidsresp(0,&response[1],&NSPV_txidsresult); fprintf(stderr,"got txids response %u size.%d %s CC.%d num.%d\n",timestamp,(int32_t)response.size(),NSPV_txidsresult.coinaddr,NSPV_txidsresult.CCflag,NSPV_txidsresult.numtxids); break; - case NSPV_NTZSRESP: + case NSPV_MEMPOOLRESP: + NSPV_mempoolresp_purge(&NSPV_mempoolresult); + NSPV_rwmempoolresp(0,&response[1],&NSPV_mempoolresult); + fprintf(stderr,"got mempool response %u size.%d %s CC.%d num.%d funcid.%d\n",timestamp,(int32_t)response.size(),NSPV_mempoolresult.coinaddr,NSPV_mempoolresult.CCflag,NSPV_mempoolresult.numtxids,NSPV_mempoolresult.funcid); + break; + case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); NSPV_rwntzsresp(0,&response[1],&NSPV_ntzsresult); if ( NSPV_ntzsresp_find(NSPV_ntzsresult.reqheight) == 0 ) @@ -630,6 +636,40 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) return(result); } +UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout) +{ + UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; + NSPV_mempoolresp_purge(&NSPV_mempoolresult); + if ( coinaddr[0] != 0 && bitcoin_base58decode(msg,coinaddr) != 25 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid address")); + return(result); + } + slen = (int32_t)strlen(coinaddr); + msg[len++] = NSPV_MEMPOOL; + msg[len++] = (CCflag != 0); + len += iguana_rwnum(1,&msg[len],sizeof(funcid),&funcid); + len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); + len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + msg[len++] = slen; + memcpy(&msg[len],coinaddr,slen), len += slen; + for (iter=0; iter<3; iter++); + if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) + { + for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_mempoolresult.coinaddr) == 0 && CCflag == NSPV_mempoolresult.CCflag && txid == NSPV_mempoolresult.txid && vout == NSPV_mempoolresult.vout && funcid == NSPV_mempoolresult.funcid ) + return(NSPV_mempoolresp_json(&NSPV_mempoolresult)); + } + } else sleep(1); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","no txid result")); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); + return(result); +} + UniValue NSPV_notarizations(int32_t reqheight) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N,*ptr; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 51c43cbe4..ebc1293e2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -420,6 +420,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_getinfo", &nspv_getinfo, true }, { "nSPV", "nspv_login", &nspv_login, true }, { "nSPV", "nspv_listunspent", &nspv_listunspent, true }, + { "nSPV", "nspv_mempool", &nspv_mempool, true }, { "nSPV", "nspv_listtransactions",&nspv_listtransactions, true }, { "nSPV", "nspv_spentinfo", &nspv_spentinfo, true }, { "nSPV", "nspv_notarizations", &nspv_notarizations, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 0450ce016..0865307c9 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -468,6 +468,7 @@ extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp); extern UniValue nspv_getinfo(const UniValue& params, bool fHelp); extern UniValue nspv_login(const UniValue& params, bool fHelp); extern UniValue nspv_listtransactions(const UniValue& params, bool fHelp); +extern UniValue nspv_mempool(const UniValue& params, bool fHelp); extern UniValue nspv_listunspent(const UniValue& params, bool fHelp); extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); extern UniValue nspv_notarizations(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index fbca72fda..2df09f1c6 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -977,6 +977,7 @@ UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount); UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount); +UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); @@ -1032,6 +1033,26 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); } +UniValue nspv_mempool(const UniValue& params, bool fHelp) +{ + UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout); + int32_t vout = 0,CCflag = 0; uint256 txid; uint8_t funcid; char *coinaddr; + memset(&txid,0,sizeof(txid)); + if ( fHelp || params.size() > 5 ) + throw runtime_error("nspv_mempool func(0 all, 1 address, 2 txid spent, 3 txid inmempool) address isCC [txid vout]]]\n"); + funcid = atoi((char *)params[0].get_str().c_str()); + coinaddr = (char *)params[1].get_str().c_str); + CCflag = atoi((char *)params[2].get_str().c_str()); + if ( params.size() > 3 ) + { + if ( params.size() != 5 ) + throw runtime_error("nspv_mempool func(0 all, 1 address, 2 txid spent, 3 txid inmempool) address isCC [txid vout]]]\n"); + txid = Parseuint256((char *)params[3].get_str().c_str()); + vout = atoi((char *)params[4].get_str().c_str()); + } + return(NSPV_mempooltxids(coinaddr,CCflag,funcid,txid,vout)); +} + UniValue nspv_listtransactions(const UniValue& params, bool fHelp) { int32_t skipcount = 0,CCflag = 0; From 720bf6251b64cf58ff1c5e2ac594f76a83c98878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:16:12 -1100 Subject: [PATCH 33/56] Syntax --- src/komodo_nSPV.h | 3 ++- src/komodo_nSPV_defs.h | 1 + src/komodo_nSPV_fullnode.h | 2 +- src/komodo_nSPV_superlite.h | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 541eeb8d2..dc561c6b0 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -208,8 +208,9 @@ int32_t NSPV_rwmempoolresp(int32_t rwflag,uint8_t *serialized,struct NSPV_mempoo if ( ptr->txids == 0 ) ptr->txids = (uint256 *)calloc(sizeof(*ptr->txids),ptr->numtxids); for (i=0; inumtxids; i++) - len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txids[i]),(uint8_t *)&ptr->txids[i]); } + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index ddba19cb6..1380f87d2 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -100,6 +100,7 @@ struct NSPV_mempoolresp { uint256 *txids; char coinaddr[64]; + uint256 txid; int32_t nodeheight,vout,pad32; uint16_t numtxids; uint8_t CCflag,funcid; }; diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 09f8df4d2..be3c1b9e9 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -563,7 +563,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } - NSPV_mempoolresp_purge(&T); + NSPV_mempoolresp_purge(&M); } } else fprintf(stderr,"len.%d req1.%d\n",len,request[1]); } diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index ba763f191..31c92955f 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -437,6 +437,24 @@ UniValue NSPV_txidsresp_json(struct NSPV_txidsresp *ptr) return(result); } +UniValue NSPV_mempoolresp_json(struct NSPV_mempoolresp *ptr) +{ + UniValue result(UniValue::VOBJ),array(UniValue::VARR); int32_t i; + result.push_back(Pair("result","success")); + for (i=0; inumtxids; i++) + array.push_back(Pair("txid",ptr->txids[i].GetHex().c_str())); + result.push_back(Pair("txids",array)); + result.push_back(Pair("address",ptr->coinaddr)); + result.push_back(Pair("isCC",ptr->CCflag)); + result.push_back(Pair("height",(int64_t)ptr->nodeheight)); + result.push_back(Pair("numtxids",(int64_t)ptr->numtxids)); + result.push_back(Pair("txid",ptr->txid.GetHex().c_str())); + result.push_back(Pair("vout",(int64_t)ptr->vout)); + result.push_back(Pair("funcid",(int64_t)ptr->funcid)); + result.push_back(Pair("lastpeer",NSPV_lastpeer)); + return(result); +} + UniValue NSPV_ntzsresp_json(struct NSPV_ntzsresp *ptr) { UniValue result(UniValue::VOBJ); From 75cad9d24bf8cad89254c869fd2cab81a9e6b224 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:21:17 -1100 Subject: [PATCH 34/56] Syntax --- src/komodo_nSPV_fullnode.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index be3c1b9e9..08e565a29 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -262,7 +262,7 @@ int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,u int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - std::vector txids; int32_t i,len = 0; + std::vector txids; uint256 tmp; int32_t i,len = 0; ptr->nodeheight = chainActive.LastTip()->GetHeight(); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; @@ -276,7 +276,10 @@ int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC, { ptr->txids = (uint256 *)calloc(ptr->numtxids,sizeof(*ptr->txids)); for (i=0; inumtxids; i++) - iguana_rwbignum(0,&txids[i],sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); + { + iguana_rwbignum(0,&tmp,sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); + txids.push_back(tmp); + } } len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); return(len); From a3bb5e076c90bbb7635b1133af4b10924ff1501d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:24:51 -1100 Subject: [PATCH 35/56] Syntax --- src/komodo_nSPV_fullnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 08e565a29..694425842 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -262,7 +262,7 @@ int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,u int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - std::vector txids; uint256 tmp; int32_t i,len = 0; + std::vector txids; uint256 tmp,tmpdest; int32_t i,len = 0; ptr->nodeheight = chainActive.LastTip()->GetHeight(); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; @@ -277,8 +277,8 @@ int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC, ptr->txids = (uint256 *)calloc(ptr->numtxids,sizeof(*ptr->txids)); for (i=0; inumtxids; i++) { - iguana_rwbignum(0,&tmp,sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); - txids.push_back(tmp); + tmp = txids[i]; + iguana_rwbignum(0,&tmp,sizeof(*ptr->txids),(uint8_t *)((void *)&ptr->txids[i])); } } len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); From a9a68b98d28454429e857f59691f8b7e6c29eff4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:27:14 -1100 Subject: [PATCH 36/56] Syntax --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 694425842..9ca5e2a62 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -278,7 +278,7 @@ int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC, for (i=0; inumtxids; i++) { tmp = txids[i]; - iguana_rwbignum(0,&tmp,sizeof(*ptr->txids),(uint8_t *)((void *)&ptr->txids[i])); + iguana_rwbignum(0,(uint8_t *)&tmp,sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); } } len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); From b7a4da251020beaa56ad9af86ad3b56af3433dac Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:32:57 -1100 Subject: [PATCH 37/56] () --- src/wallet/rpcdump.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 2df09f1c6..49d6a829b 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1041,7 +1041,7 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp) if ( fHelp || params.size() > 5 ) throw runtime_error("nspv_mempool func(0 all, 1 address, 2 txid spent, 3 txid inmempool) address isCC [txid vout]]]\n"); funcid = atoi((char *)params[0].get_str().c_str()); - coinaddr = (char *)params[1].get_str().c_str); + coinaddr = (char *)params[1].get_str().c_str(); CCflag = atoi((char *)params[2].get_str().c_str()); if ( params.size() > 3 ) { From 7d97b461bea1a21a2d3400ad39b88899c1ef9018 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 02:55:52 -1100 Subject: [PATCH 38/56] Prints --- src/komodo_nSPV_superlite.h | 3 ++- src/wallet/rpcdump.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 31c92955f..1b9c52a2a 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -170,7 +170,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_MEMPOOLRESP: NSPV_mempoolresp_purge(&NSPV_mempoolresult); NSPV_rwmempoolresp(0,&response[1],&NSPV_mempoolresult); - fprintf(stderr,"got mempool response %u size.%d %s CC.%d num.%d funcid.%d\n",timestamp,(int32_t)response.size(),NSPV_mempoolresult.coinaddr,NSPV_mempoolresult.CCflag,NSPV_mempoolresult.numtxids,NSPV_mempoolresult.funcid); + fprintf(stderr,"got mempool response %u size.%d %s CC.%d num.%d funcid.%d %s/v%d\n",timestamp,(int32_t)response.size(),NSPV_mempoolresult.coinaddr,NSPV_mempoolresult.CCflag,NSPV_mempoolresult.numtxids,NSPV_mempoolresult.funcid,NSPV_mempoolresult.txid.GetHex().c_str(),NSPV_mempoolresult.vout); break; case NSPV_NTZSRESP: NSPV_ntzsresp_purge(&NSPV_ntzsresult); @@ -672,6 +672,7 @@ UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; + fprintf(stderr,"(%s) func.%d CC.%d %s/v%d\n",coinaddr,funcid,CCflag,txid.GetHex().c_str(),vout); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 49d6a829b..de89f5d60 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1035,7 +1035,6 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) UniValue nspv_mempool(const UniValue& params, bool fHelp) { - UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout); int32_t vout = 0,CCflag = 0; uint256 txid; uint8_t funcid; char *coinaddr; memset(&txid,0,sizeof(txid)); if ( fHelp || params.size() > 5 ) From 64ad47d5c7a4cd61304271359ab753e142155505 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:01:39 -1100 Subject: [PATCH 39/56] Fix --- src/komodo_nSPV_superlite.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 1b9c52a2a..d93027ad4 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -656,7 +656,7 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout) { - UniValue result(UniValue::VOBJ); uint8_t msg[64]; int32_t i,iter,slen,len = 0; + UniValue result(UniValue::VOBJ); uint8_t msg[512]; int32_t i,iter,slen,len = 0; NSPV_mempoolresp_purge(&NSPV_mempoolresult); if ( coinaddr[0] != 0 && bitcoin_base58decode(msg,coinaddr) != 25 ) { From cd2ebf3a6ebee01cc784fdac1dd4487be63f269d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:05:10 -1100 Subject: [PATCH 40/56] Fix --- src/komodo_nSPV_fullnode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9ca5e2a62..399dd0530 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -548,6 +548,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { int32_t vout; uint256 txid; uint8_t funcid,isCC = 0; n = 1; + len += iguana_rwnum(0,&request[len],sizeof(CCflag),&isCC); len += iguana_rwnum(0,&request[len],sizeof(funcid),&funcid); len += iguana_rwnum(0,&request[len],sizeof(vout),&vout); len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); From 0a99703311e1fb89366e8779cd630a3bafa6ef6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:05:51 -1100 Subject: [PATCH 41/56] Null term --- src/komodo_nSPV_fullnode.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 399dd0530..38e5703dd 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -554,6 +554,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); slen = request[len++]; memcpy(coinaddr,&request[len],slen), len += slen; + coinaddr[slen] = ; //if ( isCC != 0 ) fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout); memset(&M,0,sizeof(M)); From b3a4493f0d38b48df975ce38105804e79b1bd278 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:07:25 -1100 Subject: [PATCH 42/56] Fix --- src/komodo_nSPV_fullnode.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 38e5703dd..de26c3419 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -553,22 +553,25 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req len += iguana_rwnum(0,&request[len],sizeof(vout),&vout); len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); slen = request[len++]; - memcpy(coinaddr,&request[len],slen), len += slen; - coinaddr[slen] = ; - //if ( isCC != 0 ) - fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout); - memset(&M,0,sizeof(M)); - if ( (slen= NSPV_mempooltxids(&M,coinaddr,isCC,funcid,txid,vout)) > 0 ) + if ( wlen < 63 ) { - fprintf(stderr,"NSPV_mempooltxids slen.%d\n",slen); - response.resize(1 + slen); - response[0] = NSPV_MEMPOOLRESP; - if ( NSPV_rwmempoolresp(1,&response[1],&M) == slen ) + memcpy(coinaddr,&request[len],slen), len += slen; + coinaddr[slen] = 0; + //if ( isCC != 0 ) + fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout); + memset(&M,0,sizeof(M)); + if ( (slen= NSPV_mempooltxids(&M,coinaddr,isCC,funcid,txid,vout)) > 0 ) { - pfrom->PushMessage("nSPV",response); - pfrom->prevtimes[ind] = timestamp; + fprintf(stderr,"NSPV_mempooltxids slen.%d\n",slen); + response.resize(1 + slen); + response[0] = NSPV_MEMPOOLRESP; + if ( NSPV_rwmempoolresp(1,&response[1],&M) == slen ) + { + pfrom->PushMessage("nSPV",response); + pfrom->prevtimes[ind] = timestamp; + } + NSPV_mempoolresp_purge(&M); } - NSPV_mempoolresp_purge(&M); } } else fprintf(stderr,"len.%d req1.%d\n",len,request[1]); } From de0a8ada1ca8c5ef3049f7d66e7338d76204f2e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:08:35 -1100 Subject: [PATCH 43/56] Seen --- src/komodo_nSPV.h | 2 +- src/komodo_nSPV_fullnode.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index dc561c6b0..1705a1955 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -226,7 +226,7 @@ int32_t NSPV_rwmempoolresp(int32_t rwflag,uint8_t *serialized,struct NSPV_mempoo memcpy(ptr->coinaddr,&serialized[len],sizeof(ptr->coinaddr)); len += sizeof(ptr->coinaddr); } - fprintf(stderr,"NSPV_rwmempoolresp rwlen.%d\n",len); + //fprintf(stderr,"NSPV_rwmempoolresp rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index de26c3419..6c653eb6d 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -553,7 +553,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req len += iguana_rwnum(0,&request[len],sizeof(vout),&vout); len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); slen = request[len++]; - if ( wlen < 63 ) + if ( slen < 63 ) { memcpy(coinaddr,&request[len],slen), len += slen; coinaddr[slen] = 0; @@ -562,7 +562,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&M,0,sizeof(M)); if ( (slen= NSPV_mempooltxids(&M,coinaddr,isCC,funcid,txid,vout)) > 0 ) { - fprintf(stderr,"NSPV_mempooltxids slen.%d\n",slen); + //fprintf(stderr,"NSPV_mempooltxids slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_MEMPOOLRESP; if ( NSPV_rwmempoolresp(1,&response[1],&M) == slen ) From 6312e435ea3783a35e4252ff626d51b12ee0d2fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:10:15 -1100 Subject: [PATCH 44/56] isCC --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 6c653eb6d..9f0ca98ac 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -548,7 +548,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { int32_t vout; uint256 txid; uint8_t funcid,isCC = 0; n = 1; - len += iguana_rwnum(0,&request[len],sizeof(CCflag),&isCC); + len += iguana_rwnum(0,&request[len],sizeof(isCC),&isCC); len += iguana_rwnum(0,&request[len],sizeof(funcid),&funcid); len += iguana_rwnum(0,&request[len],sizeof(vout),&vout); len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); From 91a88acc22cfe3b9e52b20541b2903652c995327 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:15:33 -1100 Subject: [PATCH 45/56] Len -> n --- src/komodo_nSPV_fullnode.h | 14 +++++++------- src/komodo_nSPV_superlite.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 9f0ca98ac..94e656a72 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -548,17 +548,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { int32_t vout; uint256 txid; uint8_t funcid,isCC = 0; n = 1; - len += iguana_rwnum(0,&request[len],sizeof(isCC),&isCC); - len += iguana_rwnum(0,&request[len],sizeof(funcid),&funcid); - len += iguana_rwnum(0,&request[len],sizeof(vout),&vout); - len += iguana_rwbignum(0,&request[len],sizeof(txid),(uint8_t *)&txid); - slen = request[len++]; + n += iguana_rwnum(0,&request[n],sizeof(isCC),&isCC); + n += iguana_rwnum(0,&request[n],sizeof(funcid),&funcid); + n += iguana_rwnum(0,&request[n],sizeof(vout),&vout); + n += iguana_rwbignum(0,&request[n],sizeof(txid),(uint8_t *)&txid); + slen = request[n++]; if ( slen < 63 ) { - memcpy(coinaddr,&request[len],slen), len += slen; + memcpy(coinaddr,&request[n],slen), n += slen; coinaddr[slen] = 0; //if ( isCC != 0 ) - fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout); + fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d len.%d slen.%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout,len,slen); memset(&M,0,sizeof(M)); if ( (slen= NSPV_mempooltxids(&M,coinaddr,isCC,funcid,txid,vout)) > 0 ) { diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d93027ad4..4be698367 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -664,15 +664,15 @@ UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 result.push_back(Pair("error","invalid address")); return(result); } - slen = (int32_t)strlen(coinaddr); msg[len++] = NSPV_MEMPOOL; msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(funcid),&funcid); len += iguana_rwnum(1,&msg[len],sizeof(vout),&vout); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); + slen = (int32_t)strlen(coinaddr); msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; - fprintf(stderr,"(%s) func.%d CC.%d %s/v%d\n",coinaddr,funcid,CCflag,txid.GetHex().c_str(),vout); + fprintf(stderr,"(%s) func.%d CC.%d %s/v%d len.%d\n",coinaddr,funcid,CCflag,txid.GetHex().c_str(),vout,len); for (iter=0; iter<3; iter++); if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { From 9ac1b1fea899c202b246120441c98d3a669967a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 03:39:09 -1100 Subject: [PATCH 46/56] Implement nspv_mempool functions #define NSPV_MEMPOOL_ALL 0 #define NSPV_MEMPOOL_ADDRESS 1 #define NSPV_MEMPOOL_ISSPENT 2 #define NSPV_MEMPOOL_INMEMPOOL 3 --- src/komodo_nSPV_fullnode.h | 94 +++++++++++++++++++++++++++----------- src/wallet/rpcdump.cpp | 4 +- 2 files changed, 69 insertions(+), 29 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 94e656a72..c30f542c0 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -241,23 +241,61 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC return(0); } -/*struct NSPV_mempoolresp +int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - uint256 *txids; - char coinaddr[64]; - int32_t nodeheight; - uint16_t numtxids; uint8_t CCflag,funcid; -}; - -#define NSPV_MEMPOOL_ALL 0 -#define NSPV_MEMPOOL_ADDRESS 1 -#define NSPV_MEMPOOL_ISSPENT 2 -#define NSPV_MEMPOOL_INMEMPOOL 3 - */ - -int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid) -{ - + int32_t num = 0,vini = 0; char destaddr[64]; + if ( mempool.size() == 0 ) + return(0); + LOCK(mempool.cs); + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); + if ( funcid == NSPV_MEMPOOL_ALL ) + { + txids.push_back(hash); + num++; + continue; + } + else if ( funcid == NSPV_MEMPOOL_INMEMPOOL ) + { + if ( hash == txid ) + { + txids.push_back(hash); + return(++num); + } + } + if ( funcid == NSPV_MEMPOOL_ISSPENT ) + { + BOOST_FOREACH(const CTxIn &txin,tx.vin) + { + //fprintf(stderr,"%s/v%d ",uint256_str(str,txin.prevout.hash),txin.prevout.n); + if ( txin.prevout.n == vout && txin.prevout.hash == txid ) + { + txids.push_back(hash); + return(++num); + } + vini++; + } + } + else if ( funcid == NSPV_MEMPOOL_ADDRESS ) + { + BOOST_FOREACH(const CTxOut &txout,tx.vout) + { + if ( txout.scriptPubKey.IsPayToCryptoCondition() == isCC ) + { + Getscriptaddress(destaddr,txout.scriptPubKey); + if ( strcmp(destaddr,coinaddr) == 0 ) + { + txids.push_back(hash); + num++; + } + } + } + } + //fprintf(stderr,"are vins for %s\n",uint256_str(str,hash)); + } + return(num); } int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) @@ -269,20 +307,22 @@ int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC, ptr->txid = txid; ptr->vout = vout; ptr->funcid = funcid; - NSPV_mempoolfuncs(txids,coinaddr,isCC,funcid,txid); - if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 ) + if ( NSPV_mempoolfuncs(txids,coinaddr,isCC,funcid,txid,vout) >= 0 ) { - if ( ptr->numtxids > 0 ) + if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 ) { - ptr->txids = (uint256 *)calloc(ptr->numtxids,sizeof(*ptr->txids)); - for (i=0; inumtxids; i++) + if ( ptr->numtxids > 0 ) { - tmp = txids[i]; - iguana_rwbignum(0,(uint8_t *)&tmp,sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); + ptr->txids = (uint256 *)calloc(ptr->numtxids,sizeof(*ptr->txids)); + for (i=0; inumtxids; i++) + { + tmp = txids[i]; + iguana_rwbignum(0,(uint8_t *)&tmp,sizeof(*ptr->txids),(uint8_t *)&ptr->txids[i]); + } } + len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); + return(len); } - len = (int32_t)(sizeof(*ptr) + sizeof(*ptr->txids)*ptr->numtxids - sizeof(ptr->txids)); - return(len); } if ( ptr->txids != 0 ) free(ptr->txids); @@ -557,8 +597,8 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { memcpy(coinaddr,&request[n],slen), n += slen; coinaddr[slen] = 0; - //if ( isCC != 0 ) - fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d len.%d slen.%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout,len,slen); + if ( isCC != 0 ) + fprintf(stderr,"(%s) isCC.%d funcid.%d %s/v%d len.%d slen.%d\n",coinaddr,isCC,funcid,txid.GetHex().c_str(),vout,len,slen); memset(&M,0,sizeof(M)); if ( (slen= NSPV_mempooltxids(&M,coinaddr,isCC,funcid,txid,vout)) > 0 ) { diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index de89f5d60..395612a3d 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1038,14 +1038,14 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp) int32_t vout = 0,CCflag = 0; uint256 txid; uint8_t funcid; char *coinaddr; memset(&txid,0,sizeof(txid)); if ( fHelp || params.size() > 5 ) - throw runtime_error("nspv_mempool func(0 all, 1 address, 2 txid spent, 3 txid inmempool) address isCC [txid vout]]]\n"); + throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n"); funcid = atoi((char *)params[0].get_str().c_str()); coinaddr = (char *)params[1].get_str().c_str(); CCflag = atoi((char *)params[2].get_str().c_str()); if ( params.size() > 3 ) { if ( params.size() != 5 ) - throw runtime_error("nspv_mempool func(0 all, 1 address, 2 txid spent, 3 txid inmempool) address isCC [txid vout]]]\n"); + throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n"); txid = Parseuint256((char *)params[3].get_str().c_str()); vout = atoi((char *)params[4].get_str().c_str()); } From ab4619c98bc7b96bf2241cc81023528360b95f2a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Jul 2019 04:06:20 -1100 Subject: [PATCH 47/56] Scrub privkeys from memory after done --- src/cc/CCtx.cpp | 2 + src/cc/channels.cpp | 1 + src/cc/dice.cpp | 1 + src/cc/dilithium.c | 104 ++++++++++++++++++++++++++++----------- src/cc/gamescc.cpp | 23 +++++---- src/cc/heir.cpp | 1 + src/cc/heir_validate.h | 2 + src/cc/marmara.cpp | 1 + src/cc/musig.cpp | 2 + src/cc/oracles.cpp | 1 + src/cc/pegs.cpp | 20 ++++++-- src/cc/rogue_rpc.cpp | 2 + src/komodo_nSPV.h | 2 +- src/wallet/rpcwallet.cpp | 1 + 14 files changed, 119 insertions(+), 44 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 3afe682c4..01cb02211 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -108,6 +108,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran else { fprintf(stderr,"vin.%d vout.%d is bigger than vintx.%d\n",i,mtx.vin[i].prevout.n,(int32_t)vintx.vout.size()); + memset(myprivkey,0,32); return(""); } } @@ -280,6 +281,7 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran if ( flag == 0 ) { fprintf(stderr,"CC signing error: vini.%d has unknown CC address.(%s)\n",i,destaddr); + memset(myprivkey,0,32); return(""); } } diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index f88546b6e..3a87b9fc2 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -453,6 +453,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C Myprivkey(myprivkey); if (tokenid!=zeroid) CCaddrTokens1of2set(cp,srcpub,destpub,myprivkey,coinaddr); else CCaddr1of2set(cp,srcpub,destpub,myprivkey,coinaddr); + memset(myprivkey,0,32); return totalinputs; } else return 0; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 20f7a0567..4d1453084 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -587,6 +587,7 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv,int32_t vout,int32_t fprintf(stderr,"%02x",ssecret2.bytes[i]); fprintf(stderr," ssecret2 dont match\n"); } + memset(tmp256.bytes,0,32); //char str[65],str2[65]; //fprintf(stderr,"generated house hentropy.%s <- entropy.%s\n",uint256_str(str,hentropy),uint256_str(str2,entropy)); return(hentropy); diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 4a3813e61..d0f7aa16d 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -3148,6 +3148,8 @@ UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *para if ( externalflag == 0 ) result.push_back(Pair("warning","test mode using privkey for -pubkey, only for testing. there is no point using quantum secure signing if you are using a privkey with a known secp256k1 pubkey!!")); result.push_back(Pair("result","success")); + memset(seed,0,32); + memset(sk,0,sizeof(sk)); return(result); } @@ -3194,9 +3196,23 @@ UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *par if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dilithiumpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_registeropret(handle,mypk,bigpub)); + memset(seed,0,32); + memset(sk,0,sizeof(sk)); return(musig_rawtxresult(result,rawtx)); - } else return(cclib_error(result,"couldnt find enough funds")); - } else return(cclib_error(result,"not enough parameters")); + } + else + { + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(cclib_error(result,"couldnt find enough funds")); + } + } + else + { + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(cclib_error(result,"not enough parameters")); + } } else return(cclib_error(result,"not dilithiumpk funds")); } @@ -3222,9 +3238,23 @@ UniValue dilithium_sign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) result.push_back(Pair("signature",dilithium_hexstr(str,sm,smlen))); calc_rmd160_sha256(rmd160,sm,smlen); result.push_back(Pair("sighash",dilithium_hexstr(str,rmd160,20))); + memset(seed,0,32); + memset(sk,0,sizeof(sk)); return(result); - } else return(cclib_error(result,"unexpected signed message len")); - } else return(cclib_error(result,"not enough parameters")); + } + else + { + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(cclib_error(result,"unexpected signed message len")); + } + } + else + { + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(cclib_error(result,"not enough parameters")); + } } UniValue dilithium_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) @@ -3289,7 +3319,7 @@ UniValue dilithium_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue dilithium_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,destpub33; CTransaction vintx; uint256 prevhash,hashBlock,destpubtxid; int32_t i,smlen,n,numvouts; char str[129],*scriptstr; CTxOut vout; std::string handle; uint8_t pk[CRYPTO_PUBLICKEYBYTES],pk2[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES],msg[32],seed[32]; std::vector sig; + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,destpub33; CTransaction vintx; uint256 prevhash,hashBlock,destpubtxid; int32_t i,smlen,n,numvouts; char str[129],*scriptstr,*retstr=""; CTxOut vout; std::string handle; uint8_t pk[CRYPTO_PUBLICKEYBYTES],pk2[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES],msg[32],seed[32]; std::vector sig; if ( txfee == 0 ) txfee = DILITHIUM_TXFEE; mypk = pubkey2pk(Mypubkey()); @@ -3317,23 +3347,31 @@ UniValue dilithium_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params if ( dilithium_sendopretdecode(destpubtxid,vintx.vout[numvouts-1].scriptPubKey) == 'x' ) { if ( dilithium_bigpubget(handle,destpub33,pk2,destpubtxid) < 0 ) - return(cclib_error(result,"couldnt get bigpub")); + retstr = (char *)"couldnt get bigpub"; else if ( memcmp(pk,pk2,sizeof(pk)) != 0 ) - return(cclib_error(result,"dilithium bigpub mismatch")); + retstr = (char *)"dilithium bigpub mismatch"; else if ( destpub33 != mypk ) - return(cclib_error(result,"destpub33 is not for this -pubkey")); + retstr = (char *)"destpub33 is not for this -pubkey"; else if ( _dilithium_sign(&sig[0],&smlen,msg,32,sk) < 0 ) - return(cclib_error(result,"dilithium signing error")); + retstr = (char *)"dilithium signing error"; else if ( smlen != 32+CRYPTO_BYTES ) - return(cclib_error(result,"siglen error")); - mtx.vin.push_back(CTxIn(prevhash,0)); - mtx.vout.push_back(vout); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_spendopret(destpubtxid,sig)); - return(dilithium_rawtxresult(result,rawtx)); - } else return(cclib_error(result,"couldnt decode send opret")); - } else return(cclib_error(result,"couldnt find vin0")); - } else return(cclib_error(result,"script or bad destpubtxid is not hex")); - } else return(cclib_error(result,"need to have exactly 2 params sendtxid, scriptPubKey")); + retstr = (char *)"siglen error"; + else + { + mtx.vin.push_back(CTxIn(prevhash,0)); + mtx.vout.push_back(vout); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_spendopret(destpubtxid,sig)); + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(dilithium_rawtxresult(result,rawtx)); + } + } else retstr = (char *)"couldnt decode send opret"; + } else retstr = (char *)"couldnt find vin0"; + } else retstr = (char *)"script or bad destpubtxid is not hex"; + } else retstr = (char *)"need to have exactly 2 params sendtxid, scriptPubKey"; + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(cclib_error(result,retstr)); } int64_t dilithium_inputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 destpubtxid,int64_t total,int32_t maxinputs,char *cmpaddr) @@ -3377,7 +3415,7 @@ int64_t dilithium_inputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu UniValue dilithium_Qsend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,destpub33; CTransaction tx,vintx; uint256 prevhash,mypubtxid,hashBlock,destpubtxid; int64_t amount,inputsum,outputsum,change; int32_t i,smlen,n,numvouts; char str[129],myCCaddr[64],*scriptstr; CTxOut vout; std::string handle; uint8_t pk[CRYPTO_PUBLICKEYBYTES],pk2[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES],msg[32],seed[32]; std::vector sig; std::vector voutpubtxids; + UniValue result(UniValue::VOBJ); std::string rawtx; CPubKey mypk,destpub33; CTransaction tx,vintx; uint256 prevhash,mypubtxid,hashBlock,destpubtxid; int64_t amount,inputsum,outputsum,change; int32_t i,smlen,n,numvouts; char str[129],myCCaddr[64],*scriptstr,*retstr=""; CTxOut vout; std::string handle; uint8_t pk[CRYPTO_PUBLICKEYBYTES],pk2[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES],msg[32],seed[32]; std::vector sig; std::vector voutpubtxids; if ( txfee == 0 ) txfee = DILITHIUM_TXFEE; mypk = pubkey2pk(Mypubkey()); @@ -3402,6 +3440,8 @@ UniValue dilithium_Qsend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params if ( dilithium_bigpubget(handle,destpub33,pk2,prevhash) < 0 ) { result.push_back(Pair("destpubtxid",prevhash.GetHex().c_str())); + memset(seed,0,32); + memset(sk,0,sizeof(sk)); return(cclib_error(result,"couldnt find bigpub at destpubtxid")); } else @@ -3437,19 +3477,27 @@ UniValue dilithium_Qsend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params //fprintf(stderr," msg\n"); sig.resize(32+CRYPTO_BYTES); if ( dilithium_bigpubget(handle,destpub33,pk2,mypubtxid) < 0 ) - return(cclib_error(result,"couldnt get bigpub")); + retstr = (char *)"couldnt get bigpub"; else if ( memcmp(pk,pk2,sizeof(pk)) != 0 ) - return(cclib_error(result,"dilithium bigpub mismatch")); + retstr = (char *)"dilithium bigpub mismatch"; else if ( destpub33 != mypk ) - return(cclib_error(result,"destpub33 is not for this -pubkey")); + retstr = (char *)"destpub33 is not for this -pubkey"; else if ( _dilithium_sign(&sig[0],&smlen,msg,32,sk) < 0 ) - return(cclib_error(result,"dilithium signing error")); + retstr = (char *)"dilithium signing error"; else if ( smlen != 32+CRYPTO_BYTES ) - return(cclib_error(result,"siglen error")); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_Qsendopret(mypubtxid,sig,voutpubtxids)); - return(dilithium_rawtxresult(result,rawtx)); - } else return(cclib_error(result,"Q couldnt find enough Q or x inputs")); - } else return(cclib_error(result,"need to have exactly 2 params sendtxid, scriptPubKey")); + retstr = (char *)"siglen error"; + else + { + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,dilithium_Qsendopret(mypubtxid,sig,voutpubtxids)); + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(dilithium_rawtxresult(result,rawtx)); + } + } else retstr = (char *)"Q couldnt find enough Q or x inputs"; + } else retstr = (char *)"need to have exactly 2 params sendtxid, scriptPubKey"; + memset(seed,0,32); + memset(sk,0,sizeof(sk)); + return(cclib_error(result,retstr)); } bool dilithium_Qvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 997013b0c..425ae473d 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -411,7 +411,7 @@ UniValue games_rng(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) int32_t games_eventsign(uint32_t ×tamp,std::vector &sig,std::vector payload,CPubKey pk) { static secp256k1_context *ctx; - size_t siglen = 74; secp256k1_pubkey pubkey; secp256k1_ecdsa_signature signature; int32_t len,verifyflag = 1; uint8_t privkey[32]; uint256 hash; uint32_t t; + size_t siglen = 74; secp256k1_pubkey pubkey; secp256k1_ecdsa_signature signature; int32_t len,verifyflag = 1,retval=-100; uint8_t privkey[32]; uint256 hash; uint32_t t; if ( ctx == 0 ) ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); if ( ctx != 0 ) @@ -439,10 +439,9 @@ int32_t games_eventsign(uint32_t ×tamp,std::vector &sig,std::vecto { if ( siglen != sig.size() ) sig.resize(siglen); - return(0); - } - else return(-3); - } else return(-2); + retval = 0; + } else retval = -3; + } else retval = -2; } else { @@ -451,12 +450,14 @@ int32_t games_eventsign(uint32_t ×tamp,std::vector &sig,std::vecto if ( secp256k1_ecdsa_signature_parse_der(ctx,&signature,&sig[0],sig.size()) > 0 ) { if ( secp256k1_ecdsa_verify(ctx,&signature,(uint8_t *)&hash,&pubkey) > 0 ) - return(0); - else return(-4); - } else return(-3); - } else return(-2); + retval = 0; + else retval = -4; + } else retval = -3; + } else retval = -2; } - } else return(-1); + } else retval = -1; + memset(privkey,0,sizeof(privkey)); + return(retval); } int32_t games_event(uint32_t timestamp,uint256 gametxid,int32_t eventid,std::vector payload) @@ -1339,6 +1340,7 @@ UniValue games_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param CCaddr1of2set(cp,gamespk,mypk,mypriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,games_keystrokesopret(gametxid,batontxid,mypk,keystrokes)); //fprintf(stderr,"KEYSTROKES.(%s)\n",rawtx.c_str()); + memset(mypriv,0,sizeof(mypriv)); return(games_rawtxresult(result,rawtx,1)); } else return(cclib_error(result,"keystrokes tx was too late")); } else return(cclib_error(result,"couldnt find batontxid")); @@ -1612,6 +1614,7 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,ch GetOpReturnData(opret, vopretNonfungible); rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), std::string(seedstr), gametxid.GetHex(), vopretNonfungible)); } + memset(mypriv,0,sizeof(mypriv)); return(games_rawtxresult(result,rawtx,1)); } result.push_back(Pair("result","success")); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index fc3a2f2fd..df3b0b7e8 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -967,6 +967,7 @@ template UniValue _HeirClaim(uint256 fundingtxid, int64_t txfee std::string rawhextx = FinalizeCCTx(0, cp, mtx, myPubkey, txfee, Helper::makeClaimOpRet(tokenid, voutTokenPubkeys, fundingtxid, (myPubkey == heirPubkey) ? 1 : hasHeirSpendingBegun)); // forward isHeirSpending to the next latest tx + memset(myprivkey,0,sizeof(myprivkey)); if (!rawhextx.empty()) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", rawhextx)); diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index c7424bc16..768390aa3 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -56,6 +56,7 @@ public: uint8_t mypriv[32]; Myprivkey(mypriv); CCaddr1of2set(cp, ownerPubkey, heirPubkey,mypriv, coinaddr); + memset(mypriv,0,sizeof(mypriv)); } }; @@ -101,6 +102,7 @@ public: uint8_t mypriv[32]; Myprivkey(mypriv); CCaddrTokens1of2set(cp, ownerPubkey, heirPubkey, mypriv, coinaddr); + memset(mypriv,0,sizeof(mypriv)); } }; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index e28566079..68625c038 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -488,6 +488,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) } } } + memset(mypriv,0,sizeof(mypriv)); } if ( inputsum >= amount+txfee ) { diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index bc113bc5c..e98937d71 100644 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -482,10 +482,12 @@ UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) MUSIG[musiglocation]->numcommits = 1; result.push_back(Pair("commitment",str)); result.push_back(Pair("result","success")); + memset(privkey,0,sizeof(privkey)); return(result); } else { + memset(privkey,0,sizeof(privkey)); memset(session,0,sizeof(session)); return(cclib_error(result,"couldnt initialize session")); } diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 5056ccade..0830ca6c1 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -193,6 +193,7 @@ CPubKey OracleBatonPk(char *batonaddr,struct CCcontract_info *cp) //fprintf(stderr,"batonpk.(%s) -> %s\n",(char *)HexStr(batonpk).c_str(),batonaddr); strcpy(cp->unspendableaddr2,batonaddr); } else fprintf(stderr,"error creating pubkey\n"); + memset(priv,0,sizeof(priv)); return(batonpk); } diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 002b591c4..949417be5 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -439,7 +439,8 @@ int64_t AddPegsTokenInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,u uint8_t mypriv[32]; Myprivkey(mypriv); CCaddrTokens1of2set(cp,pk1,pk2,mypriv,coinaddr); - } + memset(mypriv,0,sizeof(mypriv)); + } } return(totalinputs); } @@ -753,6 +754,7 @@ std::string PegsFund(uint64_t txfee,uint256 pegstxid, uint256 tokenid,int64_t am mtx.vin.push_back(CTxIn(accounttxid,1,CScript())); GetCCaddress1of2(cp,coinaddr,mypk,pegspk); CCaddr1of2set(cp,mypk,pegspk,mypriv,coinaddr); + memset(mypriv,0,sizeof(mypriv)); } else funds=AddPegsInputs(cp,mtx,pegspk,CPubKey(),txfee+2*CC_MARKER_VALUE,3); if (funds>=txfee+2*CC_MARKER_VALUE) @@ -839,7 +841,9 @@ std::string PegsGet(uint64_t txfee,uint256 pegstxid, uint256 tokenid, int64_t am Myprivkey(mypriv); GetCCaddress1of2(cp,coinaddr,mypk,pegspk); CCaddr1of2set(cp,mypk,pegspk,mypriv,coinaddr); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); + std::string retstr = FinalizeCCTx(0,cp,mtx,mypk,txfee,opret); + memset(mypriv,0,sizeof(mypriv)); + return(retstr); } std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid) @@ -929,28 +933,34 @@ std::string PegsRedeem(uint64_t txfee,uint256 pegstxid, uint256 tokenid) account.first=0; account.second=0; LOGSTREAM("pegscc",CCLOG_DEBUG2, stream << "new account [deposit=" << account.first << ",debt=" << account.second << "]" << std::endl); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsReedemOpRet(tokenid,pegstxid,mypk,amount,account))); + std::string retstr = FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePegsReedemOpRet(tokenid,pegstxid,mypk,amount,account)); + memset(mypriv,0,32); + return(retstr); } else { CCerror = strprintf("not enough balance in pegs global CC address"); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); - return(""); + memset(mypriv,0,32); + return(""); } } CCerror = strprintf("not enough tokens in pegs account (%lld) to redeem this amount of tokens %lld",tokenfunds,account.first); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + memset(mypriv,0,32); return(""); } else { CCerror = strprintf("not enough balance in pegs global CC address"); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); - return(""); + memset(mypriv,0,32); + return(""); } } CCerror = strprintf("to redeem from account and close it you must redeem full debt ammount %lld instead of %lld",account.second,funds); LOGSTREAM("pegscc",CCLOG_INFO, stream << CCerror << std::endl); + memset(mypriv,0,32); return(""); } diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index b0ed60ab2..a6168a206 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -963,6 +963,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param CCaddr1of2set(cp,roguepk,mypk,mypriv,destaddr); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,rogue_keystrokesopret(gametxid,batontxid,mypk,keystrokes)); //fprintf(stderr,"KEYSTROKES.(%s)\n",rawtx.c_str()); + memset(mypriv,0,32); return(rogue_rawtxresult(result,rawtx,1)); } else return(cclib_error(result,"keystrokes tx was too late")); } else return(cclib_error(result,"couldnt find batontxid")); @@ -1330,6 +1331,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param GetOpReturnData(opret, vopretNonfungible); rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), std::string(seedstr), gametxid.GetHex(), vopretNonfungible)); } + memset(mypriv,0,32); return(rogue_rawtxresult(result,rawtx,1)); } result.push_back(Pair("result","success")); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1705a1955..83b07bb4c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -16,7 +16,7 @@ // todo: -// new p2p messages: getrawmempool and support myIsutxo_spentinmempool and mytxid_inmempool +// use mempool functions in CC: myIsutxo_spentinmempool and mytxid_inmempool // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 426baa1f7..365399a7d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5399,6 +5399,7 @@ UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector %s\n",cp->unspendableCCaddr,destaddr); strcpy(cp->unspendableCCaddr,destaddr); + memset(priv,0,32); } result.push_back(Pair("result", "success")); sprintf(str,"%sCCAddress",name); From adc186390a0efc15c8979502d6080dd8fe08fc89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 17 Jul 2019 01:07:12 -1100 Subject: [PATCH 48/56] nSPV mempool used by CC --- src/cc/CCutils.cpp | 4 ++++ src/komodo_nSPV.h | 6 +----- src/komodo_nSPV_defs.h | 2 +- src/komodo_nSPV_fullnode.h | 11 ++++++++--- src/komodo_nSPV_superlite.h | 29 +++++++++++++++++++++++++++++ src/rpc/blockchain.cpp | 11 +++++++++-- 6 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 0c456450f..dfb8aeff3 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -578,9 +578,13 @@ uint256 CCOraclesReverseScan(char const *logcategory,uint256 &txid,int32_t heigh return(zeroid); } +int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t CCflag); + int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr) { int32_t i,n; char destaddr[64]; + if ( KOMODO_NSPV != 0 ) + return(NSPV_coinaddr_inmempool(logcategory,coinaddr,1)); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { const CTransaction &tx = e.GetTx(); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 83b07bb4c..5a16e91f1 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -16,14 +16,10 @@ // todo: -// use mempool functions in CC: myIsutxo_spentinmempool and mytxid_inmempool - // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs -// Myprivkey(uint8_t *privkey), scrub all destination privkey buffers // make sure to sanity check all vector lengths on receipt // make sure no files are updated (this is to allow nSPV=1 and later nSPV=0 without affecting database) -// make req for utxo/txid more sane? (optional) // bug: under load, fullnode was returning all 0 nServices #ifndef KOMODO_NSPV_H @@ -213,7 +209,7 @@ int32_t NSPV_rwmempoolresp(int32_t rwflag,uint8_t *serialized,struct NSPV_mempoo len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->txid),(uint8_t *)&ptr->txid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vindex),&ptr->vindex); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->funcid),&ptr->funcid); if ( rwflag != 0 ) diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 1380f87d2..f681a6f77 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -101,7 +101,7 @@ struct NSPV_mempoolresp uint256 *txids; char coinaddr[64]; uint256 txid; - int32_t nodeheight,vout,pad32; + int32_t nodeheight,vout,vindex; uint16_t numtxids; uint8_t CCflag,funcid; }; diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index c30f542c0..b73514da1 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -241,9 +241,10 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC return(0); } -int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) +int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - int32_t num = 0,vini = 0; char destaddr[64]; + int32_t num = 0,vini = 0,vouti = 0; char destaddr[64]; + *vindexp = -1; if ( mempool.size() == 0 ) return(0); LOCK(mempool.cs); @@ -264,6 +265,7 @@ int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,u txids.push_back(hash); return(++num); } + continue; } if ( funcid == NSPV_MEMPOOL_ISSPENT ) { @@ -273,6 +275,7 @@ int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,u if ( txin.prevout.n == vout && txin.prevout.hash == txid ) { txids.push_back(hash); + *vindexp = vini; return(++num); } vini++; @@ -288,9 +291,11 @@ int32_t NSPV_mempoolfuncs(std::vector &txids,char *coinaddr,bool isCC,u if ( strcmp(destaddr,coinaddr) == 0 ) { txids.push_back(hash); + *vindexp = vouti; num++; } } + vouti++; } } //fprintf(stderr,"are vins for %s\n",uint256_str(str,hash)); @@ -307,7 +312,7 @@ int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC, ptr->txid = txid; ptr->vout = vout; ptr->funcid = funcid; - if ( NSPV_mempoolfuncs(txids,coinaddr,isCC,funcid,txid,vout) >= 0 ) + if ( NSPV_mempoolfuncs(&ptr->vindex,txids,coinaddr,isCC,funcid,txid,vout) >= 0 ) { if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 ) { diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 4be698367..64c29bb5d 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -689,6 +689,35 @@ UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 return(result); } +int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t CCflag) +{ + NSPV_mempooltxids(coinaddr,CCflag,NSPV_MEMPOOL_ADDRESS,zeroid,-1); + if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids >= 1 && NSPV_mempoolresult.txid == txid && NSPV_mempoolresult.CCflag == CCflag ) + { + LogPrint(logcategory,"found (%s) vout in mempool\n",coinaddr); + return(true); + } else return(false); +} + +bool NSPV_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout) +{ + NSPV_mempooltxids("",0,NSPV_MEMPOOL_ISSPENT,txid,vout); + if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids == 1 && NSPV_mempoolresult.txid == txid ) + { + spenttxid = NSPV_mempoolresult.txids[0]; + spentvini = NSPV_mempoolresult.vindex; + return(true); + } else return(false); +} + +bool NSPV_inmempool(uint256 txid) +{ + NSPV_mempooltxids("",0,NSPV_MEMPOOL_INMEMPOOL,txid,0); + if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids == 1 && NSPV_mempoolresult.txids[0] == txid ) + return(true); + else return(false); +} + UniValue NSPV_notarizations(int32_t reqheight) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N,*ptr; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 9c55c807b..deb198aa6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -390,11 +390,14 @@ UniValue getdifficulty(const UniValue& params, bool fHelp) return GetNetworkDifficulty(); } +bool NSPV_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout); +bool NSPV_inmempool(uint256 txid); + bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout) { - //char *uint256_str(char *str,uint256); char str[65]; - //LOCK(mempool.cs); int32_t vini = 0; + if ( KOMODO_NSPV != 0 ) + return(NSPV_spentinmempool(spenttxid,spentvini,txid,vout)); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { const CTransaction &tx = e.GetTx(); @@ -417,6 +420,10 @@ bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid, bool mytxid_inmempool(uint256 txid) { + if ( KOMODO_NSPV != 0 ) + { + + } BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { const CTransaction &tx = e.GetTx(); From a24a1553e12f0a7bd712013a5835e7e3e41919cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 17 Jul 2019 01:28:49 -1100 Subject: [PATCH 49/56] Syntax --- src/komodo_nSPV_superlite.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 64c29bb5d..c6e1a0264 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -692,7 +692,7 @@ UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t CCflag) { NSPV_mempooltxids(coinaddr,CCflag,NSPV_MEMPOOL_ADDRESS,zeroid,-1); - if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids >= 1 && NSPV_mempoolresult.txid == txid && NSPV_mempoolresult.CCflag == CCflag ) + if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids >= 1 && strcmp(NSPV_mempoolresult.coinaddr,coinaddr) == 0 && NSPV_mempoolresult.CCflag == CCflag ) { LogPrint(logcategory,"found (%s) vout in mempool\n",coinaddr); return(true); @@ -701,7 +701,7 @@ int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t C bool NSPV_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout) { - NSPV_mempooltxids("",0,NSPV_MEMPOOL_ISSPENT,txid,vout); + NSPV_mempooltxids((char *)"",0,NSPV_MEMPOOL_ISSPENT,txid,vout); if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids == 1 && NSPV_mempoolresult.txid == txid ) { spenttxid = NSPV_mempoolresult.txids[0]; @@ -712,7 +712,7 @@ bool NSPV_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int3 bool NSPV_inmempool(uint256 txid) { - NSPV_mempooltxids("",0,NSPV_MEMPOOL_INMEMPOOL,txid,0); + NSPV_mempooltxids((char *)"",0,NSPV_MEMPOOL_INMEMPOOL,txid,0); if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids == 1 && NSPV_mempoolresult.txids[0] == txid ) return(true); else return(false); From 730ad7e6e84e4f8e566c7bf97439e559fa1f499d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 02:43:13 -1100 Subject: [PATCH 50/56] NSPV_MEMPOOL_CCEVALCODE Searches mempool for CC evalcode and fancied --- src/komodo_nSPV.h | 1 + src/komodo_nSPV_defs.h | 1 + src/komodo_nSPV_fullnode.h | 26 ++++++++++++++++++++++++-- src/komodo_nSPV_superlite.h | 7 +++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 5a16e91f1..27f03a5be 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -15,6 +15,7 @@ ******************************************************************************/ // todo: +// spentinfo via CC // headers "sync" make sure it connects to prior blocks to notarization. use getinfo hdrht to get missing hdrs diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index f681a6f77..4cf4d93eb 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -47,6 +47,7 @@ #define NSPV_MEMPOOL_ADDRESS 1 #define NSPV_MEMPOOL_ISSPENT 2 #define NSPV_MEMPOOL_INMEMPOOL 3 +#define NSPV_MEMPOOL_CCEVALCODE 4 int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,int64_t extradata,uint32_t tiptime,int64_t &rewardsum); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index b73514da1..e737b333f 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -243,10 +243,16 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - int32_t num = 0,vini = 0,vouti = 0; char destaddr[64]; + int32_t num = 0,vini = 0,vouti = 0; uint8_t evalcode,funcid=0; std::vector vopret; char destaddr[64]; *vindexp = -1; if ( mempool.size() == 0 ) return(0); + if ( funcid == NSPV_MEMPOOL_CCEVALCODE ) + { + isCC = true; + evalcode = vout & 0xff; + funcid = (vout >> 8) & 0xff; + } LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { @@ -267,6 +273,22 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coi } continue; } + else if ( funcid == NSPV_MEMPOOL_CCEVALCODE ) + { + if ( tx.vout.size() > 1 ) + { + scriptPubKey = tx.vout[tx.vout.size()-1].scriptPubKey; + if ( GetOpReturnData(scriptPubKey,vopret) != 0 ) + { + if ( vpopret[0] == evalcode && vpopret[1] == funcid ) + { + txids.push_back(hash); + num++; + } + } + } + continue; + } if ( funcid == NSPV_MEMPOOL_ISSPENT ) { BOOST_FOREACH(const CTxIn &txin,tx.vin) @@ -303,7 +325,7 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coi return(num); } -int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) +int32_t NSPV_mempooltxids(struct NSPV_mempoolresp *ptr,char *coinaddr,uint8_t isCC,uint8_t funcid,uint256 txid,int32_t vout) { std::vector txids; uint256 tmp,tmpdest; int32_t i,len = 0; ptr->nodeheight = chainActive.LastTip()->GetHeight(); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index c6e1a0264..8de8d96a4 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -718,6 +718,13 @@ bool NSPV_inmempool(uint256 txid) else return(false); } +bool NSPV_evalcode_inmempool(uint8_t evalcode,uint8_t funcid) +{ + int32_t vout; + vout = ((uint32_t)funcid << 8) | evalcode; + NSPV_mempooltxids((char *)"",1,NSPV_MEMPOOL_CCEVALCODE,zeroid,vout); +} + UniValue NSPV_notarizations(int32_t reqheight) { uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_ntzsresp N,*ptr; From f3a16b7765b11e022cc58e4d7b5d0d4874a1d1d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 02:45:00 -1100 Subject: [PATCH 51/56] Fix --- src/komodo_nSPV_superlite.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index 8de8d96a4..f8dae10bf 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -723,6 +723,9 @@ bool NSPV_evalcode_inmempool(uint8_t evalcode,uint8_t funcid) int32_t vout; vout = ((uint32_t)funcid << 8) | evalcode; NSPV_mempooltxids((char *)"",1,NSPV_MEMPOOL_CCEVALCODE,zeroid,vout); + if ( NSPV_mempoolresult.txids != 0 && NSPV_mempoolresult.numtxids >= 1 && NSPV_mempoolresult.vout == vout ) + return(true); + else return(false); } UniValue NSPV_notarizations(int32_t reqheight) From a2a6732a18530f94b1bce3a05143436cfed05ac5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 02:50:14 -1100 Subject: [PATCH 52/56] Sytax --- src/komodo_nSPV_fullnode.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index e737b333f..bfc256e2a 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -243,15 +243,15 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - int32_t num = 0,vini = 0,vouti = 0; uint8_t evalcode,funcid=0; std::vector vopret; char destaddr[64]; + int32_t num = 0,vini = 0,vouti = 0; uint8_t e=0,f=0; std::vector vopret; char destaddr[64]; *vindexp = -1; if ( mempool.size() == 0 ) return(0); if ( funcid == NSPV_MEMPOOL_CCEVALCODE ) { isCC = true; - evalcode = vout & 0xff; - funcid = (vout >> 8) & 0xff; + e = vout & 0xff; + f = (vout >> 8) & 0xff; } LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) @@ -277,10 +277,10 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coi { if ( tx.vout.size() > 1 ) { - scriptPubKey = tx.vout[tx.vout.size()-1].scriptPubKey; + CScript scriptPubKey = tx.vout[tx.vout.size()-1].scriptPubKey; if ( GetOpReturnData(scriptPubKey,vopret) != 0 ) { - if ( vpopret[0] == evalcode && vpopret[1] == funcid ) + if ( vopret[0] == evalcode && vopret[1] == funcid ) { txids.push_back(hash); num++; From d08c7516682832ad903654f3309c05984658ada7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 02:53:09 -1100 Subject: [PATCH 53/56] Test --- src/komodo_nSPV_fullnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index bfc256e2a..7c5f421c2 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -280,7 +280,7 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coi CScript scriptPubKey = tx.vout[tx.vout.size()-1].scriptPubKey; if ( GetOpReturnData(scriptPubKey,vopret) != 0 ) { - if ( vopret[0] == evalcode && vopret[1] == funcid ) + if ( vopret[0] == e && vopret[1] == f ) { txids.push_back(hash); num++; From be93e8049fcdd76da1eee3807ab50ede71bc8e33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 02:55:44 -1100 Subject: [PATCH 54/56] Syntax --- src/komodo_nSPV_fullnode.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 7c5f421c2..054077765 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -280,7 +280,8 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coi CScript scriptPubKey = tx.vout[tx.vout.size()-1].scriptPubKey; if ( GetOpReturnData(scriptPubKey,vopret) != 0 ) { - if ( vopret[0] == e && vopret[1] == f ) + uint8_t *ptr = vopret.data(); + if ( ptr[0] == e && ptr[1] == f ) { txids.push_back(hash); num++; From 580a4654365e410f090cc77d90b3d24c3559761f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 02:57:59 -1100 Subject: [PATCH 55/56] Syntax --- src/komodo_nSPV_fullnode.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 054077765..b5eba8ed3 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -243,15 +243,15 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coinaddr,bool isCC,uint8_t funcid,uint256 txid,int32_t vout) { - int32_t num = 0,vini = 0,vouti = 0; uint8_t e=0,f=0; std::vector vopret; char destaddr[64]; + int32_t num = 0,vini = 0,vouti = 0; uint8_t evalcode=0,func=0; std::vector vopret; char destaddr[64]; *vindexp = -1; if ( mempool.size() == 0 ) return(0); if ( funcid == NSPV_MEMPOOL_CCEVALCODE ) { isCC = true; - e = vout & 0xff; - f = (vout >> 8) & 0xff; + evalcode = vout & 0xff; + func = (vout >> 8) & 0xff; } LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) @@ -280,8 +280,7 @@ int32_t NSPV_mempoolfuncs(int32_t *vindexp,std::vector &txids,char *coi CScript scriptPubKey = tx.vout[tx.vout.size()-1].scriptPubKey; if ( GetOpReturnData(scriptPubKey,vopret) != 0 ) { - uint8_t *ptr = vopret.data(); - if ( ptr[0] == e && ptr[1] == f ) + if ( vopret[0] == evalcode && vopret[1] == func ) { txids.push_back(hash); num++; From 9907aaebddc26ddd6394b7e7c6ed2f0ede890f72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Jul 2019 06:57:54 -1100 Subject: [PATCH 56/56] Prevent init spam --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8fc9ea4c8..da293c242 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1772,6 +1772,8 @@ void komodo_args(char *argv0) { int32_t ecode = ccEnablesHeight[i]; int32_t ht = ccEnablesHeight[i+1]; + if ( i > 1 && ccEnablesHeight[i-2] == ecode ) + break; if ( ecode > 255 || ecode < 0 ) fprintf(stderr, "ac_ccactivateht: invalid evalcode.%i must be between 0 and 256.\n", ecode); else if ( ht > 0 )