diff --git a/src/cc/customcc.cpp b/src/cc/customcc.cpp index 7edb95f79..961089de8 100644 --- a/src/cc/customcc.cpp +++ b/src/cc/customcc.cpp @@ -1,88 +1,15 @@ // Copyright (c) 2016-2024 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html -/* - simple stub custom cc - - Just update the functions in this file, then from ~/hush3/src/cc - - ../hush-cli -ac_name=CUSTOM stop - ./makecustom - ../hush-smart-chain -ac_name=CUSTOM -ac_cclib=custom -ac_cc=2 ... - - The above will rebuild hushd and get it running again - */ - -CScript custom_opret(uint8_t funcid,CPubKey pk) -{ - CScript opret; uint8_t evalcode = EVAL_CUSTOM; - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk); - return(opret); -} - -uint8_t custom_opretdecode(CPubKey &pk,CScript scriptPubKey) -{ - std::vector vopret; uint8_t e,f; - GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk) != 0 && e == EVAL_CUSTOM ) - { - return(f); - } - return(0); -} - -UniValue custom_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag) -{ - CTransaction tx; - if ( rawtx.size() > 0 ) - { - result.push_back(Pair("hex",rawtx)); - if ( DecodeHexTx(tx,rawtx) != 0 ) - { - if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) - RelayTransaction(tx); - result.push_back(Pair("txid",tx.GetHash().ToString())); - result.push_back(Pair("result","success")); - } else result.push_back(Pair("error","decode hex")); - } else result.push_back(Pair("error","couldnt finalize CCtx")); - return(result); -} UniValue custom_func0(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); - result.push_back(Pair("result","success")); - result.push_back(Pair("message","just an example of an information returning rpc")); return(result); } -// send yourself 1 coin to your CC address using normal utxo from your -pubkey - UniValue custom_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), hush_nextheight()); std::string rawtx; - UniValue result(UniValue::VOBJ); CPubKey mypk; int64_t amount = COIN; int32_t broadcastflag=0; - if ( txfee == 0 ) - txfee = CUSTOM_TXFEE; - mypk = pubkey2pk(Mypubkey()); - if ( AddNormalinputs2(mtx,COIN+txfee,64) >= COIN+txfee ) // add utxo to mtx - { - // make op_return payload as normal. - CScript opret = custom_opret('1',mypk); - std::vector> vData = std::vector>(); - if ( makeCCopret(opret, vData) ) - { - // make vout0 with op_return included as payload. - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,mypk,&vData)); - fprintf(stderr, "vout size2.%li\n", mtx.vout.size()); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript()); - return(custom_rawtxresult(result,rawtx,broadcastflag)); - } - } + UniValue result(UniValue::VOBJ); return(result); } - -bool custom_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) -{ - return false; -} diff --git a/src/cc/customcc.h b/src/cc/customcc.h index 4159d9608..7dfb78f84 100644 --- a/src/cc/customcc.h +++ b/src/cc/customcc.h @@ -1,20 +1,6 @@ // Copyright (c) 2016-2024 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html -/* - to create a custom libcc.so: - - 1. change "func0" and "func1" to method names that fit your custom cc. Of course, you can create more functions by adding another entry to RPC_FUNCS. there is not any practical limit to the number of methods. - - 2. For each method make sure there is a UniValue function declaration and CUSTOM_DISPATCH has an if statement checking for it that calls the custom_func - - 3. write the actual custom_func0, custom_func1 and custom_validate in customcc.cpp - - 4. ./makecustom, which builds cclib.cpp with -DBUILD_CUSTOMCC and puts the libcc.so in ~/hush3/src and rebuilds hushd - - 5. launch your chain with -ac_cclib=customcc -ac_cc=2 - - */ std::string MYCCLIBNAME = (char *)"customcc"; @@ -27,22 +13,3 @@ std::string MYCCLIBNAME = (char *)"customcc"; { (char *)MYCCNAME, (char *)"func0", (char *)"", 1, 1, '0', EVAL_CUSTOM }, \ { (char *)MYCCNAME, (char *)"func1", (char *)"", 0, 0, '1', EVAL_CUSTOM }, -bool custom_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx); -UniValue custom_func0(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); -UniValue custom_func1(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); - -#define CUSTOM_DISPATCH \ -if ( cp->evalcode == EVAL_CUSTOM ) \ -{ \ - if ( strcmp(method,"func0") == 0 ) \ - return(custom_func0(txfee,cp,params)); \ - else if ( strcmp(method,"func1") == 0 ) \ - return(custom_func1(txfee,cp,params)); \ - else \ - { \ - result.push_back(Pair("result","error")); \ - result.push_back(Pair("error","invalid customcc method")); \ - result.push_back(Pair("method",method)); \ - return(result); \ - } \ -}