diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 6106a6000..49e247ae4 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -336,5 +336,13 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); int32_t komodo_currentheight(); +struct NSPV_spentinfo +{ + uint256 txid,spenttxid; + int32_t vout,height,spentvin,spentheight; +}; +void komodo_nSPV_spentinfoclear(); +struct nSPV_spentinfo komodo_nSPV_spentinfo(bits256 txid,int32_t vout); + #endif diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index eec332102..5ea5b106c 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -31,6 +31,8 @@ #define NSPV_NTZPROOFRESP 0x07 #define NSPV_TXPROOF 0x08 #define NSPV_TXPROOFRESP 0x09 +#define NSPV_SPENTINFO 0x0a +#define NSPV_SPENTINFORESP 0x0b struct NSPV_ntz { @@ -97,6 +99,7 @@ struct NSPV_txproof uint32_t NSPV_lastinfo,NSPV_lastutxos; std::vector NSPV_utxos; +std::vector NSPV_spends; // on fullnode: void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a request @@ -120,6 +123,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response[0] = NSPV_UTXOSRESP; pfrom->lastutxos = timestamp; + // check mempool pfrom->PushMessage("nSPV",response); } } @@ -150,7 +154,17 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req pfrom->PushMessage("nSPV",response); } } - } + else if ( request[0] == NSPV_SPENTINFO ) + { + if ( timestamp > pfrom->lastspent ) + { + response[0] = NSPV_SPENTINFORESP; + // check mempool + pfrom->lastspent = timestamp; + pfrom->PushMessage("nSPV",response); + } + } + } } // on nSPV client @@ -176,12 +190,47 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r case NSPV_TXPROOFRESP: fprintf(stderr,"got txproof response %u\n",timestamp); // update utxos[i] break; + case NSPV_SPENTINFORESP: + fprintf(stderr,"got spentinfo response %u\n",timestamp); // update utxos[i] + break; default: fprintf(stderr,"unexpected response %02x size.%d at %u\n",response[0],(int32_t)response.size(),timestamp); break; } } } +void komodo_nSPV_spentinfoclear() +{ + nSPV_spends.resize(0); +} + +struct nSPV_spentinfo komodo_nSPV_spentinfo(bits256 txid,int32_t vout) // just a primitive example of how to add new rpc to p2p msg +{ + std::vector request; struct nSPV_spentinfo I; int32_t i,numsent = 0; uint32_t timestamp = (uint32_t)time(NULL); + // lookup spentinfo + for (i=0; ihSocket == INVALID_SOCKET ) + continue; + if ( (pto->nServices & NODE_NSPV) != 0 && timestamp > pto->lastspent ) + { + request.resize(1); + request[0] = NSPV_SPENTINFO; + pto->lastspent = timestamp; + pto->PushMessage("getnSPV",request); + if ( ++numsent >= 3 ) + break; + } + } +} + void komodo_nSPV(CNode *pto) { std::vector request; int32_t i; uint32_t timestamp = (uint32_t)time(NULL); diff --git a/src/net.h b/src/net.h index 3b9ad176f..dce52aa8b 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 lastutxos,lastinfo,lastntzs,lastproof; + uint32_t lastutxos,lastinfo,lastntzs,lastproof,lastspent; CAddress addr; std::string addrName; CService addrLocal;