diff --git a/src/cc/CCImportGateway.h b/src/cc/CCImportGateway.h index 671b431cd..9be54f23a 100644 --- a/src/cc/CCImportGateway.h +++ b/src/cc/CCImportGateway.h @@ -28,7 +28,6 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string refcoin, std::string hex); std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::string refcoin,std::string hex); std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::string refcoin); -UniValue ImportGatewayPendingDeposits(uint256 bindtxid,std::string refcoin); UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin); UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin); UniValue ImportGatewayExternalAddress(uint256 bindtxid,CPubKey pubkey); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 24acc03e2..d26b4b7ad 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -176,12 +176,14 @@ static const uint256 zeroid; static uint256 ignoretxid; static int32_t ignorevin; bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock); +bool NSPV_myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock, int32_t &txheight, int32_t ¤theight); int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx, CValidationState *pstate = NULL, bool fSkipExpiry = false); int64_t CCgettxout(uint256 txid,int32_t vout,int32_t mempoolflag,int32_t lockflag); bool myIsutxo_spentinmempool(uint256 &spenttxid,int32_t &spentvini,uint256 txid,int32_t vout); bool mytxid_inmempool(uint256 txid); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); +int32_t myGet_mempool_txs(std::vector &txs,uint8_t evalcode,uint8_t funcid); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index dfb8aeff3..7e376e0ce 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -444,12 +444,19 @@ std::vector Mypubkey() } extern char NSPV_wifstr[],NSPV_pubkeystr[]; +extern uint32_t NSPV_logintime; +#define NSPV_AUTOLOGOUT 777 bool Myprivkey(uint8_t myprivkey[]) { char coinaddr[64],checkaddr[64]; std::string strAddress; char *dest; int32_t i,n; CBitcoinAddress address; CKeyID keyID; CKey vchSecret; uint8_t buf33[33]; if ( KOMODO_NSPV != 0 ) { + if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) + { + fprintf(stderr,"need to be logged in to get myprivkey\n"); + return false; + } vchSecret = DecodeSecret(NSPV_wifstr); memcpy(myprivkey,vchSecret.begin(),32); //for (i=0; i<32; i++) @@ -605,6 +612,32 @@ int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr) return(0); } +extern struct NSPV_mempoolresp NSPV_mempoolresult; +extern bool NSPV_evalcode_inmempool(uint8_t evalcode,uint8_t funcid); + +int32_t myGet_mempool_txs(std::vector &txs,uint8_t evalcode,uint8_t funcid) +{ + int i=0; + + if ( KOMODO_NSPV != 0 ) + { + CTransaction tx; uint256 hashBlock; + + NSPV_evalcode_inmempool(evalcode,funcid); + for (int i=0;i &proofData, std::ve bool komodo_txnotarizedconfirmed(uint256 txid) { char str[65]; - uint32_t confirms,notarized=0,txheight; + int32_t confirms,notarized=0,txheight=0,currentheight=0;; CTransaction tx; uint256 hashBlock; CBlockIndex *pindex; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; - if ( myGetTransaction(txid,tx,hashBlock) == 0 ) + if (KOMODO_NSPV!=0) { - fprintf(stderr,"komodo_txnotarizedconfirmed cant find txid %s\n",txid.ToString().c_str()); - return(0); + if ( NSPV_myGetTransaction(txid,tx,hashBlock,txheight,currentheight) == 0 ) + { + fprintf(stderr,"komodo_txnotarizedconfirmed cant find txid %s\n",txid.ToString().c_str()); + return(0); + } + else if (txheight<=0) + { + fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d for txid %s\n",txheight,txid.ToString().c_str()); + return(0); + } + else if (txheight>currentheight) + { + fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,currentheight); + return(0); + } + confirms=1 + currentheight - txheight; } - else if ( hashBlock == zeroid ) + else { - fprintf(stderr,"komodo_txnotarizedconfirmed no hashBlock for txid %s\n",txid.ToString().c_str()); - return(0); + if ( myGetTransaction(txid,tx,hashBlock) == 0 ) + { + fprintf(stderr,"komodo_txnotarizedconfirmed cant find txid %s\n",txid.ToString().c_str()); + return(0); + } + else if ( hashBlock == zeroid ) + { + fprintf(stderr,"komodo_txnotarizedconfirmed no hashBlock for txid %s\n",txid.ToString().c_str()); + return(0); + } + else if ( (pindex= komodo_blockindex(hashBlock)) == 0 || (txheight= pindex->GetHeight()) <= 0 ) + { + fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d %p for txid %s\n",txheight,pindex,txid.ToString().c_str()); + return(0); + } + else if ( (pindex= chainActive.LastTip()) == 0 || pindex->GetHeight() < txheight ) + { + fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,(int32_t)pindex->GetHeight()); + return(0); + } + confirms=1 + pindex->GetHeight() - txheight; } - else if ( (pindex= komodo_blockindex(hashBlock)) == 0 || (txheight= pindex->GetHeight()) <= 0 ) - { - fprintf(stderr,"komodo_txnotarizedconfirmed no txheight.%d %p for txid %s\n",txheight,pindex,txid.ToString().c_str()); - return(0); - } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->GetHeight() < txheight ) - { - fprintf(stderr,"komodo_txnotarizedconfirmed backwards heights for txid %s hts.(%d %d)\n",txid.ToString().c_str(),txheight,(int32_t)pindex->GetHeight()); - return(0); - } - confirms=1 + pindex->GetHeight() - txheight; + if ((sp= komodo_stateptr(symbol,dest)) != 0 && (notarized=sp->NOTARIZED_HEIGHT) > 0 && txheight > sp->NOTARIZED_HEIGHT) notarized=0; #ifdef TESTMODE notarized=0; diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 3a87b9fc2..9545090c1 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -431,12 +431,14 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C { txid=zeroid; int32_t mindepth=CHANNELS_MAXPAYMENTS; - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_CHANNELS,'P'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &txmempool = e.GetTx(); + const CTransaction &txmempool = *it; const uint256 &hash = txmempool.GetHash(); - if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) != 0 && + if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)=='P' && tmp_txid==openTx.GetHash() && param1 < mindepth) { txid=hash; @@ -815,10 +817,10 @@ UniValue ChannelsList() UniValue ChannelsInfo(uint256 channeltxid) { - UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid,tokenid; + UniValue result(UniValue::VOBJ),array(UniValue::VARR); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,tokenid; struct CCcontract_info *cp,C; char CCaddr[65],addr[65],str[512]; int32_t vout,numvouts,param1,numpayments; int64_t param2,payment; CPubKey srcpub,destpub,mypk; - std::vector > addressIndex; std::vector txids; + std::vector > addressIndex; std::vector txs; cp = CCinit(&C,EVAL_CHANNELS); mypk = pubkey2pk(Mypubkey()); @@ -826,7 +828,7 @@ UniValue ChannelsInfo(uint256 channeltxid) if (myGetTransaction(channeltxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'O')) { - GetCCaddress(cp,CCaddr,mypk); + GetCCaddress1of2(cp,CCaddr,srcpub,destpub); Getscriptaddress(addr,CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG); result.push_back(Pair("result","success")); result.push_back(Pair("Channel CC address",CCaddr)); @@ -842,32 +844,33 @@ UniValue ChannelsInfo(uint256 channeltxid) { result.push_back(Pair("Denomination (satoshi)",i64tostr(param2))); result.push_back(Pair("Amount (satoshi)",i64tostr(param1*param2))); - } + } + GetCCaddress(cp,CCaddr,mypk); SetCCtxids(addressIndex,CCaddr,true); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { - if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) - if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) - txids.push_back(it->first.txhash); + if (myGetTransaction(it->first.txhash,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 && it->second==CC_MARKER_VALUE && + DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3)!=0 && (tmp_txid==channeltxid || tx.GetHash()==channeltxid)) + txs.push_back(tx); } - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_CHANNELS,'P'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &txmempool = e.GetTx(); - const uint256 &hash = txmempool.GetHash(); + const CTransaction &txmempool = *it; if ((numvouts=txmempool.vout.size()) > 0 && DecodeChannelsOpRet(txmempool.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'P' && tmp_txid==channeltxid) - txids.push_back(hash); + txs.push_back(txmempool); } - prevtxid=zeroid; - for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) + for (std::vector::const_iterator it=txs.begin(); it!=txs.end(); it++) { - txid=*it; - if (txid!=prevtxid && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size()) > 0 ) + tx=*it; + if ((numvouts= tx.vout.size()) > 0 ) { UniValue obj(UniValue::VOBJ); if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,param1,param2,param3) == 'O' && tx.GetHash()==channeltxid) { - obj.push_back(Pair("Open",txid.GetHex().data())); + obj.push_back(Pair("Open",tx.GetHash().GetHex().data())); } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) { @@ -875,7 +878,7 @@ UniValue ChannelsInfo(uint256 channeltxid) DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tokenid,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { Getscriptaddress(str,tx.vout[3].scriptPubKey); - obj.push_back(Pair("Payment",txid.GetHex().data())); + obj.push_back(Pair("Payment",tx.GetHash().GetHex().data())); obj.push_back(Pair("Number of payments",param2)); obj.push_back(Pair("Amount",param2*payment)); obj.push_back(Pair("Destination",str)); @@ -885,18 +888,17 @@ UniValue ChannelsInfo(uint256 channeltxid) } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'C' && opentxid==channeltxid) { - obj.push_back(Pair("Close",txid.GetHex().data())); + obj.push_back(Pair("Close",tx.GetHash().GetHex().data())); } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,tokenid,opentxid,srcpub,destpub,param1,param2,param3) == 'R' && opentxid==channeltxid) { Getscriptaddress(str,tx.vout[2].scriptPubKey); - obj.push_back(Pair("Refund",txid.GetHex().data())); + obj.push_back(Pair("Refund",tx.GetHash().GetHex().data())); obj.push_back(Pair("Amount",param1*param2)); obj.push_back(Pair("Destination",str)); } array.push_back(obj); } - prevtxid=txid; } result.push_back(Pair("Transactions",array)); } diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c25a6e001..1f0b9d59f 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -499,10 +499,11 @@ int32_t GatewaysBindExists(struct CCcontract_info *cp,CPubKey gatewayspk,uint256 } } } - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_GATEWAYS,'B'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &txmempool = e.GetTx(); - const uint256 &hash = txmempool.GetHash(); + const CTransaction &txmempool = *it; if ((numvouts=txmempool.vout.size()) > 0 && DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)=='B') if (DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B' && @@ -1164,7 +1165,7 @@ std::string GatewaysWithdraw(uint64_t txfee,uint256 bindtxid,std::string refcoin vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P')) { if (funcid=='W' && DecodeGatewaysWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmptokenid,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' @@ -1503,7 +1504,7 @@ UniValue GatewaysPendingDeposits(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && DecodeGatewaysDepositOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,publishers,txids,height,cointxid,claimvout,hex,proof,destpub,amount) == 'D' && tmpbindtxid==bindtxid && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { @@ -1567,7 +1568,7 @@ UniValue GatewaysPendingWithdraws(uint256 bindtxid,std::string refcoin) vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P') && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { if (funcid=='W') @@ -1654,7 +1655,7 @@ UniValue GatewaysProcessedWithdraws(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && DecodeGatewaysCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,hex) == 'S' && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { if (myGetTransaction(withdrawtxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 diff --git a/src/cc/importgateway.cpp b/src/cc/importgateway.cpp index e5590bb3d..1f16c7fd4 100644 --- a/src/cc/importgateway.cpp +++ b/src/cc/importgateway.cpp @@ -278,10 +278,11 @@ int32_t ImportGatewayBindExists(struct CCcontract_info *cp,CPubKey importgateway } } } - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_IMPORTGATEWAY,'B'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &txmempool = e.GetTx(); - const uint256 &hash = txmempool.GetHash(); + const CTransaction &txmempool = *it; if ((numvouts=txmempool.vout.size()) > 0 && DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey)=='B') if (DecodeImportGatewayBindOpRet(burnaddr,tx.vout[numvouts-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) == 'B') @@ -568,7 +569,7 @@ std::string ImportGatewayDeposit(uint64_t txfee,uint256 bindtxid,int32_t height, if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) { - CCerror = strprintf("CheckGATEWAYimport invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } @@ -645,6 +646,12 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re std::vector msigpubkeys; char burnaddr[64],str[65],coinaddr[64]; struct CCcontract_info *cp,C; std::vector > unspentOutputs; + if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) + { + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } cp = CCinit(&C,EVAL_IMPORTGATEWAY); if ( txfee == 0 ) txfee = 10000; @@ -677,7 +684,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P')) { if (funcid=='W' && DecodeImportGatewayWithdrawOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,withdrawpub,tmpamount)=='W' @@ -701,7 +708,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re if( AddNormalinputs(mtx, mypk, txfee+CC_MARKER_VALUE+amount, 64) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_IMPORTGATEWAY,CC_MARKER_VALUE,importgatewaypk)); - mtx.vout.push_back(MakeCC1vout(EVAL_IMPORTGATEWAY,amount,importgatewaypk)); + mtx.vout.push_back(MakeCC1vout(EVAL_IMPORTGATEWAY,amount,CCtxidaddr(str,bindtxid))); return(FinalizeCCTx(0, cp, mtx, mypk, txfee,EncodeImportGatewayWithdrawOpRet('W',bindtxid,refcoin,withdrawpub,amount))); } CCerror = strprintf("cant find enough normal inputs"); @@ -738,6 +745,12 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } + else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) + { + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } else if (komodo_txnotarizedconfirmed(withdrawtxid)==false) { CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized"); @@ -779,6 +792,12 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } + else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) + { + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } else if (komodo_txnotarizedconfirmed(withdrawtxid)==false) { CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized"); @@ -844,12 +863,24 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } + else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) + { + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } else if (komodo_txnotarizedconfirmed(withdrawtxid)==false) { CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized"); LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } + else if (GetTransaction(bindtxid,tmptx,hashBlock,false)==0 || (numvouts=tmptx.vout.size())<=0) + { + CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } else if (DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin!=coin) { @@ -878,6 +909,12 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } + else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) + { + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } else if (komodo_txnotarizedconfirmed(withdrawtxid)==false) { CCerror = strprintf("gatewayswithdraw tx not yet confirmed/notarized"); @@ -950,6 +987,12 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); return(""); } + else if (KOMODO_EARLYTXID!=zeroid && bindtxid!=KOMODO_EARLYTXID) + { + CCerror = strprintf("invalid import gateway. On this chain only valid import gateway is %s",KOMODO_EARLYTXID.GetHex()); + LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); + return(""); + } else if (myGetTransaction(bindtxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) { CCerror = strprintf("can't find bind tx %s",uint256_str(str,bindtxid)); @@ -974,61 +1017,6 @@ std::string ImportGatewayMarkDone(uint64_t txfee,uint256 completetxid,std::strin return(""); } -UniValue ImportGatewayPendingDeposits(uint256 bindtxid,std::string refcoin) -{ - UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex,pub; - CPubKey mypk,importgatewaypk,destpub; std::vector pubkeys,publishers; std::vector txids; - uint256 tmpbindtxid,hashBlock,txid,oracletxid,burntxid; uint8_t M,N,taddr,prefix,prefix2,wiftype; - char burnaddr[65],coinaddr[65],str[65],destaddr[65],txidaddr[65]; std::vector proof; - int32_t numvouts,vout,claimvout,height; int64_t nValue,amount; struct CCcontract_info *cp,C; - std::vector > unspentOutputs; - - cp = CCinit(&C,EVAL_IMPORTGATEWAY); - mypk = pubkey2pk(Mypubkey()); - importgatewaypk = GetUnspendable(cp,0); - _GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,mypk); - if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) - { - CCerror = strprintf("cant find bindtxid %s",uint256_str(str,bindtxid)); - LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); - return(""); - } - if ( DecodeImportGatewayBindOpRet(burnaddr,tx.vout[numvouts-1].scriptPubKey,coin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin) - { - CCerror = strprintf("invalid bindtxid %s coin.%s",uint256_str(str,bindtxid),coin.c_str()); - LOGSTREAM("importgateway",CCLOG_INFO, stream << CCerror << std::endl); - return(""); - } - SetCCunspents(unspentOutputs,coinaddr,true); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) - { - txid = it->first.txhash; - vout = (int32_t)it->first.index; - nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts=tx.vout.size())>0 && - DecodeImportGatewayDepositOpRet(tx.vout[numvouts-1].scriptPubKey,tmpbindtxid,coin,publishers,txids,height,burntxid,claimvout,hex,proof,destpub,amount) == 'D' - && tmpbindtxid==bindtxid && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) - { - UniValue obj(UniValue::VOBJ); - obj.push_back(Pair("burntxid",uint256_str(str,burntxid))); - obj.push_back(Pair("deposittxid",uint256_str(str,txid))); - CCtxidaddr(txidaddr,txid); - obj.push_back(Pair("deposittxidaddr",txidaddr)); - _GetCCaddress(destaddr,EVAL_TOKENS,destpub); - obj.push_back(Pair("depositaddr",burnaddr)); - obj.push_back(Pair("tokens_destination_address",destaddr)); - pub=HexStr(destpub); - obj.push_back(Pair("claim_pubkey",pub)); - obj.push_back(Pair("amount",(double)amount/COIN)); - obj.push_back(Pair("confirmed_or_notarized",komodo_txnotarizedconfirmed(txid))); - pending.push_back(obj); - } - } - result.push_back(Pair("coin",refcoin)); - result.push_back(Pair("pending",pending)); - return(result); -} - UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin) { UniValue result(UniValue::VOBJ),pending(UniValue::VARR); CTransaction tx; std::string coin,hex; CPubKey mypk,importgatewaypk,withdrawpub,signerpk; @@ -1068,7 +1056,7 @@ UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin) vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; K=0; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))!=0 && (funcid=='W' || funcid=='P') && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { if (funcid=='W') @@ -1155,7 +1143,7 @@ UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin) txid = it->first.txhash; vout = (int32_t)it->first.index; nValue = (int64_t)it->second.satoshis; - if ( vout == 0 && nValue == 10000 && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && + if ( vout == 0 && nValue == CC_MARKER_VALUE && myGetTransaction(txid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 && DecodeImportGatewayCompleteSigningOpRet(tx.vout[numvouts-1].scriptPubKey,withdrawtxid,coin,K,hex) == 'S' && refcoin == coin && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0) { if (myGetTransaction(withdrawtxid,tx,hashBlock) != 0 && (numvouts= tx.vout.size())>0 diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 0830ca6c1..01be01199 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -247,9 +247,11 @@ int64_t OracleDatafee(CScript &scriptPubKey,uint256 oracletxid,CPubKey publisher static uint256 myIs_baton_spentinmempool(uint256 batontxid,int32_t batonvout) { - BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_ORACLES,'D'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &tx = e.GetTx(); + const CTransaction &tx = *it; if ( tx.vout.size() > 0 && tx.vin.size() > 1 && batontxid == tx.vin[1].prevout.hash && batonvout == tx.vin[1].prevout.n ) { const uint256 &txid = tx.GetHash(); @@ -830,9 +832,11 @@ int64_t AddMyOraclesFunds(struct CCcontract_info *cp,CMutableTransaction &mtx,CP } else fprintf(stderr,"couldnt find transaction\n"); } - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_ORACLES,'F'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &txmempool = e.GetTx(); + const CTransaction &txmempool = *it; const uint256 &hash = txmempool.GetHash(); nValue=txmempool.vout[0].nValue; @@ -1099,9 +1103,11 @@ UniValue OracleDataSamples(uint256 reforacletxid,char* batonaddr,int32_t num) { if ( DecodeOraclesCreateOpRet(oracletx.vout[numvouts-1].scriptPubKey,name,description,format) == 'C' ) { - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + std::vector tmp_txs; + myGet_mempool_txs(tmp_txs,EVAL_ORACLES,'D'); + for (std::vector::const_iterator it=tmp_txs.begin(); it!=tmp_txs.end(); it++) { - const CTransaction &txmempool = e.GetTx(); + const CTransaction &txmempool = *it; const uint256 &hash = txmempool.GetHash(); if ((numvouts=txmempool.vout.size())>0 && DecodeOraclesData(txmempool.vout[numvouts-1].scriptPubKey,oracletxid,btxid,pk,data) == 'D' && reforacletxid == oracletxid ) { diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 949417be5..6a31a3810 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -470,7 +470,7 @@ std::string PegsDecodeAccountTx(CTransaction tx,CPubKey& pk,int64_t &amount,std: char PegsFindAccount(struct CCcontract_info *cp,CPubKey pk,uint256 pegstxid, uint256 tokenid, uint256 &accounttxid, std::pair &account) { - char coinaddr[64]; int64_t nValue,tmpamount; uint256 txid,hashBlock,tmptokenid,tmppegstxid; + char coinaddr[64]; int64_t nValue,tmpamount; uint256 txid,spenttxid,hashBlock,tmptokenid,tmppegstxid; CTransaction tx,acctx; int32_t numvouts,vout,ratio; char funcid,f; CPubKey pegspk,tmppk; std::vector > unspentOutputs; ImportProof proof; CTransaction burntx; std::vector payouts; @@ -493,20 +493,15 @@ char PegsFindAccount(struct CCcontract_info *cp,CPubKey pk,uint256 pegstxid, uin acctx=tx; } } - if (accounttxid!=zeroid && myIsutxo_spentinmempool(ignoretxid,ignorevin,accounttxid,1) != 0) + if (accounttxid!=zeroid && myIsutxo_spentinmempool(spenttxid,ignorevin,accounttxid,1) != 0) { accounttxid=zeroid; - BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) + if (myGetTransaction(spenttxid,tx,hashBlock)!=0 && (numvouts=tx.vout.size()) > 0 && + (f=DecodePegsOpRet(tx,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid) { - const CTransaction &txmempool = e.GetTx(); - const uint256 &hash = txmempool.GetHash(); - - if ((numvouts=txmempool.vout.size()) > 0 && (f=DecodePegsOpRet(txmempool,tmppegstxid,tmptokenid))!=0 && pegstxid==tmppegstxid && tokenid==tmptokenid) - { - funcid=f; - accounttxid=hash; - acctx=txmempool; - } + funcid=f; + accounttxid=spenttxid; + acctx=tx; } } if (accounttxid!=zeroid) diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 27f03a5be..9b23cb018 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -101,7 +101,7 @@ int32_t NSPV_rwutxosresp(int32_t rwflag,uint8_t *serialized,struct NSPV_utxosres len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->total),&ptr->total); 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->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->filter),&ptr->filter); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount); if ( rwflag != 0 ) @@ -159,7 +159,7 @@ int32_t NSPV_rwtxidsresp(int32_t rwflag,uint8_t *serialized,struct NSPV_txidsres len += NSPV_rwtxidresp(rwflag,&serialized[len],&ptr->txids[i]); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->nodeheight),&ptr->nodeheight); - len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->pad32),&ptr->pad32); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->filter),&ptr->filter); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->CCflag),&ptr->CCflag); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->skipcount),&ptr->skipcount); if ( rwflag != 0 ) @@ -286,7 +286,7 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); - //fprintf(stderr,"hdr rwlen.%d\n",len); +//fprintf(stderr,"hdr rwlen.%d\n",len); return(len); } @@ -305,6 +305,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->vout),&ptr->vout); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->hashblock),(uint8_t *)&ptr->hashblock); return(len); } @@ -493,14 +494,15 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t continue; char coinaddr[64]; Getscriptaddress(coinaddr,scriptPubKeys[j]); NSPV_SignTx(mtx,vini,10000,scriptPubKeys[j],nTime); // sets SIG_TXHASH + //fprintf(stderr,"%s ",SIG_TXHASH.GetHex().c_str()); if ( (retval= pubkeys[j].Verify(SIG_TXHASH,vData[0])) != 0 ) { - fprintf(stderr,"(vini.%d %s.%d) ",vini,coinaddr,retval); + //fprintf(stderr,"(vini.%d %s.%d) ",vini,coinaddr,retval); mask |= (1LL << j); break; } } - fprintf(stderr," verified %llx\n",(long long)mask); + //fprintf(stderr," vini.%d verified %llx\n",vini,(long long)mask); } } return(bitweight(mask)); @@ -515,11 +517,11 @@ int32_t NSPV_fastnotariescount(CTransaction tx,uint8_t elected[64][33],uint32_t */ int32_t NSPV_notariescount(CTransaction tx,uint8_t elected[64][33]) { - uint8_t *script; CTransaction vintx; int64_t rewardsum = 0; int32_t i,j,utxovout,scriptlen,numsigs = 0; + uint8_t *script; CTransaction vintx; int64_t rewardsum = 0; int32_t i,j,utxovout,scriptlen,numsigs = 0,txheight,currentheight; uint256 hashBlock; for (i=0; i > unspentOutputs; @@ -148,6 +148,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC maxlen /= sizeof(*ptr->utxos); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; + ptr->filter = filter; if ( skipcount < 0 ) skipcount = 0; if ( (ptr->numutxos= (int32_t)unspentOutputs.size()) >= 0 && ptr->numutxos < maxlen ) @@ -198,7 +199,7 @@ int32_t NSPV_getaddressutxos(struct NSPV_utxosresp *ptr,char *coinaddr,bool isCC return(0); } -int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount) +int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC,int32_t skipcount,uint32_t filter) { int32_t maxlen,txheight,ind=0,n = 0,len = 0; std::vector > txids; @@ -208,6 +209,7 @@ int32_t NSPV_getaddresstxids(struct NSPV_txidsresp *ptr,char *coinaddr,bool isCC maxlen /= sizeof(*ptr->txids); strncpy(ptr->coinaddr,coinaddr,sizeof(ptr->coinaddr)-1); ptr->CCflag = isCC; + ptr->filter = filter; if ( skipcount < 0 ) skipcount = 0; if ( (ptr->numtxids= (int32_t)txids.size()) >= 0 && ptr->numtxids < maxlen ) @@ -363,7 +365,10 @@ uint8_t *NSPV_getrawtx(CTransaction &tx,uint256 &hashBlock,int32_t *txlenp,uint2 *txlenp = 0; { if (!GetTransaction(txid, tx, hashBlock, false)) + { + //fprintf(stderr,"error getting transaction %s\n",txid.GetHex().c_str()); return(0); + } string strHex = EncodeHexTx(tx); *txlenp = (int32_t)strHex.size() >> 1; if ( *txlenp > 0 ) @@ -405,33 +410,39 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,int32_t vout,uint256 txid,int32 return(-1); ptr->txid = txid; ptr->vout = vout; - ptr->height = height; - if ( height != 0 && (pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) + ptr->hashblock = hashBlock; + if ( height == 0 ) + ptr->height = komodo_blockheight(hashBlock); + else { - BOOST_FOREACH(const CTransaction&tx, block.vtx) + ptr->height = height; + if ((pindex= komodo_chainactive(height)) != 0 && komodo_blockload(block,pindex) == 0 ) { - if ( tx.GetHash() == txid ) + BOOST_FOREACH(const CTransaction&tx, block.vtx) { - flag = 1; - break; + if ( tx.GetHash() == txid ) + { + flag = 1; + break; + } } - } - if ( flag != 0 ) - { - set setTxids; - CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); - setTxids.insert(txid); - CMerkleBlock mb(block, setTxids); - ssMB << mb; - std::vector proof(ssMB.begin(), ssMB.end()); - ptr->txprooflen = (int32_t)proof.size(); - //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); - if ( ptr->txprooflen > 0 ) + if ( flag != 0 ) { - ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); - memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + set setTxids; + CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION); + setTxids.insert(txid); + CMerkleBlock mb(block, setTxids); + ssMB << mb; + std::vector proof(ssMB.begin(), ssMB.end()); + ptr->txprooflen = (int32_t)proof.size(); + //fprintf(stderr,"%s txproof.(%s)\n",txid.GetHex().c_str(),HexStr(proof).c_str()); + if ( ptr->txprooflen > 0 ) + { + ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); + memcpy(ptr->txproof,&proof[0],ptr->txprooflen); + } + //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); } - //fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen)); } } ptr->unspentvalue = CCgettxout(txid,vout,1,1); @@ -529,6 +540,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req //fprintf(stderr,"slen.%d\n",slen); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { + //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } @@ -541,23 +553,29 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req //fprintf(stderr,"utxos: %u > %u, ind.%d, len.%d\n",timestamp,pfrom->prevtimes[ind],ind,len); if ( timestamp > pfrom->prevtimes[ind] ) { - struct NSPV_utxosresp U; char coinaddr[64]; - if ( len < 64 && (request[1] == len-3 || request[1] == len-7) ) + struct NSPV_utxosresp U; + if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7 || request[1] == len-11) ) { - int32_t skipcount = 0; uint8_t isCC = 0; + int32_t skipcount = 0; char coinaddr[64]; uint8_t filter; uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; if ( request[1] == len-3 ) isCC = (request[len-1] != 0); - else + else if ( request[1] == len-7 ) { isCC = (request[len-5] != 0); iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount); } + else + { + isCC = (request[len-9] != 0); + iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount); + iguana_rwnum(0,&request[len-4],sizeof(filter),&filter); + } if ( isCC != 0 ) - fprintf(stderr,"%s isCC.%d skipcount.%d\n",coinaddr,isCC,skipcount); + fprintf(stderr,"utxos %s isCC.%d skipcount.%d filter.%x\n",coinaddr,isCC,skipcount,filter); memset(&U,0,sizeof(U)); - if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC,skipcount)) > 0 ) + if ( (slen= NSPV_getaddressutxos(&U,coinaddr,isCC,skipcount,filter)) > 0 ) { response.resize(1 + slen); response[0] = NSPV_UTXOSRESP; @@ -575,23 +593,29 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { if ( timestamp > pfrom->prevtimes[ind] ) { - struct NSPV_txidsresp T; char coinaddr[64]; - if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7) ) + struct NSPV_txidsresp T; + if ( len < 64+5 && (request[1] == len-3 || request[1] == len-7 || request[1] == len-11) ) { - int32_t skipcount = 0; uint8_t isCC = 0; + int32_t skipcount = 0; char coinaddr[64]; uint32_t filter; uint8_t isCC = 0; memcpy(coinaddr,&request[2],request[1]); coinaddr[request[1]] = 0; if ( request[1] == len-3 ) isCC = (request[len-1] != 0); - else + else if ( request[1] == len-7 ) { isCC = (request[len-5] != 0); iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount); } + else + { + isCC = (request[len-9] != 0); + iguana_rwnum(0,&request[len-4],sizeof(skipcount),&skipcount); + iguana_rwnum(0,&request[len-4],sizeof(filter),&filter); + } //if ( isCC != 0 ) - fprintf(stderr,"%s isCC.%d skipcount.%d\n",coinaddr,isCC,skipcount); + fprintf(stderr,"txids %s isCC.%d skipcount.%d filter.%d\n",coinaddr,isCC,skipcount,filter); memset(&T,0,sizeof(T)); - if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount)) > 0 ) + if ( (slen= NSPV_getaddresstxids(&T,coinaddr,isCC,skipcount,filter)) > 0 ) { //fprintf(stderr,"slen.%d\n",slen); response.resize(1 + slen); @@ -705,16 +729,18 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req memset(&P,0,sizeof(P)); if ( (slen= NSPV_gettxproof(&P,vout,txid,height)) > 0 ) { + //fprintf(stderr,"slen.%d\n",slen); response.resize(1 + slen); response[0] = NSPV_TXPROOFRESP; if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) { + //fprintf(stderr,"send response\n"); pfrom->PushMessage("nSPV",response); pfrom->prevtimes[ind] = timestamp; } NSPV_txproof_purge(&P); - } - } + } else fprintf(stderr,"gettxproof error.%d\n",slen); + } else fprintf(stderr,"txproof reqlen.%d\n",len); } } else if ( request[0] == NSPV_SPENTINFO ) diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index f8dae10bf..d7f11c41b 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -59,7 +59,7 @@ struct NSPV_ntzsresp *NSPV_ntzsresp_add(struct NSPV_ntzsresp *ptr) if ( NSPV_ntzsresp_cache[i].reqheight == 0 ) break; if ( i == sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache) ) - i == (rand() % (sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache))); + i = (rand() % (sizeof(NSPV_ntzsresp_cache)/sizeof(*NSPV_ntzsresp_cache))); NSPV_ntzsresp_purge(&NSPV_ntzsresp_cache[i]); NSPV_ntzsresp_copy(&NSPV_ntzsresp_cache[i],ptr); fprintf(stderr,"ADD CACHE ntzsresp req.%d\n",ptr->reqheight); @@ -98,7 +98,7 @@ struct NSPV_txproof *NSPV_txproof_add(struct NSPV_txproof *ptr) if ( NSPV_txproof_cache[i].txlen == 0 ) break; if ( i == sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache) ) - i == (rand() % (sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache))); + i = (rand() % (sizeof(NSPV_txproof_cache)/sizeof(*NSPV_txproof_cache))); NSPV_txproof_purge(&NSPV_txproof_cache[i]); NSPV_txproof_copy(&NSPV_txproof_cache[i],ptr); fprintf(stderr,"ADD CACHE txproof %s\n",ptr->txid.GetHex().c_str()); @@ -121,7 +121,7 @@ struct NSPV_ntzsproofresp *NSPV_ntzsproof_add(struct NSPV_ntzsproofresp *ptr) if ( NSPV_ntzsproofresp_cache[i].common.hdrs == 0 ) break; if ( i == sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache) ) - i == (rand() % (sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache))); + i = (rand() % (sizeof(NSPV_ntzsproofresp_cache)/sizeof(*NSPV_ntzsproofresp_cache))); NSPV_ntzsproofresp_purge(&NSPV_ntzsproofresp_cache[i]); NSPV_ntzsproofresp_copy(&NSPV_ntzsproofresp_cache[i],ptr); fprintf(stderr,"ADD CACHE ntzsproof %s %s\n",ptr->prevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); @@ -403,6 +403,7 @@ UniValue NSPV_utxosresp_json(struct NSPV_utxosresp *ptr) result.push_back(Pair("balance",(double)ptr->total/COIN)); if ( ASSETCHAINS_SYMBOL[0] == 0 ) result.push_back(Pair("interest",(double)ptr->interest/COIN)); + result.push_back(Pair("filter",(int64_t)ptr->filter)); result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -433,6 +434,7 @@ UniValue NSPV_txidsresp_json(struct NSPV_txidsresp *ptr) result.push_back(Pair("isCC",ptr->CCflag)); result.push_back(Pair("height",(int64_t)ptr->nodeheight)); result.push_back(Pair("numtxids",(int64_t)ptr->numtxids)); + result.push_back(Pair("filter",(int64_t)ptr->filter)); result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); } @@ -442,7 +444,7 @@ UniValue NSPV_mempoolresp_json(struct NSPV_mempoolresp *ptr) UniValue result(UniValue::VOBJ),array(UniValue::VARR); int32_t i; result.push_back(Pair("result","success")); for (i=0; inumtxids; i++) - array.push_back(Pair("txid",ptr->txids[i].GetHex().c_str())); + array.push_back(ptr->txids[i].GetHex().c_str()); result.push_back(Pair("txids",array)); result.push_back(Pair("address",ptr->coinaddr)); result.push_back(Pair("isCC",ptr->CCflag)); @@ -476,7 +478,7 @@ UniValue NSPV_ntzsproof_json(struct NSPV_ntzsproofresp *ptr) result.push_back(Pair("prevtxlen",(int64_t)ptr->prevtxlen)); result.push_back(Pair("nexttxid",ptr->nexttxid.GetHex())); result.push_back(Pair("nexttxidht",(int64_t)ptr->nexttxidht)); - result.push_back(Pair("nexttxlen",(int64_t)ptr->prevtxlen)); + result.push_back(Pair("nexttxlen",(int64_t)ptr->nexttxlen)); result.push_back(Pair("numhdrs",(int64_t)ptr->common.numhdrs)); result.push_back(Pair("headers",NSPV_headers_json(ptr->common.hdrs,ptr->common.numhdrs,ptr->common.prevht))); result.push_back(Pair("lastpeer",NSPV_lastpeer)); @@ -544,11 +546,11 @@ UniValue NSPV_login(char *wifstr) UniValue NSPV_getinfo_req(int32_t reqht) { - uint8_t msg[64]; int32_t i,iter,len = 0; struct NSPV_inforesp I; + uint8_t msg[512]; int32_t i,iter,len = 0; struct NSPV_inforesp I; NSPV_inforesp_purge(&NSPV_inforesult); msg[len++] = NSPV_INFO; len += iguana_rwnum(1,&msg[len],sizeof(reqht),&reqht); - for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_utxosresult.coinaddr) == 0 && CCflag == NSPV_utxosresult.CCflag && skipcount == NSPV_utxosresult.skipcount ) return(NSPV_utxosresp_json(&NSPV_utxosresult)); @@ -601,7 +603,8 @@ UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount) memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); - for (iter=0; iter<3; iter++); + len += iguana_rwnum(1,&msg[len],sizeof(filter),&filter); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i= NSPV_inforesult.height && strcmp(coinaddr,NSPV_txidsresult.coinaddr) == 0 && CCflag == NSPV_txidsresult.CCflag && skipcount == NSPV_txidsresult.skipcount ) return(NSPV_txidsresp_json(&NSPV_txidsresult)); if ( skipcount < 0 ) @@ -637,8 +640,9 @@ UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount) memcpy(&msg[len],coinaddr,slen), len += slen; msg[len++] = (CCflag != 0); len += iguana_rwnum(1,&msg[len],sizeof(skipcount),&skipcount); + len += iguana_rwnum(1,&msg[len],sizeof(filter),&filter); //fprintf(stderr,"skipcount.%d\n",skipcount); - for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_ADDRINDEX,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; iprevtxid.GetHex().c_str(),ptr->nexttxid.GetHex().c_str()); @@ -768,7 +775,7 @@ UniValue NSPV_txidhdrsproof(uint256 prevtxid,uint256 nexttxid) msg[len++] = NSPV_NTZSPROOF; len += iguana_rwbignum(1,&msg[len],sizeof(prevtxid),(uint8_t *)&prevtxid); len += iguana_rwbignum(1,&msg[len],sizeof(nexttxid),(uint8_t *)&nexttxid); - for (iter=0; iter<3; iter++); + for (iter=0; iter<3; iter++) if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i>1) != 0 ) { for (i=0; i proof; + struct NSPV_txproof *ptr; int32_t i,offset,retval; int64_t rewards = 0; uint32_t nLockTime; std::vector proof; + retval = skipvalidation != 0 ? 0 : -1; + //fprintf(stderr,"NSPV_gettx %s/v%d ht.%d\n",txid.GetHex().c_str(),vout,height); if ( (ptr= NSPV_txproof_find(txid)) == 0 ) { NSPV_txproof(vout,txid,height); ptr = &NSPV_txproofresult; } + hashblock=ptr->hashblock; + txheight=ptr->height; + currentheight=NSPV_inforesult.height; if ( ptr->txid != txid ) { fprintf(stderr,"txproof error %s != %s\n",ptr->txid.GetHex().c_str(),txid.GetHex().c_str()); @@ -78,7 +83,7 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int retval = -2001; else if ( skipvalidation == 0 && ptr->unspentvalue <= 0 ) retval = -2002; - else if ( ASSETCHAINS_SYMBOL[0] == 0 && extradata >= 0 && tiptime != 0 ) + else if ( ASSETCHAINS_SYMBOL[0] == 0 && tiptime != 0 ) { rewards = komodo_interestnew(height,tx.vout[vout].nValue,tx.nLockTime,tiptime); if ( rewards != extradata ) @@ -117,11 +122,12 @@ int32_t NSPV_gettransaction(int32_t skipvalidation,int32_t vout,uint256 txid,int { std::vector txids; uint256 proofroot; proofroot = BitcoinGetProofMerkleRoot(proof,txids); - if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot ) + if ( proofroot != NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot || txids[0] != txid ) { + fprintf(stderr,"txid.%s vs txids[0] %s\n",txid.GetHex().c_str(),txids[0].GetHex().c_str()); fprintf(stderr,"prooflen.%d proofroot.%s vs %s\n",(int32_t)proof.size(),proofroot.GetHex().c_str(),NSPV_ntzsproofresult.common.hdrs[offset].hashMerkleRoot.GetHex().c_str()); retval = -2003; - } + } else retval = 0; } } else retval = -2005; } else retval = -2004; @@ -233,6 +239,11 @@ int64_t NSPV_addinputs(struct NSPV_utxoresp *used,CMutableTransaction &mtx,int64 bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey,uint32_t nTime) { CTransaction txNewConst(mtx); SignatureData sigdata; CBasicKeyStore keystore; int64_t branchid = NSPV_BRANCHID; + if ( NSPV_logintime == 0 || time(NULL) > NSPV_logintime+NSPV_AUTOLOGOUT ) + { + fprintf(stderr,"need to be logged in to get myprivkey\n"); + return false; + } keystore.AddKey(NSPV_key); if ( nTime != 0 && nTime < KOMODO_SAPLING_ACTIVATION ) { @@ -242,7 +253,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C if ( ProduceSignature(TransactionSignatureCreator(&keystore,&txNewConst,vini,utxovalue,SIGHASH_ALL),scriptPubKey,sigdata,branchid) != 0 ) { UpdateTransaction(mtx,vini,sigdata); - //fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); + fprintf(stderr,"SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(true); } //else fprintf(stderr,"sigerr SIG_TXHASH %s vini.%d %.8f\n",SIG_TXHASH.GetHex().c_str(),vini,(double)utxovalue/COIN); return(false); @@ -250,7 +261,7 @@ bool NSPV_SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const C std::string NSPV_signtx(int64_t &rewardsum,int64_t &interestsum,UniValue &retcodes,CMutableTransaction &mtx,uint64_t txfee,CScript opret,struct NSPV_utxoresp used[]) { - CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation; + CTransaction vintx; std::string hex; uint256 hashBlock; int64_t interest=0,change,totaloutputs=0,totalinputs=0; int32_t i,utxovout,n,validation,txheight,currentheight; n = mtx.vout.size(); for (i=0; i 0 ) sleep(1); - validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,used[i].extradata,NSPV_tiptime,rewardsum); + validation = NSPV_gettransaction(0,utxovout,mtx.vin[i].prevout.hash,used[i].height,vintx,hashBlock,txheight,currentheight,used[i].extradata,NSPV_tiptime,rewardsum); retcodes.push_back(validation); if ( validation != -1 ) // most others are degraded security { @@ -321,12 +332,21 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a len >>= 1; data.resize(len); decode_hex(&data[0],len,destaddr); - scriptPubKey = CScript() << data << OP_CHECKCRYPTOCONDITION; + if ( data[len-1] == OP_CHECKCRYPTOCONDITION ) + { + data.resize(--len); + scriptPubKey = CScript() << data << OP_CHECKCRYPTOCONDITION; + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","only CC hex allowed for now")); + return(result); } } else { result.push_back(Pair("result","error")); - result.push_back(Pair("error","invalid destaddr")); + result.push_back(Pair("error","invalid destaddr/CCvout hex")); return(result); } } @@ -343,7 +363,7 @@ UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis) // what its a return(result); } if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) - NSPV_addressutxos(srcaddr,0,0); + NSPV_addressutxos(srcaddr,0,0,0); if ( NSPV_utxosresult.CCflag != 0 || strcmp(NSPV_utxosresult.coinaddr,srcaddr) != 0 || NSPV_utxosresult.nodeheight < NSPV_inforesult.height ) { result.push_back(Pair("result","error")); @@ -434,7 +454,7 @@ int64_t NSPV_AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( strcmp(ptr->U.coinaddr,coinaddr) != 0 ) { - NSPV_addressutxos(coinaddr,CCflag,0); + NSPV_addressutxos(coinaddr,CCflag,0,0); NSPV_utxosresp_purge(&ptr->U); NSPV_utxosresp_copy(&ptr->U,&NSPV_utxosresult); } @@ -494,13 +514,15 @@ void NSPV_txids2CCtxids(struct NSPV_txidsresp *ptr,std::vector > &outputs,char *coinaddr,bool ccflag) { - NSPV_addressutxos(coinaddr,ccflag,0); + int32_t filter = 0; + NSPV_addressutxos(coinaddr,ccflag,0,filter); NSPV_utxos2CCunspents(&NSPV_utxosresult,outputs); } void NSPV_CCtxids(std::vector > &txids,char *coinaddr,bool ccflag) { - NSPV_addresstxids(coinaddr,ccflag,0); + int32_t filter = 0; + NSPV_addresstxids(coinaddr,ccflag,0,filter); NSPV_txids2CCtxids(&NSPV_txidsresult,txids); } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 028bc4dc2..caa99bdcd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -73,7 +73,7 @@ int32_t getkmdseason(int32_t height) return(i+1); } return(0); -}; +} int32_t getacseason(uint32_t timestamp) { @@ -85,7 +85,7 @@ int32_t getacseason(uint32_t timestamp) return(i+1); } return(0); -}; +} int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index da293c242..4ab61b4eb 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1700,6 +1700,7 @@ void komodo_args(char *argv0) KOMODO_NSPV = GetArg("-nSPV",0); memset(ccenables,0,sizeof(ccenables)); memset(disablebits,0,sizeof(disablebits)); + memset(ccEnablesHeight,0,sizeof(ccEnablesHeight)); if ( GetBoolArg("-gen", false) != 0 ) { KOMODO_MININGTHREADS = GetArg("-genproclimit",-1); @@ -2296,10 +2297,18 @@ fprintf(stderr,"extralen.%d before disable bits\n",extralen); //printf("created (%s)\n",fname); } else printf("error creating (%s)\n",fname); #endif - if ( KOMODO_CCACTIVATE != 0 && ASSETCHAINS_CC < 2 ) + if ( ASSETCHAINS_CC < 2 ) { - ASSETCHAINS_CC = 2; - fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE); + if ( KOMODO_CCACTIVATE != 0 ) + { + ASSETCHAINS_CC = 2; + fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE); + } + else if ( ccEnablesHeight[0] != 0 ) + { + ASSETCHAINS_CC = 2; + fprintf(stderr,"smart utxo CC contract %d will activate at height.%d\n",(int32_t)ccEnablesHeight[0],(int32_t)ccEnablesHeight[1]); + } } } else diff --git a/src/main.cpp b/src/main.cpp index f3b714eaa..34b84058e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2229,14 +2229,14 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo memset(&hashBlock,0,sizeof(hashBlock)); if ( KOMODO_NSPV != 0 ) { - int64_t rewardsum = 0; int32_t i,retval,txheight = 0,vout = 0; + int64_t rewardsum = 0; int32_t i,retval,txheight,currentheight,height=0,vout = 0; for (i=0; iid); //if ( KOMODO_NSPV != 0 ) //if ( strCommand != "version" && strCommand != "verack" ) - // fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); + // fprintf(stderr, "recv: %s (%u bytes) peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)vRecv.size(), (int32_t)pfrom->GetId()); if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) { LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); @@ -7287,7 +7305,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, else if (pfrom->nVersion < chainparams.GetConsensus().vUpgrades[ CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion) { - LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion); + LogPrintf("peer=%d using obsolete version %i vs %d; disconnecting\n", pfrom->id, pfrom->nVersion,(int32_t)chainparams.GetConsensus().vUpgrades[ + CurrentEpoch(GetHeight(), chainparams.GetConsensus())].nProtocolVersion); pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, strprintf("Version must be %d or greater", chainparams.GetConsensus().vUpgrades[ diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 076e89a03..b42a08f62 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -754,6 +754,10 @@ UniValue selfimport(const UniValue& params, bool fHelp) // return(0); return -1; } + else if (source == "PEGSCC") + { + return -1; + } else if (source == "PUBKEY") { ImportProof proofNull; @@ -833,6 +837,10 @@ UniValue importdual(const UniValue& params, bool fHelp) // confirm via ASSETCHAINS_CODAPORT that burnTx/hash is a valid CODA burn // return(0); } + else if (source == "PEGSCC") + { + return -1; + } RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) { @@ -1054,18 +1062,6 @@ UniValue importgatewaymarkdone(const UniValue& params, bool fHelp) return(result); } -UniValue importgatewaypendingdeposits(const UniValue& params, bool fHelp) -{ - uint256 bindtxid; std::string coin; - if ( fHelp || params.size() != 2 ) - throw runtime_error("importgatewaypendingdeposits bindtxid coin\n"); - if ( ensure_CCrequirements(EVAL_IMPORTGATEWAY) < 0 ) - throw runtime_error(CC_REQUIREMENTS_MSG); - bindtxid = Parseuint256((char *)params[0].get_str().c_str()); - coin = params[1].get_str(); - return(ImportGatewayPendingDeposits(bindtxid,coin)); -} - UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp) { uint256 bindtxid; std::string coin; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index ebc1293e2..6baa8a67d 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -370,7 +370,6 @@ static const CRPCCommand vRPCCommands[] = { "crosschain", "importgatewaypartialsign", &importgatewaypartialsign, true }, { "crosschain", "importgatewaycompletesigning", &importgatewaycompletesigning, true }, { "crosschain", "importgatewaymarkdone", &importgatewaymarkdone, true }, - { "crosschain", "importgatewaypendingdeposits", &importgatewaypendingdeposits, true }, { "crosschain", "importgatewaypendingwithdraws", &importgatewaypendingwithdraws, true }, { "crosschain", "importgatewayprocessed", &importgatewayprocessed, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 0865307c9..6338989a5 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -461,7 +461,6 @@ extern UniValue importgatewaywithdraw(const UniValue& params, bool fHelp); extern UniValue importgatewaypartialsign(const UniValue& params, bool fHelp); extern UniValue importgatewaycompletesigning(const UniValue& params, bool fHelp); extern UniValue importgatewaymarkdone(const UniValue& params, bool fHelp); -extern UniValue importgatewaypendingdeposits(const UniValue& params, bool fHelp); extern UniValue importgatewaypendingwithdraws(const UniValue& params, bool fHelp); extern UniValue importgatewayprocessed(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 395612a3d..5fa7dee9d 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -972,11 +972,12 @@ UniValue z_exportviewingkey(const UniValue& params, bool fHelp) return EncodeViewingKey(vk); } +extern int32_t KOMODO_NSPV; UniValue NSPV_getinfo_req(int32_t reqht); UniValue NSPV_login(char *wifstr); UniValue NSPV_logout(); -UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount); -UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount); +UniValue NSPV_addresstxids(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter); +UniValue NSPV_addressutxos(char *coinaddr,int32_t CCflag,int32_t skipcount,int32_t filter); UniValue NSPV_mempooltxids(char *coinaddr,int32_t CCflag,uint8_t funcid,uint256 txid,int32_t vout); UniValue NSPV_broadcast(char *hex); UniValue NSPV_spend(char *srcaddr,char *destaddr,int64_t satoshis); @@ -992,6 +993,8 @@ UniValue nspv_getinfo(const UniValue& params, bool fHelp) int32_t reqht = 0; if ( fHelp || params.size() > 1 ) throw runtime_error("nspv_getinfo [hdrheight]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 1 ) reqht = atoi((char *)params[0].get_str().c_str()); return(NSPV_getinfo_req(reqht)); @@ -1001,6 +1004,8 @@ UniValue nspv_logout(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 0 ) throw runtime_error("nspv_logout\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_logout()); } @@ -1008,6 +1013,8 @@ UniValue nspv_login(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_login wif\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_login((char *)params[0].get_str().c_str())); } @@ -1016,10 +1023,12 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) int32_t skipcount = 0,CCflag = 0; if ( fHelp || params.size() > 3 ) throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addressutxos((char *)NSPV_address.c_str(),0,0)); + return(NSPV_addressutxos((char *)NSPV_address.c_str(),0,0,0)); else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); } if ( params.size() >= 1 ) @@ -1028,7 +1037,7 @@ UniValue nspv_listunspent(const UniValue& params, bool fHelp) CCflag = atoi((char *)params[1].get_str().c_str()); if ( params.size() == 3 ) skipcount = atoi((char *)params[2].get_str().c_str()); - return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag,skipcount)); + return(NSPV_addressutxos((char *)params[0].get_str().c_str(),CCflag,skipcount,0)); } else throw runtime_error("nspv_listunspent [address [isCC [skipcount]]]\n"); } @@ -1039,6 +1048,8 @@ UniValue nspv_mempool(const UniValue& params, bool fHelp) memset(&txid,0,sizeof(txid)); if ( fHelp || params.size() > 5 ) throw runtime_error("nspv_mempool func(0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool) address isCC [txid vout]]]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); funcid = atoi((char *)params[0].get_str().c_str()); coinaddr = (char *)params[1].get_str().c_str(); CCflag = atoi((char *)params[2].get_str().c_str()); @@ -1057,10 +1068,12 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) int32_t skipcount = 0,CCflag = 0; if ( fHelp || params.size() > 3 ) throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); if ( params.size() == 0 ) { if ( NSPV_address.size() != 0 ) - return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0)); + return(NSPV_addresstxids((char *)NSPV_address.c_str(),0,0,0)); else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); } if ( params.size() >= 1 ) @@ -1070,7 +1083,7 @@ UniValue nspv_listtransactions(const UniValue& params, bool fHelp) if ( params.size() == 3 ) skipcount = atoi((char *)params[2].get_str().c_str()); //fprintf(stderr,"call txids cc.%d skip.%d\n",CCflag,skipcount); - return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount)); + return(NSPV_addresstxids((char *)params[0].get_str().c_str(),CCflag,skipcount,0)); } else throw runtime_error("nspv_listtransactions [address [isCC [skipcount]]]\n"); } @@ -1080,6 +1093,8 @@ UniValue nspv_spentinfo(const UniValue& params, bool fHelp) uint256 txid; int32_t vout; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_spentinfo txid vout\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); vout = atoi((char *)params[1].get_str().c_str()); return(NSPV_spentinfo(txid,vout)); @@ -1090,6 +1105,8 @@ UniValue nspv_notarizations(const UniValue& params, bool fHelp) int32_t height; if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_notarizations height\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); height = atoi((char *)params[0].get_str().c_str()); return(NSPV_notarizations(height)); } @@ -1099,6 +1116,8 @@ UniValue nspv_hdrsproof(const UniValue& params, bool fHelp) int32_t prevheight,nextheight; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_hdrsproof prevheight nextheight\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); prevheight = atoi((char *)params[0].get_str().c_str()); nextheight = atoi((char *)params[1].get_str().c_str()); return(NSPV_hdrsproof(prevheight,nextheight)); @@ -1109,6 +1128,8 @@ UniValue nspv_txproof(const UniValue& params, bool fHelp) uint256 txid; int32_t height; if ( fHelp || params.size() != 2 ) throw runtime_error("nspv_txproof txid height\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); txid = Parseuint256((char *)params[0].get_str().c_str()); height = atoi((char *)params[1].get_str().c_str()); return(NSPV_txproof(0,txid,height)); @@ -1118,7 +1139,9 @@ UniValue nspv_spend(const UniValue& params, bool fHelp) { uint64_t satoshis; if ( fHelp || params.size() != 2 ) - throw runtime_error("nspv_spend destaddr amount\n"); + throw runtime_error("nspv_spend address amount\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\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; @@ -1132,5 +1155,7 @@ UniValue nspv_broadcast(const UniValue& params, bool fHelp) { if ( fHelp || params.size() != 1 ) throw runtime_error("nspv_broadcast hex\n"); + if ( KOMODO_NSPV == 0 ) + throw runtime_error("-nSPV=1 must be set to use nspv\n"); return(NSPV_broadcast((char *)params[0].get_str().c_str())); }