diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 68e0da8b3..ff329a0d6 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -77,7 +77,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) //fprintf(stderr,"call passport iteration\n"); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - komodo_passport_iteration(); + if ( KOMODO_NSPV == 0 ) + komodo_passport_iteration(); for (i=0; i<10; i++) { fShutdown = ShutdownRequested(); diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index fd90df5f4..56ec85488 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -256,26 +256,6 @@ void NSPV_txproof_purge(struct NSPV_txproof *ptr) } } -/*struct NSPV_utxo -{ - struct NSPV_txproof T; - int64_t satoshis,extradata; - int32_t vout,prevht,nextht,pad32; -}; - -int32_t NSPV_rwutxo(int32_t rwflag,uint8_t *serialized,struct NSPV_utxo *ptr) -{ - int32_t len = 0; - len += NSPV_rwtxproof(rwflag,&serialized[len],&ptr->T); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->satoshis),&ptr->satoshis); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->extradata),&ptr->extradata); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->prevht),&ptr->prevht); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nextht),&ptr->nextht); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); - return(len); -}*/ - struct NSPV_ntzproofshared { struct NSPV_equihdr *hdrs; @@ -383,4 +363,13 @@ void NSPV_broadcast_purge(struct NSPV_broadcastresp *ptr) memset(ptr,0,sizeof(*ptr)); } +uint256 NSPV_doublesha256(uint8_t *data,int32_t datalen) +{ + bits256 _hash; uint256 hash; + _hash = bits256_doublesha256(0,data,datalen); + for (i=0; i<32; i++) + ((uint8_t *)&hash)[i] = _hash.bytes[31 - i]; + return(hash); +} + #endif // KOMODO_NSPV_H diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index a2f80b79e..ade2c8115 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -384,13 +384,11 @@ UniValue NSPV_spentinfo(uint256 txid,int32_t vout) UniValue NSPV_broadcast(char *hex) { - uint8_t *msg,*data; bits256 _txid; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; + uint8_t *msg,*data; uint256 txid; uint16_t n; int32_t i,len = 0; struct NSPV_broadcastresp B; n = (int32_t)strlen(hex) >> 1; data = (uint8_t *)malloc(n); decode_hex(data,n,hex); - _txid = bits256_doublesha256(0,data,n); - for (i=0; i<32; i++) - ((uint8_t *)&txid)[i] = _txid.bytes[31 - i]; + txid = NSPV_doublesha256(data,n); msg = (uint8_t *)malloc(1 + sizeof(txid) + sizeof(n) + n); msg[len++] = NSPV_BROADCAST; len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); diff --git a/src/komodo_nSPV_wallet.h b/src/komodo_nSPV_wallet.h index c96aa99db..d53d0c8a1 100644 --- a/src/komodo_nSPV_wallet.h +++ b/src/komodo_nSPV_wallet.h @@ -23,6 +23,37 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& #define NSPV_AUTOLOGOUT 60 #define NSPV_BRANCHID 0x76b809bb + +/*struct NSPV_ntzproofshared +{ + struct NSPV_equihdr *hdrs; + int32_t prevht,nextht,pad32; + uint16_t numhdrs,pad16; +}; + +struct NSPV_ntzsproofresp +{ + struct NSPV_ntzproofshared common; + uint256 prevtxid,nexttxid; + int32_t pad32,prevtxidht,nexttxidht; + uint16_t prevtxlen,nexttxlen; + uint8_t *prevntz,*nextntz; +};*/ + +int32_t NSPV_validatehdrs(struct NSPV_ntzsproofresult *ptr) +{ + int32_t i; + // verify nextntz is valid notarization + // validate blockhash of lasthdr with nextntz value, and height + for (i=numhdrs-1; i>0; i--) + { + // make sure the hash of i-1 matches the prevBlockhash of i + } + // verify prevntz is valid notarization + // verify blockhash of first hdr with prevntz value and height + return(0); +} + int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) { char *txstr; int32_t retval = 0; @@ -35,11 +66,15 @@ int32_t NSPV_gettransaction(uint256 txid,int32_t height,CTransaction &tx) retval = -1; else { - //printf("got tx.(%s)\n",txstr); - // need to validate txproof NSPV_notarizations(height); // gets the prev and next notarizations - NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment - // merkle prove txproof to the merkleroot in the corresponding hdr + if ( NSPV_ntzsresult.prevntz.height != 0 && NSPV_ntzsresult.prevntz.height <= NSPV_ntzsresult.nextntz.height ) + { + NSPV_hdrsproof(NSPV_ntzsresult.prevntz.height,NSPV_ntzsresult.nextntz.height); // validate the segment + if ( NSPV_validatehdrs(&NSPV_ntzsproofresult) == 0 ) + { + // merkle prove txproof to the merkleroot in the corresponding hdr + } + } else retval = -1; } free(txstr); return(retval);