diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 1ee338628..2ee42f0fa 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -292,7 +292,7 @@ extern std::vector NULL_pubkeys; std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret,std::vector pubkeys = NULL_pubkeys); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool CCflag = true); void SetCCtxids(std::vector > &addressIndex,char *coinaddr,bool CCflag = true); -void SetCCtxids_NSPV(std::vector > &addressIndex,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid); +void SetCCtxids(std::vector &txids,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid, uint8_t func); int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs,struct NSPV_CCmtxinfo *ptr); int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs); diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 9e20540be..16e4082bb 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -340,7 +340,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 NSPV_CCtxids(std::vector > &txids,char *coinaddr,bool ccflag,uint8_t evalcode,uint256 filtertxid); +void NSPV_CCtxids(std::vector &txids,char *coinaddr,bool ccflag, uint8_t evalcode,uint256 filtertxid, uint8_t func); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr,bool ccflag) { @@ -390,14 +390,30 @@ void SetCCtxids(std::vector > &addressIndex } } -void SetCCtxids_NSPV(std::vector > &addressIndex,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid) +void SetCCtxids(std::vector &txids,char *coinaddr,bool ccflag, uint8_t evalcode, uint256 filtertxid, uint8_t func) { + int32_t type=0,i,n; char *ptr; std::string addrstr; uint160 hashBytes; std::vector > addresses; + std::vector > addressIndex; if ( KOMODO_NSPV_SUPERLITE ) { - NSPV_CCtxids(addressIndex,coinaddr,ccflag,evalcode,filtertxid); + NSPV_CCtxids(txids,coinaddr,ccflag,evalcode,filtertxid,func); return; } - else SetCCtxids(addressIndex,coinaddr,ccflag); + n = (int32_t)strlen(coinaddr); + addrstr.resize(n+1); + ptr = (char *)addrstr.data(); + for (i=0; i<=n; i++) + ptr[i] = coinaddr[i]; + CBitcoinAddress address(addrstr); + if ( address.GetIndexKey(hashBytes, type, ccflag) == 0 ) + return; + addresses.push_back(std::make_pair(hashBytes,type)); + for (std::vector >::iterator it = addresses.begin(); it != addresses.end(); it++) + { + if ( GetAddressIndex((*it).first, (*it).second, addressIndex) == 0 ) + return; + for (std::vector >::const_iterator it1=addressIndex.begin(); it1!=addressIndex.end(); it1++) txids.push_back(it1->first.txhash); + } } int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout,int32_t CCflag) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 5e7acc6b6..219e18c54 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -787,22 +787,20 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) UniValue ChannelsList() { - UniValue result(UniValue::VOBJ); std::vector > txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; + UniValue result(UniValue::VOBJ); std::vector txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,tmp_txid,param3,tokenid; CTransaction tx; char myCCaddr[65],addr[65],str[256]; CPubKey mypk,srcpub,destpub; int32_t vout,numvouts,param1; int64_t nValue,param2; cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); GetCCaddress(cp,myCCaddr,mypk); - SetCCtxids(txids,myCCaddr,true); + SetCCtxids(txids,myCCaddr,true,EVAL_CHANNELS,zeroid,'O'); result.push_back(Pair("result","success")); result.push_back(Pair("name","Channels List")); - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - nValue = (int64_t)it->second; - if ( (vout == 1 || vout == 2) && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) + txid = *it; + if ( myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) { if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O') { @@ -820,7 +818,7 @@ UniValue ChannelsInfo(uint256 channeltxid) UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,tokenid; struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; int64_t param2,payment; CPubKey srcpub,destpub,mypk; - std::vector > addressIndex; std::vector txs; + std::vector txids; std::vector txs; cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); @@ -846,10 +844,10 @@ UniValue ChannelsInfo(uint256 channeltxid) result.push_back(Pair("Amount (satoshi)",i64tostr(param1*param2))); } GetCCaddress(cp,CCaddr,mypk); - SetCCtxids_NSPV(addressIndex,CCaddr,true,EVAL_CHANNELS,opentxid); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + SetCCtxids(txids,CCaddr,true,EVAL_CHANNELS,channeltxid,0); + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && it->second==CC_MARKER_VALUE && + if (myGetTransaction(*it,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) txs.push_back(tx); } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 5f167a224..dd4b73e73 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -481,13 +481,13 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 { char markeraddr[64],depositaddr[64]; std::string coin; int32_t numvouts; int64_t totalsupply; uint256 tokenid,oracletxid,hashBlock; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector pubkeys; CTransaction tx; - std::vector > addressIndex; + std::vector txids; _GetCCaddress(markeraddr,EVAL_GATEWAYS,gatewayspk); - SetCCtxids(addressIndex,markeraddr,true); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + SetCCtxids(txids,markeraddr,true,EVAL_GATEWAYS,zeroid,'B'); + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - if ( myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B' ) + if ( myGetTransaction(*it,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B' ) { if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' ) { @@ -1676,12 +1676,12 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) UniValue GatewaysList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector pubkeys; + UniValue result(UniValue::VARR); std::vector txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock,oracletxid,tokenid; CTransaction vintx; std::string coin; int64_t totalsupply; char str[65],depositaddr[64]; uint8_t M,N,taddr,prefix,prefix2,wiftype; std::vector pubkeys; cp = CCinit(&C,EVAL_GATEWAYS); - SetCCtxids(addressIndex,cp->unspendableCCaddr,true); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + SetCCtxids(txids,cp->unspendableCCaddr,true,EVAL_GATEWAYS,zeroid,'B'); + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - txid = it->first.txhash; + txid = *it; if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeGatewaysBindOpRet(depositaddr,vintx.vout[vintx.vout.size()-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 0 ) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 2d4e7804c..a5a3b0f14 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -792,13 +792,13 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,uint int64_t LifetimeOraclesFunds(struct CCcontract_info *cp,uint256 oracletxid,CPubKey publisher) { char coinaddr[64]; CPubKey pk; int64_t total=0,num; uint256 txid,hashBlock,subtxid; CTransaction subtx; - std::vector > addressIndex; + std::vector txids; GetCCaddress(cp,coinaddr,publisher); - SetCCtxids_NSPV(addressIndex,coinaddr,true,EVAL_ORACLES,oracletxid); + SetCCtxids(txids,coinaddr,true,EVAL_ORACLES,oracletxid,'S'); //fprintf(stderr,"scan lifetime of %s\n",coinaddr); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - txid = it->first.txhash; + txid = *it; if ( myGetTransaction(txid,subtx,hashBlock) != 0 ) { if ( subtx.vout.size() > 0 && DecodeOraclesOpRet(subtx.vout[subtx.vout.size()-1].scriptPubKey,subtxid,pk,num) == 'S' && subtxid == oracletxid && pk == publisher ) @@ -1097,7 +1097,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) { UniValue result(UniValue::VOBJ),b(UniValue::VARR); CTransaction tx,oracletx; uint256 txid,hashBlock,btxid,oracletxid; CPubKey pk; std::string name,description,format; int32_t numvouts,n=0,vout; std::vector data; char *formatstr = 0; - std::vector > addressIndex; int64_t nValue; + std::vector txids; int64_t nValue; result.push_back(Pair("result","success")); if ( myGetTransaction(reforacletxid,oracletx,hashBlock) != 0 && (numvouts=oracletx.vout.size()) > 0 ) @@ -1122,15 +1122,13 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) break; } } - SetCCtxids(addressIndex,batonaddr,true); - if (addressIndex.size()>0) + SetCCtxids(txids,batonaddr,true,EVAL_ORACLES,zeroid,'D'); + if (txids.size()>0) { - for (std::vector >::const_iterator it=addressIndex.end()-1; it!=addressIndex.begin(); it--) + for (std::vector::const_iterator it=txids.end()-1; it!=txids.begin(); it--) { - txid=it->first.txhash; - vout = (int32_t)it->first.index; - nValue = (int64_t)it->second; - if (vout==1 && nValue==10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 ) + txid=*it; + if (myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size()) > 0 ) { if ( DecodeOraclesData(tx.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) { @@ -1224,12 +1222,12 @@ UniValue OracleInfo(uint256 origtxid) UniValue OraclesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; + UniValue result(UniValue::VARR); std::vector txids; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction createtx; std::string name,description,format; char str[65]; cp = CCinit(&C,EVAL_ORACLES); - SetCCtxids(addressIndex,cp->normaladdr,false); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + SetCCtxids(txids,cp->normaladdr,false,EVAL_ORACLES,zeroid,'C'); + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - txid = it->first.txhash; + txid = *it; if ( myGetTransaction(txid,createtx,hashBlock) != 0 ) { if ( createtx.vout.size() > 0 && DecodeOraclesCreateOpRet(createtx.vout[createtx.vout.size()-1].scriptPubKey,name,description,format) == 'C' ) diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 3ffc25a11..4daa85b36 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -1225,7 +1225,7 @@ UniValue PegsAccountHistory(uint256 pegstxid) { char coinaddr[64]; int64_t nValue,amount; uint256 txid,accounttxid,hashBlock,tmptokenid,tmppegstxid; CTransaction tx; int32_t numvouts,vout; char funcid; CPubKey mypk,pegspk,pk; std::map> accounts; - std::vector > txids; std::pair account; + std::vector txids; std::pair account; UniValue result(UniValue::VOBJ),acc(UniValue::VARR); struct CCcontract_info *cp,C; result.push_back(Pair("result","success")); @@ -1234,13 +1234,11 @@ UniValue PegsAccountHistory(uint256 pegstxid) mypk = pubkey2pk(Mypubkey()); pegspk = GetUnspendable(cp,0); GetCCaddress1of2(cp,coinaddr,mypk,pegspk); - SetCCtxids_NSPV(txids,coinaddr,true,EVAL_PEGS,pegstxid); - for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + SetCCtxids(txids,coinaddr,true,EVAL_PEGS,pegstxid,0); + for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - nValue = (int64_t)it->second; - if (vout == 1 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && + txid = *it; + if (myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && (funcid=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid) { UniValue obj(UniValue::VOBJ); diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index a24639e86..0bfaa7722 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -49,6 +49,7 @@ #define NSPV_MEMPOOL_ISSPENT 2 #define NSPV_MEMPOOL_INMEMPOOL 3 #define NSPV_MEMPOOL_CCEVALCODE 4 +#define NSPV_CC_TXIDS 16 int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int32_t height,CTransaction &tx,uint256 &hashblock,int32_t &txheight,int32_t ¤theight,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 78c3939cd..20cdb8dd4 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -208,13 +208,8 @@ 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,uint32_t filter) { - int32_t maxlen,txheight,ind=0,n = 0,len = 0; CTransaction tx; uint256 hashBlock,filtertxid; + int32_t maxlen,txheight,ind=0,n = 0,len = 0; CTransaction tx; uint256 hashBlock; std::vector > txids; - if (ptr->txids!=0) - { - filtertxid=ptr->txids[0].txid; - free(ptr->txids); - } SetCCtxids(txids,coinaddr,isCC); ptr->nodeheight = chainActive.LastTip()->GetHeight(); maxlen = MAX_BLOCK_SIZE(ptr->nodeheight) - 512; @@ -236,32 +231,6 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC { if ( n >= skipcount ) { - if (filter&0xFF!=0) - { - myGetTransaction(it->first.txhash,tx,hashBlock); - std::vector> oprets; uint256 tokenid,txid; - std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; - std::vector pubkeys; - - if (DecodeTokenOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,tokenevalcode,tokenid,pubkeys,oprets)!=0 && GetOpretBlob(oprets, OPRETID_CHANNELSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) - { - vopret=vOpretExtra; - } - else GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey, vopret); - script = (uint8_t *)vopret.data(); - if ( vopret.size() > 2 && script[0]==filter&0xFF ) - { - switch (filter&0xFF) - { - case EVAL_CHANNELS:EVAL_PEGS:EVAL_ORACLES: - E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> txid;); - if (txid!=filtertxid && e==filter&0xFF) continue; - break; - default: - break; - } - } - } ptr->txids[ind].txid = it->first.txhash; ptr->txids[ind].vout = (int32_t)it->first.index; ptr->txids[ind].satoshis = (int64_t)it->second; @@ -286,6 +255,53 @@ int32_t NSPV_mempoolfuncs(bits256 *satoshisp,int32_t *vindexp,std::vector vopret; char destaddr[64]; *vindexp = -1; memset(satoshisp,0,sizeof(*satoshisp)); + if ( funcid == NSPV_CC_TXIDS) + { + std::vector > tmp_txids; uint256 tmp_txid,hashBlock; + int32_t n=0,skipcount=vout>>16; uint8_t eval=(vout>>8)&0xFF, func=vout&0xFF; + + CTransaction tx; + SetCCtxids(tmp_txids,coinaddr,isCC); + if ( skipcount < 0 ) skipcount = 0; + if ( skipcount >= tmp_txids.size() ) + skipcount = tmp_txids.size()-1; + if ( tmp_txids.size()-skipcount > 0 ) + { + for (std::vector >::const_iterator it=tmp_txids.begin(); it!=tmp_txids.end(); it++) + { + if (txid!=zeroid || func!=0) + { + myGetTransaction(it->first.txhash,tx,hashBlock); + std::vector> oprets; uint256 tokenid,txid; + std::vector vopret,vOpretExtra; uint8_t *script,e,f,tokenevalcode; + std::vector pubkeys; + + if (DecodeTokenOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,tokenevalcode,tokenid,pubkeys,oprets)!=0 && GetOpretBlob(oprets, OPRETID_CHANNELSDATA, vOpretExtra) && tokenevalcode==EVAL_TOKENS && vOpretExtra.size()>0) + { + vopret=vOpretExtra; + } + else GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey, vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0]==eval ) + { + switch (eval) + { + case EVAL_CHANNELS:EVAL_PEGS:EVAL_ORACLES: + E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> tmp_txid;); + if (e!=eval || (txid!=zeroid && txid!=tmp_txid) || (func!=0 && f!=func)) continue; + break; + default: + break; + } + } + } + if ( n >= skipcount ) txids.push_back(it->first.txhash); + n++; + } + return (n-skipcount); + } + return (0); + } if ( mempool.size() == 0 ) return(0); if ( funcid == NSPV_MEMPOOL_CCEVALCODE ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index b5f3b4ca1..cda671834 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -621,7 +621,7 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32 return(result); } -UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter, uint256 filtertxid) +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter) { UniValue result(UniValue::VOBJ); uint8_t msg[512]; 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 ) @@ -642,11 +642,6 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32 msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); len += iguana_rwnum(1,&msg[len],sizeof(filter),&filter); - if (filtertxid!=zeroid) - { - NSPV_txidsresult.txids = (struct NSPV_txidresp *)malloc(sizeof(NSPV_txidsresult.txids)); - NSPV_txidsresult.txids[0].txid=filtertxid; - } //fprintf(stderr,"skipcount.%d\n",skipcount); for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) @@ -664,6 +659,45 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32 return(result); } +UniValue NSPV_ccaddresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,uint256 filtertxid,uint8_t evalcode, uint8_t func) +{ + UniValue result(UniValue::VOBJ); uint8_t msg[512],funcid=NSPV_CC_TXIDS; char zeroes[64]; int32_t i,iter,slen,len = 0,vout; + NSPV_mempoolresp_purge(&NSPV_mempoolresult); + memset(zeroes,0,sizeof(zeroes)); + if ( coinaddr == 0 ) + coinaddr = zeroes; + if ( coinaddr[0] != 0 && bitcoin_base58decode(msg,coinaddr) != 25 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid address")); + return(result); + } + vout=skipcount << 16 | evalcode << 8 | func; + 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(filtertxid),(uint8_t *)&filtertxid); + slen = (int32_t)strlen(coinaddr); + msg[len++] = slen; + memcpy(&msg[len],coinaddr,slen), len += slen; + fprintf(stderr,"(%s) func.%d CC.%d %s skipcount.%d len.%d\n",coinaddr,NSPV_CC_TXIDS,CCflag,filtertxid.GetHex().c_str(),skipcount,len); + 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 && filtertxid == 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_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout) { UniValue result(UniValue::VOBJ); uint8_t msg[512]; char zeroes[64]; int32_t i,iter,slen,len = 0; diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index 336d40fc6..0b9ac11cf 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -522,15 +522,14 @@ void NSPV_CCunspents(std::vector > &txids,char *coinaddr,bool ccflag) { int32_t filter = 0; - NSPV_addresstxids(coinaddr,ccflag,0,filter,zeroid); + NSPV_addresstxids(coinaddr,ccflag,0,filter); NSPV_txids2CCtxids(&NSPV_txidsresult,txids); } -void NSPV_CCtxids(std::vector > &txids,char *coinaddr,bool ccflag, uint8_t evalcode,uint256 filtertxid) +void NSPV_CCtxids(std::vector &txids,char *coinaddr,bool ccflag, uint8_t evalcode,uint256 filtertxid, uint8_t func) { - int32_t filter = evalcode; - NSPV_addresstxids(coinaddr,ccflag,0,filter,filtertxid); - NSPV_txids2CCtxids(&NSPV_txidsresult,txids); + NSPV_ccaddresstxids(coinaddr,ccflag,0,filtertxid,evalcode,func); + for(int i=0;i= 1 ) @@ -1090,7 +1090,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) 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,0,zeroid)); + return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount,0)); } else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); }