From 085f99d44d2e64774cf32071ce22705393321e32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Jul 2019 00:35:44 -1100 Subject: [PATCH] Add coinaddr to utxos --- src/komodo_nSPV.h | 28 ++++++++++++++++++++++++---- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcdump.cpp | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 1a079eb70..d3d17221b 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -119,6 +119,7 @@ int32_t NSPV_rwutxoresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxoresp struct NSPV_utxosresp { struct NSPV_utxoresp *utxos; + char coinaddr[64]; int64_t total,interest; int32_t nodeheight; uint16_t numutxos,pad16; @@ -139,6 +140,16 @@ 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->pad16),&ptr->pad16); + 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); } @@ -469,6 +480,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr) // check SetCCunspents(unspentOutputs,coinaddr,false); maxlen = MAX_BLOCK_SIZE(tipheight) - 512; maxlen /= sizeof(*ptr->utxos); + strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) > 0 && ptr->numutxos < maxlen ) { tipheight = chainActive.LastTip()->GetHeight(); @@ -910,6 +922,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); result.push_back(Pair("utxos",NSPV_utxoresp_json(ptr->utxos,ptr->numutxos))); + result.push_back(Pair("address",ptr->coinaddr)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numutxos",(int64_t)ptr->numutxos)); result.push_back(Pair("balance",(double)ptr->total/COIN)); @@ -1218,12 +1231,19 @@ void komodo_nSPV(CNode *pto) // polling loop from SendMessages } } }*/ - if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) + if ( KOMODO_NSPV != 0 ) { - len = 0; - msg[len++] = NSPV_INFO; - NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); + if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > pto->prevtimes[NSPV_INFO>>1] + 2*ASSETCHAINS_BLOCKTIME/3 ) + { + len = 0; + msg[len++] = NSPV_INFO; + NSPV_req(pto,msg,len,NODE_NSPV,NSPV_INFO>>1); + } } } +UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis) // what its all about! +{ + +} #endif // KOMODO_NSPV_H diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 810848f74..c6a51d568 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -424,6 +424,7 @@ static const CRPCCommand vRPCCommands[] = { "nSPV", "nspv_notarizations", &nspv_notarizations, true }, { "nSPV", "nspv_hdrsproof", &nspv_hdrsproof, true }, { "nSPV", "nspv_txproof", &nspv_txproof, true }, + { "nSPV", "nspv_send", &nspv_send, true }, // rewards { "rewards", "rewardslist", &rewardslist, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 64c78ea47..37cb3d26a 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -462,6 +462,7 @@ extern UniValue nspv_spentinfo(const UniValue& params, bool fHelp); extern UniValue nspv_notarizations(const UniValue& params, bool fHelp); extern UniValue nspv_hdrsproof(const UniValue& params, bool fHelp); extern UniValue nspv_txproof(const UniValue& params, bool fHelp); +extern UniValue nspv_send(const UniValue& params, bool fHelp); extern UniValue getblocksubsidy(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index f7357aecf..b13a2b6c9 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_json(); UniValue NSPV_login(char *wifstr); UniValue NSPV_addressutxos(char *coinaddr); +UniValue NSPV_send(char *srcaddr,char *destaddr,int64_t satoshis); UniValue NSPV_spentinfo(uint256 txid,int32_t vout); UniValue NSPV_notarizations(int32_t height); UniValue NSPV_hdrsproof(int32_t prevheight,int32_t nextheight); @@ -1043,3 +1044,17 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) height = atoi((char *)params[1].get_str().c_str()); return(NSPV_txproof(txid,height)); } + +UniValue nspv_send(const UniValue& params, bool fHelp) +{ + uint64_t satoshis; + if ( fHelp || params.size() != 2 ) + throw runtime_error("nspv_send destaddr amount\n"); + if ( NSPV_address.size() == 0 ) + throw runtime_error("to nspv_send you need an active nspv_login\n"); + satoshis = atof(params[1].get_str().c_str())*COIN + 0.0000000049; + if ( satoshis < 1000 ) + throw runtime_error("amount too small\n"); + return(NSPV_send((char *)NSPV_address.c_str(),(char *)params[0].get_str().c_str(),satoshis)); +} +