Delete a lot of CC stuff #381

This commit is contained in:
Duke
2024-01-30 11:23:35 -05:00
parent bb8a3c57a4
commit 9e0ac062fa
13 changed files with 16 additions and 3825 deletions

View File

@@ -52,6 +52,8 @@
#include "hush_defs.h"
#include <string.h>
#include "rpchushwallet.h"
#include "cc/utils.h"
#include "cc/CCinclude.h"
using namespace std;
using namespace libzcash;
@@ -6092,101 +6094,8 @@ int32_t hush_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *pT
return(siglen);
}
#include "../cc/CCassets.h"
#include "../cc/CCfsm.h"
int32_t ensure_CCrequirements(uint8_t evalcode) {
CCerror = "";
if ( ASSETCHAINS_CCDISABLES[evalcode] != 0 || (evalcode == EVAL_MARMARA && ASSETCHAINS_MARMARA == 0) )
{
// check if a height activation has been set.
fprintf(stderr, "evalcode.%i activates at height. %i current height.%i\n", evalcode, mapHeightEvalActivate[evalcode], hush_currentheight());
if ( mapHeightEvalActivate[evalcode] == 0 || hush_currentheight() == 0 || mapHeightEvalActivate[evalcode] > hush_currentheight() )
{
fprintf(stderr,"evalcode %d disabled\n",evalcode);
return(-1);
}
}
if ( NOTARY_PUBKEY33[0] == 0 )
{
fprintf(stderr,"no -pubkey set\n");
return(-1);
} else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) {
fprintf(stderr,"no -addressindex\n");
return(-1);
} else if ( GetBoolArg("-spentindex", DEFAULT_SPENTINDEX) == 0 ) {
fprintf(stderr,"no -spentindex\n");
return(-1);
}
else return(0);
}
UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned char> &pubkey)
{
UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey mypk,pk;
pk = GetUnspendable(cp,0);
GetCCaddress(cp,destaddr,pk);
if ( strcmp(destaddr,cp->unspendableCCaddr) != 0 )
{
uint8_t priv[32];
Myprivkey(priv); // it is assumed the CC's normal address'es -pubkey was used
fprintf(stderr,"fix mismatched CCaddr %s -> %s\n",cp->unspendableCCaddr,destaddr);
strcpy(cp->unspendableCCaddr,destaddr);
memset(priv,0,32);
}
result.push_back(Pair("result", "success"));
sprintf(str,"%sCCAddress",name);
result.push_back(Pair(str,cp->unspendableCCaddr));
sprintf(str,"%sCCBalance",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(cp->unspendableCCaddr,1))));
sprintf(str,"%sNormalAddress",name);
result.push_back(Pair(str,cp->normaladdr));
sprintf(str,"%sNormalBalance",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(cp->normaladdr,0))));
if (strcmp(name,"Gateways")==0) result.push_back(Pair("GatewaysPubkey","03ea9c062b9652d8eff34879b504eda0717895d27597aaeb60347d65eed96ccb40"));
if ((strcmp(name,"Channels")==0 || strcmp(name,"Heir")==0) && pubkey.size() == 33)
{
sprintf(str,"%sCC1of2Address",name);
mypk = pubkey2pk(Mypubkey());
GetCCaddress1of2(cp,destaddr,mypk,pubkey2pk(pubkey));
result.push_back(Pair(str,destaddr));
if (GetTokensCCaddress1of2(cp,destaddr,mypk,pubkey2pk(pubkey))>0)
{
sprintf(str,"%sCC1of2TokensAddress",name);
result.push_back(Pair(str,destaddr));
}
}
else if (strcmp(name,"Tokens")!=0)
{
if (GetTokensCCaddress(cp,destaddr,pk)>0)
{
sprintf(str,"%sCCTokensAddress",name);
result.push_back(Pair(str,destaddr));
}
}
if ( pubkey.size() == 33 )
{
if ( GetCCaddress(cp,destaddr,pubkey2pk(pubkey)) != 0 )
{
sprintf(str,"PubkeyCCaddress(%s)",name);
result.push_back(Pair(str,destaddr));
sprintf(str,"PubkeyCCbalance(%s)",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(destaddr,0))));
}
}
if ( GetCCaddress(cp,destaddr,pubkey2pk(Mypubkey())) != 0 )
{
sprintf(str,"myCCAddress(%s)",name);
result.push_back(Pair(str,destaddr));
sprintf(str,"myCCbalance(%s)",name);
result.push_back(Pair(str,ValueFromAmount(CCaddress_balance(destaddr,1))));
}
if ( Getscriptaddress(destaddr,(CScript() << Mypubkey() << OP_CHECKSIG)) != 0 )
{
result.push_back(Pair("myaddress",destaddr));
result.push_back(Pair("mybalance",ValueFromAmount(CCaddress_balance(destaddr,0))));
}
return(result);
return -1;
}
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
@@ -6253,142 +6162,6 @@ UniValue setpubkey(const UniValue& params, bool fHelp, const CPubKey& mypk)
return result;
}
UniValue cclibaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey; uint8_t evalcode = EVAL_FIRSTUSER;
if ( fHelp || params.size() > 2 )
throw runtime_error("cclibaddress [evalcode] [pubkey]\n");
if ( params.size() >= 1 )
{
evalcode = atoi(params[0].get_str().c_str());
if ( evalcode < EVAL_FIRSTUSER || evalcode > EVAL_LASTUSER )
throw runtime_error("evalcode not between EVAL_FIRSTUSER and EVAL_LASTUSER\n");
if ( params.size() == 2 )
pubkey = ParseHex(params[1].get_str().c_str());
}
cp = CCinit(&C,evalcode);
if ( ensure_CCrequirements(cp->evalcode) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
if ( cp == 0 )
throw runtime_error("error creating *cp\n");
return(CCaddress(cp,(char *)"CClib",pubkey));
}
UniValue cclibinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; uint8_t evalcode = EVAL_FIRSTUSER;
if ( fHelp || params.size() > 0 )
throw runtime_error("cclibinfo\n");
if ( ensure_CCrequirements(0) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
cp = CCinit(&C,evalcode);
return(CClib_info(cp));
}
UniValue cclib(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; char *method,*jsonstr=0; uint8_t evalcode = EVAL_FIRSTUSER;
std::string vobjJsonSerialized;
if ( fHelp || params.size() > 3 )
throw runtime_error("cclib method [evalcode] [JSON params]\n");
if ( ASSETCHAINS_CCLIB.size() == 0 )
throw runtime_error("no -ac_cclib= specified\n");
if ( ensure_CCrequirements(0) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
method = (char *)params[0].get_str().c_str();
if ( params.size() >= 2 )
{
evalcode = atoi(params[1].get_str().c_str());
if ( evalcode < EVAL_FIRSTUSER || evalcode > EVAL_LASTUSER )
{
//printf("evalcode.%d vs (%d, %d)\n",evalcode,EVAL_FIRSTUSER,EVAL_LASTUSER);
throw runtime_error("evalcode not between EVAL_FIRSTUSER and EVAL_LASTUSER\n");
}
if ( params.size() == 3 )
{
if (params[2].getType() == UniValue::VOBJ) {
vobjJsonSerialized = params[2].write(0, 0);
jsonstr = (char *)vobjJsonSerialized.c_str();
}
else // VSTR assumed
jsonstr = (char *)params[2].get_str().c_str();
//fprintf(stderr,"params.(%s %s %s)\n",params[0].get_str().c_str(),params[1].get_str().c_str(),jsonstr);
}
}
cp = CCinit(&C,evalcode);
return(CClib(cp,method,jsonstr));
}
UniValue FSMaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_FSM);
if ( fHelp || params.size() > 1 )
throw runtime_error("FSMaddress [pubkey]\n");
if ( ensure_CCrequirements(cp->evalcode) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
if ( params.size() == 1 )
pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp,(char *)"FSM",pubkey));
}
UniValue assetsaddress(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
struct CCcontract_info *cp, C; std::vector<unsigned char> pubkey;
cp = CCinit(&C, EVAL_ASSETS);
if (fHelp || params.size() > 1)
throw runtime_error("assetsaddress [pubkey]\n");
if (ensure_CCrequirements(cp->evalcode) < 0)
throw runtime_error(CC_REQUIREMENTS_MSG);
if (params.size() == 1)
pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp, (char *)"Assets", pubkey));
}
UniValue FSMcreate(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
UniValue result(UniValue::VOBJ); std::string name,states,hex;
if ( fHelp || params.size() != 2 )
throw runtime_error("FSMcreate name states\n");
if ( ensure_CCrequirements(EVAL_FSM) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
const CKeyStore& keystore = *pwalletMain;
LOCK2(cs_main, pwalletMain->cs_wallet);
name = params[0].get_str();
states = params[1].get_str();
hex = FSMCreate(0,name,states);
if ( hex.size() > 0 )
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt create FSM transaction"));
return(result);
}
UniValue FSMlist(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 tokenid;
if ( fHelp || params.size() > 0 )
throw runtime_error("FSMlist\n");
if ( ensure_CCrequirements(EVAL_FSM) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
return(FSMList());
}
UniValue FSMinfo(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
uint256 FSMtxid;
if ( fHelp || params.size() != 1 )
throw runtime_error("FSMinfo fundingtxid\n");
if ( ensure_CCrequirements(EVAL_FSM) < 0 )
throw runtime_error(CC_REQUIREMENTS_MSG);
FSMtxid = Parseuint256((char *)params[0].get_str().c_str());
return(FSMInfo(FSMtxid));
}
UniValue getbalance64(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
set<CBitcoinAddress> setAddress; vector<COutput> vecOutputs;