From 23df289f70236cdeabca5adee79553cb86b64450 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Jul 2019 19:35:45 -1100 Subject: [PATCH] CC address support for nspv_listunspent --- src/komodo_nSPV_fullnode.h | 10 +++++++--- src/komodo_nSPV_superlite.h | 4 ++-- src/wallet/rpcdump.cpp | 21 +++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 494c511e1..f8cc47925 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -137,7 +137,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) // check mempool +int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC) // check mempool { int64_t total = 0,interest=0; uint32_t locktime; int32_t tipheight,maxlen,txheight,n = 0,len = 0; std::vector > unspentOutputs; @@ -362,12 +362,16 @@ 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 ) + 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); + fprintf(stderr,"isCC.%d\n",isCC); memset(&U,0,sizeof(U)); - if ( (slen= NSPV_getaddressutxos(&U,coinaddr)) > 0 ) + if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d23c35363..150d0859c 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -385,7 +385,7 @@ UniValue NSPV_getinfo_req(int32_t reqht) return(NSPV_getinfo_json(&NSPV_inforesult)); } -UniValue NSPV_addressutxos(char *coinaddr) +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag) { 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()); @@ -400,7 +400,7 @@ UniValue NSPV_addressutxos(char *coinaddr) msg[len++] = NSPV_UTXOS; msg[len++] = slen; memcpy(&msg[len],coinaddr,slen), len += slen; - msg[len] = 0; + msg[len++] = (CCflag != 0); 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 b197b73b0..82e44190c 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -975,7 +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_addressutxos(char *coinaddr); +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); @@ -1011,17 +1011,22 @@ UniValue nspv_login(const UniValue& params, bool fHelp) UniValue nspv_listunspent(const UniValue& params, bool fHelp) { - if ( fHelp || params.size() > 1 ) - throw runtime_error("nspv_listunspent address\n"); + int32_t CCflag = 0; + if ( fHelp || params.size() > 2 ) + throw runtime_error("nspv_listunspent address [isCC]\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addressutxos((char *)NSPV_address.c_str())); - else throw runtime_error("nspv_listunspent address\n"); + return(NSPV_addressutxos((char *)NSPV_address.c_str(),0)); + else throw runtime_error("nspv_listunspent address [isCC]\n"); } - if ( params.size() == 1 ) - return(NSPV_addressutxos((char *)params[0].get_str().c_str())); - else throw runtime_error("nspv_listunspent address\n"); + if ( params.size() >= 1 ) + { + if ( params.size() == 2 ) + CCflag = atoi((char *)params[1].get_str().c_str()); + return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag)); + } + else throw runtime_error("nspv_listunspent address [isCC]\n"); } UniValue nspv_spentinfo(const UniValue& params, bool fHelp)