CC address support for nspv_listunspent
This commit is contained in:
@@ -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<std::pair<CAddressUnspentKey, CAddressUnspentValue> > unspentOutputs;
|
||||
@@ -362,12 +362,16 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> 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;
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user