From 0cbce3b0c8235f3d2f33e3861329a2fa0747c6dc Mon Sep 17 00:00:00 2001 From: Duke Date: Sat, 10 Feb 2024 23:16:34 -0500 Subject: [PATCH] Delete more CCs #381 --- src/cc/CCutilbits.cpp | 10 --- src/cc/CCutils.cpp | 156 +----------------------------------------- 2 files changed, 1 insertion(+), 165 deletions(-) diff --git a/src/cc/CCutilbits.cpp b/src/cc/CCutilbits.cpp index e1db0a1f9..d1ae17857 100644 --- a/src/cc/CCutilbits.cpp +++ b/src/cc/CCutilbits.cpp @@ -105,14 +105,4 @@ CPubKey pubkey2pk(std::vector vpubkey) void CCLogPrintStr(const char *category, int level, const std::string &str) { - if (level < 0) - level = 0; - if (level > CCLOG_MAXLEVEL) - level = CCLOG_MAXLEVEL; - for (int i = level; i <= CCLOG_MAXLEVEL; i++) - if (LogAcceptCategory((std::string(category) + std::string("-") + std::to_string(i)).c_str()) || // '-debug=cctokens-0', '-debug=cctokens-1',... - i == 0 && LogAcceptCategory(std::string(category).c_str())) { // also supporting '-debug=cctokens' for CCLOG_INFO - LogPrintStr(str); - break; - } } diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 74b11700c..58377e268 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -410,37 +410,6 @@ void CCclearvars(struct CCcontract_info *cp) cp->unspendableaddr2[0] = cp->unspendableaddr3[0] = 0; } -int64_t CCduration(int32_t &numblocks,uint256 txid) -{ - CTransaction tx; uint256 hashBlock; uint32_t txheight,txtime=0; char str[65]; CBlockIndex *pindex; int64_t duration = 0; - numblocks = 0; - if ( myGetTransaction(txid,tx,hashBlock) == 0 ) - { - //fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid)); - return(0); - } - else if ( hashBlock == zeroid ) - { - //fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid)); - return(0); - } - else if ( (pindex= hush_getblockindex(hashBlock)) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->GetHeight()) <= 0 ) - { - fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid)); - return(0); - } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->GetHeight() <= txheight ) - { - if ( pindex->nTime < txtime ) - fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->GetHeight()); - return(0); - } - numblocks = (pindex->GetHeight() - txheight); - duration = (pindex->nTime - txtime); - //fprintf(stderr,"duration %d (%u - %u) numblocks %d (%d - %d)\n",(int32_t)duration,(uint32_t)pindex->nTime,txtime,numblocks,pindex->GetHeight(),txheight); - return(duration); -} - int32_t NSPV_coinaddr_inmempool(char const *logcategory,char *coinaddr,uint8_t CCflag); int32_t myIs_coinaddr_inmempoolvout(char const *logcategory,char *coinaddr) @@ -494,19 +463,6 @@ int32_t myGet_mempool_txs(std::vector &txs,uint8_t evalcode,uint8_ return(i); } -int32_t CCCointxidExists(char const *logcategory,uint256 cointxid) -{ - char txidaddr[64]; std::string coin; int32_t numvouts; uint256 hashBlock; - std::vector > addressIndex; - CCtxidaddr(txidaddr,cointxid); - SetCCtxids(addressIndex,txidaddr,true); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) - { - return(-1); - } - return(myIs_coinaddr_inmempoolvout(logcategory,txidaddr)); -} - /* Get the block merkle root for a proof * IN: proofData * OUT: merkle root @@ -594,37 +550,6 @@ bool hush_txnotarizedconfirmed(uint256 txid) return (false); } -CPubKey check_signing_pubkey(CScript scriptSig) -{ - bool found = false; - CPubKey pubkey; - - auto findEval = [](CC *cond, struct CCVisitor _) { - bool r = false; - - if (cc_typeId(cond) == CC_Secp256k1) { - *(CPubKey*)_.context=buf2pk(cond->publicKey); - r = true; - } - // false for a match, true for continue - return r ? 0 : 1; - }; - - CC *cond = GetCryptoCondition(scriptSig); - - if (cond) { - CCVisitor visitor = { findEval, (uint8_t*)"", 0, &pubkey }; - bool out = !cc_visit(cond, visitor); - cc_free(cond); - - if (pubkey.IsValid()) { - return pubkey; - } - } - return CPubKey(); -} - - // returns total of normal inputs signed with this pubkey int64_t TotalPubkeyNormalInputs(const CTransaction &tx, const CPubKey &pubkey) { @@ -658,57 +583,11 @@ int64_t TotalPubkeyNormalInputs(const CTransaction &tx, const CPubKey &pubkey) int64_t TotalPubkeyCCInputs(const CTransaction &tx, const CPubKey &pubkey) { int64_t total = 0; - for (auto vin : tx.vin) { - if (IsCCInput(vin.scriptSig)) { - CPubKey vinPubkey = check_signing_pubkey(vin.scriptSig); - if (vinPubkey.IsValid()) { - if (vinPubkey == pubkey) { - CTransaction vintx; - uint256 hashBlock; - if (myGetTransaction(vin.prevout.hash, vintx, hashBlock)) { - total += vintx.vout[vin.prevout.n].nValue; - } - } - } - } - } return total; } bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { - CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; - height = HUSH_CONNECTING; - if ( HUSH_CONNECTING < 0 ) // always comes back with > 0 for final confirmation - return(true); - if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < HUSH_CCACTIVATE ) - return eval->Invalid("CC are disabled or not active yet"); - if ( (HUSH_CONNECTING & (1<<30)) != 0 ) - { - from_mempool = 1; - height &= ((1<<30) - 1); - } - if (cp->validate == NULL) - return eval->Invalid("validation not supported for eval code"); - - //fprintf(stderr,"HUSH_CONNECTING.%d mempool.%d vs CCactive.%d\n",height,from_mempool,HUSH_CCACTIVATE); - // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example - //txid = ctx.GetHash(); - //if ( txid == cp->prevtxid ) - // return(true); - //fprintf(stderr,"process CC %02x\n",cp->evalcode); - CCclearvars(cp); - if ( paramsNull.size() != 0 ) // Don't expect params - return eval->Invalid("Cannot have params"); - //else if ( ctx.vout.size() == 0 ) // spend can go to z-addresses - // return eval->Invalid("no-vouts"); - else if ( (*cp->validate)(cp,eval,ctx,nIn) != 0 ) - { - //fprintf(stderr,"done CC %02x\n",cp->evalcode); - //cp->prevtxid = txid; - return(true); - } - //fprintf(stderr,"invalid CC %02x\n",cp->evalcode); return(false); } @@ -718,38 +597,5 @@ bool CClib_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C bool CClib_Dispatch(const CC *cond,Eval *eval,std::vector paramsNull,const CTransaction &txTo,unsigned int nIn) { - uint8_t evalcode; int32_t height,from_mempool; struct CCcontract_info *cp; - if ( ASSETCHAINS_CCLIB != MYCCLIBNAME ) - { - fprintf(stderr,"-ac_cclib=%s vs myname %s\n",ASSETCHAINS_CCLIB.c_str(),MYCCLIBNAME.c_str()); - return eval->Invalid("-ac_cclib name mismatches myname"); - } - height = HUSH_CONNECTING; - if ( HUSH_CONNECTING < 0 ) // always comes back with > 0 for final confirmation - return(true); - if ( ASSETCHAINS_CC == 0 || (height & ~(1<<30)) < HUSH_CCACTIVATE ) - return eval->Invalid("CC are disabled or not active yet"); - if ( (HUSH_CONNECTING & (1<<30)) != 0 ) - { - from_mempool = 1; - height &= ((1<<30) - 1); - } - evalcode = cond->code[0]; - if ( evalcode >= EVAL_FIRSTUSER && evalcode <= EVAL_LASTUSER ) - { - cp = &CCinfos[(int32_t)evalcode]; - if ( cp->didinit == 0 ) - { - if ( CClib_initcp(cp,evalcode) == 0 ) - cp->didinit = 1; - else return eval->Invalid("unsupported CClib evalcode"); - } - CCclearvars(cp); - if ( paramsNull.size() != 0 ) // Don't expect params - return eval->Invalid("Cannot have params"); - else if ( CClib_validate(cp,height,eval,txTo,nIn) != 0 ) - return(true); - return(false); //eval->Invalid("error in CClib_validate"); - } - return eval->Invalid("cclib CC must have evalcode between 16 and 127"); + return false; }