From 4f1ae9a087c7a1da11dc33793dca7c8ffc6f04b4 Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 21 May 2021 17:05:01 -0500 Subject: [PATCH 1/3] move GetUnspendable() into CCcontract_info --- src/cc/CCassetsCore.cpp | 4 +- src/cc/CCassetstx.cpp | 18 ++--- src/cc/CCcontract.cpp | 33 +++++++- src/cc/CCcontract.h | 20 +++++ src/cc/CCinclude.h | 16 ---- src/cc/CCtokens.cpp | 54 ++++++------- src/cc/CCtokens.h | 35 ++++----- src/cc/CCtokenutils.cpp | 144 ++++++++++++++++++----------------- src/cc/CCtx.cpp | 4 +- src/cc/CCutils.cpp | 11 +-- src/cc/assets.cpp | 2 +- src/cc/auction.cpp | 6 +- src/cc/cclib.cpp | 4 +- src/cc/dice.cpp | 8 +- src/cc/dilithium.cpp | 10 +-- src/cc/faucet.cpp | 6 +- src/cc/fsm.cpp | 4 +- src/cc/games/prices.cpp | 4 +- src/cc/gamescc.cpp | 28 +++---- src/cc/gateways.cpp | 24 +++--- src/cc/heir.cpp | 4 +- src/cc/importgateway.cpp | 16 ++-- src/cc/lotto.cpp | 8 +- src/cc/marmara.cpp | 20 ++--- src/cc/musig.cpp | 2 +- src/cc/oracles.cpp | 6 +- src/cc/payments.cpp | 20 ++--- src/cc/pegs.cpp | 30 ++++---- src/cc/prices.cpp | 18 ++--- src/cc/rewards.cpp | 10 +-- src/cc/rogue_rpc.cpp | 26 +++---- src/cc/sudoku.cpp | 4 +- src/komodo_bitcoind.h | 2 +- src/rpc/crosschain.cpp | 2 +- src/rpc/testtransactions.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 +- 36 files changed, 321 insertions(+), 290 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index aa44c17b4dd..5110b843d35 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -437,7 +437,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *origCCadd // if fillSell or cancelSell --> should spend tokens from dual-eval token-assets unspendable addr else if( (funcid == 'S' || funcid == 'x') && (Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || - !GetTokensCCaddress(cp, unspendableAddr, GetUnspendable(cp, NULL)) || + !GetTokensCCaddress(cp, unspendableAddr, cp->GetUnspendable()) || strcmp(destaddr, unspendableAddr) != 0)) { fprintf(stderr,"AssetValidateCCvin() cc addr %s is not dual token-evalcode=0x%02x asset unspendable addr %s\n", destaddr, (int)cp->evalcode, unspendableAddr); @@ -446,7 +446,7 @@ int64_t AssetValidateCCvin(struct CCcontract_info *cp,Eval* eval,char *origCCadd // if fillBuy or cancelBuy --> should spend coins from asset unspendable addr else if ((funcid == 'B' || funcid == 'o') && (Getscriptaddress(destaddr, vinTx.vout[tx.vin[vini].prevout.n].scriptPubKey) == 0 || - !GetCCaddress(cp, unspendableAddr, GetUnspendable(cp, NULL)) || + !GetCCaddress(cp, unspendableAddr, cp->GetUnspendable()) || strcmp(destaddr, unspendableAddr) != 0)) { fprintf(stderr, "AssetValidateCCvin() cc addr %s is not evalcode=0x%02x asset unspendable addr %s\n", destaddr, (int)cp->evalcode, unspendableAddr); diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 0b2d023ffe6..00d01d4c059 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -110,7 +110,7 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) std::vector > unspentOutputsTokens, unspentOutputsDualEvalTokens, unspentOutputsCoins; char assetsUnspendableAddr[64]; - GetCCaddress(&assetsC, assetsUnspendableAddr, GetUnspendable(&assetsC, NULL)); + GetCCaddress(&assetsC, assetsUnspendableAddr, assetsC.GetUnspendable()); SetCCunspents(unspentOutputsCoins, assetsUnspendableAddr,true); char assetsTokensUnspendableAddr[64]; @@ -120,7 +120,7 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) if (vopretNonfungible.size() > 0) assetsC.additionalTokensEvalcode2 = vopretNonfungible.begin()[0]; } - GetTokensCCaddress(&assetsC, assetsTokensUnspendableAddr, GetUnspendable(&assetsC, NULL)); + GetTokensCCaddress(&assetsC, assetsTokensUnspendableAddr, assetsC.GetUnspendable()); SetCCunspents(unspentOutputsTokens, assetsTokensUnspendableAddr,true); // tokenbids: @@ -140,7 +140,7 @@ UniValue AssetOrders(uint256 refassetid, CPubKey pk, uint8_t additionalEvalCode) // try also dual eval tokenasks (and we do not need bids): assetsC.additionalTokensEvalcode2 = additionalEvalCode; - GetTokensCCaddress(&assetsC, assetsDualEvalTokensUnspendableAddr, GetUnspendable(&assetsC, NULL)); + GetTokensCCaddress(&assetsC, assetsDualEvalTokensUnspendableAddr, assetsC.GetUnspendable()); SetCCunspents(unspentOutputsDualEvalTokens, assetsDualEvalTokensUnspendableAddr,true); for (std::vector >::const_iterator itDualEvalTokens = unspentOutputsDualEvalTokens.begin(); @@ -195,7 +195,7 @@ std::string CreateBuyOffer(int64_t txfee, int64_t bidamount, uint256 assetid, in return (""); } - CPubKey unspendableAssetsPubkey = GetUnspendable(&C, 0); + CPubKey unspendableAssetsPubkey = C.GetUnspendable(); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount, unspendableAssetsPubkey)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); std::vector voutTokenPubkeys; // should be empty - no token vouts @@ -249,7 +249,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p // set its evalcode assetsC.additionalTokensEvalcode2 = vopretNonfungible.begin()[0]; - CPubKey unspendableAssetsPubkey = GetUnspendable(&assetsC, NULL); + CPubKey unspendableAssetsPubkey = assetsC.GetUnspendable(); mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, assetsC.additionalTokensEvalcode2, askamount, unspendableAssetsPubkey)); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, txfee, mypk)); //marker (seems, it is not for tokenorders) if (inputs > askamount) @@ -405,7 +405,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) uint8_t unspendableAssetsPrivkey[32]; char unspendableAssetsAddr[64]; // init assets 'unspendable' privkey and pubkey - CPubKey unspendableAssetsPk = GetUnspendable(&assetsC, unspendableAssetsPrivkey); + CPubKey unspendableAssetsPk = assetsC.GetUnspendable(unspendableAssetsPrivkey); GetCCaddress(&assetsC, unspendableAssetsAddr, unspendableAssetsPk); // add additional eval-tokens unspendable assets privkey: @@ -473,7 +473,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f CCchange = (inputs - fillamount); uint8_t unspendableAssetsPrivkey[32]; - CPubKey unspendableAssetsPk = GetUnspendable(&assetsC, unspendableAssetsPrivkey); + CPubKey unspendableAssetsPk = assetsC.GetUnspendable(unspendableAssetsPrivkey); mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS, bidamount - paid_amount, unspendableAssetsPk)); // vout0 coins remainder mtx.vout.push_back(CTxOut(paid_amount,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); // vout1 coins to normal @@ -579,7 +579,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a // vout.0 tokens remainder to unspendable cc addr: mtx.vout.push_back(MakeTokensCC1vout(EVAL_ASSETS, additionalTokensEvalcode2, orig_assetoshis - received_assetoshis, - GetUnspendable(&assetsC, NULL))); + assetsC.GetUnspendable())); //vout.1 purchased tokens to self token single-eval or dual-eval token+nonfungible cc addr: mtx.vout.push_back(MakeTokensCC1vout(additionalTokensEvalcode2 == 0 ? EVAL_TOKENS : additionalTokensEvalcode2, received_assetoshis, mypk)); @@ -604,7 +604,7 @@ std::string FillSell(int64_t txfee, uint256 assetid, uint256 assetid2, uint256 a uint8_t unspendableAssetsPrivkey[32]; char unspendableAssetsAddr[64]; // init assets 'unspendable' privkey and pubkey - CPubKey unspendableAssetsPk = GetUnspendable(&assetsC, unspendableAssetsPrivkey); + CPubKey unspendableAssetsPk = assetsC.GetUnspendable(unspendableAssetsPrivkey); GetCCaddress(&assetsC, unspendableAssetsAddr, unspendableAssetsPk); // add additional eval-tokens unspendable assets privkey: diff --git a/src/cc/CCcontract.cpp b/src/cc/CCcontract.cpp index 44bee3896a2..c10efe7a1b4 100644 --- a/src/cc/CCcontract.cpp +++ b/src/cc/CCcontract.cpp @@ -1,6 +1,25 @@ #include "eval.h" #include "CCutils.h" // GetCryptoCondition() -#include "CCcontract.h" +#include "CCinclude.h" // pubkey2pk +#include "utilstrencodings.h" // ParseHex + +/**** + * Constructor that sets the most common values + * @param evalcode the type of contract + * @param unspendable the unspendable CC address + * @param normalAddr the normal address + * @param hex the hex string + * @param priv the binary private key + */ +CCcontract_info::CCcontract_info(const uint8_t evalcode, const char *unspendable, const char *normalAddr, const char *hex, const uint8_t *priv) + : CCcontract_info() +{ + this->evalcode = evalcode; + strcpy(unspendableCCaddr, unspendable); + strcpy(normaladdr, normalAddr); + strcpy(CChexstr, hex); + memcpy(CCpriv, priv,32); +} /// checks if the value of evalcode in cp object is present in the scriptSig parameter, /// that is, the vin for this scriptSig will be validated by the cc contract (Antara module) defined by the eval code in this CCcontract_info object @@ -41,3 +60,15 @@ bool CCcontract_info::validate(Eval* eval, const CTransaction &tx, uint32_t nIn) throw std::logic_error("validation not supported for eval code"); return false; // just to keep the compiler quiet } + +/*** + * Get an unspendable public key + * @param unspendablepriv filled with the private key + * @param returns the public key + */ +CPubKey CCcontract_info::GetUnspendable(uint8_t *unspendablepriv) +{ + if ( unspendablepriv != 0 ) + memcpy(unspendablepriv,CCpriv,32); + return(pubkey2pk(ParseHex(CChexstr))); +} \ No newline at end of file diff --git a/src/cc/CCcontract.h b/src/cc/CCcontract.h index dc900a63d0e..d0e06a7bd34 100644 --- a/src/cc/CCcontract.h +++ b/src/cc/CCcontract.h @@ -7,7 +7,27 @@ /// CC contract (Antara module) info structure that contains data used for signing and validation of cc contract transactions struct CCcontract_info { + /*** + * Default ctor, sets everything to 0 + */ CCcontract_info() { memset(this, 0, sizeof(CCcontract_info)); } + /**** + * Constructor that sets the most common values + * @param evalcode the type of contract + * @param unspendable the unspendable CC address + * @param normalAddr the normal address + * @param hex the hex string + * @param priv the 32 byte binary private key + */ + CCcontract_info(const uint8_t evalcode, const char *unspendable, const char *normalAddr, const char *hex, const uint8_t *priv); + + /*** + * Get an unspendable public key + * @param unspendablepriv filled with the private key + * @param returns the public key + */ + CPubKey GetUnspendable(uint8_t *unspendablepriv = nullptr); + virtual ~CCcontract_info() {} uint8_t evalcode; //!< cc contract eval code, set by ctor uint8_t additionalTokensEvalcode2 = 0; //!< additional eval code for spending from three-eval-code vouts with EVAL_TOKENS, evalcode, additionalTokensEvalcode2 diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2dd750fef9d..3bc57d83570 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -391,22 +391,6 @@ void GetNonfungibleData(uint256 tokenid, vscript_t &vopretNonfungible); /// @private bool ExtractTokensCCVinPubkeys(const CTransaction &tx, std::vector &vinPubkeys); -// CCcustom - -/// Returns global pubkey for the evalcode and sets private key for the global pubkey -/// @param cp CCcontract_info structure initialized for a evalcode -/// @param[out] unspendablepriv if not null then in this parameter private key is returned. Must have at least 32 byte size -/// @returns global contract pubkey.\n -/// Example: -/// \code -/// struct CCcontract_info *cp, C; -/// uint8_t ccAssetsPriv[32] -/// cp = CCinit(&C, EVAL_ASSETS); -/// CPubKey ccAssetsPk = GetUnspendable(cp, ccAssetsPriv); -/// \endcode -/// Now ccAssetsPk has Antara 'Assets' module global pubkey and ccAssetsPriv has its publicly available private key -CPubKey GetUnspendable(CCcontract_info *cp,uint8_t *unspendablepriv); - // CCutils /// finds normal address for private key diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index a26b2524d7c..0f3e66e26a4 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -41,40 +41,43 @@ ------------------------------ */ -// tx validation +/***** + * Validate a transaction + * @param eval holds results + * @param tx the transaction to validate + * @param nIn not used + * @returns true on success + */ bool CCTokensContract_info::validate(Eval* eval, const CTransaction &tx, uint32_t nIn) { - static uint256 zero; - CTxDestination address; CTransaction vinTx, createTx; uint256 hashBlock, tokenid, tokenid2; - int32_t i, starti, numvins, numvouts, preventCCvins, preventCCvouts; - int64_t remaining_price, nValue, tokenoshis, outputs, inputs, tmpprice, totalunits, ignore; - std::vector> oprets; - vscript_t /*vopretExtra,*/ tmporigpubkey, ignorepubkey; - uint8_t funcid, evalCodeInOpret; - char destaddr[64], origaddr[64], CCaddr[64]; - std::vector voutTokenPubkeys, vinTokenPubkeys; - if (strcmp(ASSETCHAINS_SYMBOL, "ROGUE") == 0 && chainActive.Height() <= 12500) return true; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - outputs = inputs = 0; - preventCCvins = preventCCvouts = -1; - // check boundaries: + int32_t numvouts = tx.vout.size(); if (numvouts < 1) return eval->Invalid("no vouts"); + int32_t numvins = tx.vin.size(); + int64_t outputs = 0; + int64_t inputs = 0; + int32_t preventCCvins = -1; + int32_t preventCCvouts = -1; + + uint256 tokenid; + std::vector> oprets; + uint8_t funcid; + uint8_t evalCodeInOpret; + std::vector voutTokenPubkeys; if ((funcid = DecodeTokenOpRet(tx.vout[numvouts - 1].scriptPubKey, evalCodeInOpret, tokenid, voutTokenPubkeys, oprets)) == 0) return eval->Invalid("TokenValidate: invalid opreturn payload"); LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "TokensValidate funcId=" << (char)(funcid?funcid:' ') << " evalcode=" << std::hex << (int)evalcode << std::endl); + CTransaction createTx; + uint256 hashBlock; if (eval->GetTxUnconfirmed(tokenid, createTx, hashBlock) == 0) return eval->Invalid("cant find token create txid"); - //else if (IsCCInput(tx.vin[0].scriptSig) != 0) - // return eval->Invalid("illegal token vin0"); // <-- this validation was removed because some token tx might not have normal vins else if (funcid != 'c') { if (tokenid == zeroid) @@ -87,8 +90,9 @@ bool CCTokensContract_info::validate(Eval* eval, const CTransaction &tx, uint32_ } } + std::vector vinTokenPubkeys; // validate spending from token cc addr: allowed only for burned non-fungible tokens: - if (ExtractTokensCCVinPubkeys(tx, vinTokenPubkeys) && std::find(vinTokenPubkeys.begin(), vinTokenPubkeys.end(), GetUnspendable(this, NULL)) != vinTokenPubkeys.end()) { + if (ExtractTokensCCVinPubkeys(tx, vinTokenPubkeys) && std::find(vinTokenPubkeys.begin(), vinTokenPubkeys.end(), GetUnspendable()) != vinTokenPubkeys.end()) { // validate spending from token unspendable cc addr: int64_t burnedAmount = HasBurnedTokensvouts(this, eval, tx, tokenid); if (burnedAmount > 0) { @@ -239,7 +243,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, uint256 tokenid) { void FilterOutTokensUnspendablePk(const std::vector &sourcePubkeys, std::vector &destPubkeys) { CCTokensContract_info tokensC; - CPubKey tokensUnspendablePk = GetUnspendable(&tokensC, NULL); + CPubKey tokensUnspendablePk = tokensC.GetUnspendable(); destPubkeys.clear(); for (auto pk : sourcePubkeys) @@ -395,13 +399,13 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys /*<--not used, always true //special check for tx when spending from 1of2 CC address and one of pubkeys is global CC pubkey std::shared_ptr cpEvalCode1 = CCinit(evalCode1); - CPubKey pk=GetUnspendable(cpEvalCode1.get(),0); + CPubKey pk = cpEvalCode1->GetUnspendable(); testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval1 pegscc cc1of2 pk[0] globalccpk")) ); if (voutPubkeys.size() == 2) testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode1, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval1 pegscc cc1of2 pk[1] globalccpk")) ); if (evalCode2!=0) { std::shared_ptr cpEvalCode2 = CCinit(evalCode2); - CPubKey pk=GetUnspendable(cpEvalCode2.get(),0); + CPubKey pk= cpEvalCode2->GetUnspendable(); testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[0], pk), std::string("dual-eval2 pegscc cc1of2 pk[0] globalccpk")) ); if (voutPubkeys.size() == 2) testVouts.push_back( std::make_pair(MakeTokensCC1of2vout(evalCode2, tx.vout[v].nValue, voutPubkeys[1], pk), std::string("dual-eval2 pegscc cc1of2 pk[1] globalccpk")) ); } @@ -497,7 +501,7 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys /*<--not used, always true bool IsTokenMarkerVout(CTxOut vout) { CCTokensContract_info tokensC; - return vout == MakeCC1vout(EVAL_TOKENS, vout.nValue, GetUnspendable(&tokensC, NULL)); + return vout == MakeCC1vout(EVAL_TOKENS, vout.nValue, tokensC.GetUnspendable()); } // compares cc inputs vs cc outputs (to prevent feeding vouts from normal inputs) @@ -829,10 +833,8 @@ std::string CreateToken(int64_t txfee, int64_t tokensupply, std::string name, st // NOTE: we should prevent spending fake-tokens from this marker in IsTokenvout(): CCTokensContract_info C; - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(&C, NULL))); // new marker to token cc addr, burnable and validated, vout pos now changed to 0 (from 1) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, C.GetUnspendable())); // new marker to token cc addr, burnable and validated, vout pos now changed to 0 (from 1) mtx.vout.push_back(MakeTokensCC1vout(destEvalCode, tokensupply, mypk)); - //mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); // old marker (non-burnable because spending could not be validated) - //mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(cp, NULL))); // ...moved to vout=0 for matching with rogue-game token return(FinalizeCCTx(0, &C, mtx, mypk, txfee, EncodeTokenCreateOpRet('c', Mypubkey(), name, description, nonfungibleData))); } diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index ca8f476fc3e..781ca4b55f6 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -12,21 +12,10 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ - - -/* - CCassetstx has the functions that create the EVAL_ASSETS transactions. It is expected that rpc calls would call these functions. For EVAL_ASSETS, the rpc functions are in rpcwallet.cpp - - CCassetsCore has functions that are used in two contexts, both during rpc transaction create time and also during the blockchain validation. Using the identical functions is a good way to prevent them from being mismatched. The must match or the transaction will get rejected. - */ - #pragma once #include "CCinclude.h" -#include "CCcontract.h" -// CCcustom -bool TokensValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t &inputs, int64_t &outputs, Eval* eval, const CTransaction &tx, uint256 tokenid); std::string CreateToken(int64_t txfee, int64_t assetsupply, std::string name, std::string description, std::vector nonfungibleData); std::string TokenTransfer(int64_t txfee, uint256 assetid, std::vector destpubkey, int64_t total); @@ -40,16 +29,20 @@ UniValue TokenList(); struct CCTokensContract_info : public CCcontract_info { - CCTokensContract_info() : CCcontract_info() - { - evalcode = EVAL_TOKENS; - strcpy(unspendableCCaddr, "RAMvUfoyURBRxAdVeTMHxn3giJZCFWeha2"); - strcpy(normaladdr, "RCNgAngYAdrfzujYyPgfbjCGNVQZzCgTad"); - strcpy(CChexstr, "03e6191c70c9c9a28f9fd87089b9488d0e6c02fb629df64979c9cdb6b2b4a68d95"); - uint8_t TokensCCpriv[32] = { 0x1d, 0x0d, 0x0d, 0xce, 0x2d, 0xd2, 0xe1, 0x9d, 0xf5, + CCTokensContract_info() : CCcontract_info(EVAL_TOKENS, + "RAMvUfoyURBRxAdVeTMHxn3giJZCFWeha2", + "RCNgAngYAdrfzujYyPgfbjCGNVQZzCgTad", + "03e6191c70c9c9a28f9fd87089b9488d0e6c02fb629df64979c9cdb6b2b4a68d95", + (const uint8_t[]){ 0x1d, 0x0d, 0x0d, 0xce, 0x2d, 0xd2, 0xe1, 0x9d, 0xf5, 0xb6, 0x26, 0xd5, 0xad, 0xa0, 0xf0, 0x0a, 0xdd, 0x7a, 0x72, 0x7d, 0x17, 0x35, - 0xb5, 0xe3, 0x2c, 0x6c, 0xa9, 0xa2, 0x03, 0x16, 0x4b, 0xcf }; - memcpy(CCpriv, TokensCCpriv,32); - } + 0xb5, 0xe3, 0x2c, 0x6c, 0xa9, 0xa2, 0x03, 0x16, 0x4b, 0xcf }) + { } + /***** + * Validate a transaction + * @param eval holds results + * @param tx the transaction to validate + * @param nIn not used + * @returns true on success + */ virtual bool validate(Eval* eval, const CTransaction &tx, uint32_t nIn) override; }; diff --git a/src/cc/CCtokenutils.cpp b/src/cc/CCtokenutils.cpp index 73209bcb5c9..75be5f1db65 100644 --- a/src/cc/CCtokenutils.cpp +++ b/src/cc/CCtokenutils.cpp @@ -1,5 +1,5 @@ /****************************************************************************** -* Copyright © 2014-2019 The SuperNET Developers. * +* Copyright � 2014-2019 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * @@ -178,19 +178,13 @@ uint8_t DecodeTokenCreateOpRet(const CScript &scriptPubKey, std::vector // decode token opret: // for 't' returns all data from opret, vopretExtra contains other contract's data (currently only assets'). // for 'c' returns only funcid. NOTE: nonfungible data is not returned -uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, uint256 &tokenid, std::vector &voutPubkeys, std::vector> &oprets) +uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, uint256 &tokenid, + std::vector &voutPubkeys, std::vector> &oprets) { - vscript_t vopret, vblob, dummyPubkey, vnonfungibleDummy; - uint8_t funcId = 0, *script, dummyEvalCode, dummyFuncId, ccType, opretId = 0; - std::string dummyName; std::string dummyDescription; - uint256 dummySrcTokenId; - CPubKey voutPubkey1, voutPubkey2; - - vscript_t voldstyledata; - bool foundOldstyle = false; - + vscript_t vopret; GetOpReturnData(scriptPubKey, vopret); - script = (uint8_t *)vopret.data(); + + uint8_t *script = (uint8_t *)vopret.data(); tokenid = zeroid; oprets.clear(); @@ -198,73 +192,87 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, ui { evalCodeTokens = script[0]; if (evalCodeTokens != EVAL_TOKENS) { - LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() incorrect evalcode in tokens opret" << std::endl); + LOGSTREAM((char *)"cctokens", CCLOG_INFO, + stream << "DecodeTokenOpRet() incorrect evalcode in tokens opret" << std::endl); return (uint8_t)0; } - funcId = script[1]; - LOGSTREAM((char *)"cctokens", CCLOG_DEBUG2, stream << "DecodeTokenOpRet() decoded funcId=" << (char)(funcId ? funcId : ' ') << std::endl); + uint8_t funcId = script[1]; + LOGSTREAM((char *)"cctokens", CCLOG_DEBUG2, stream << "DecodeTokenOpRet() decoded funcId=" + << (char)(funcId ? funcId : ' ') << std::endl); switch (funcId) { case 'c': - return DecodeTokenCreateOpRet(scriptPubKey, dummyPubkey, dummyName, dummyDescription, oprets); - + { + vscript_t dummyPubkey; + std::string dummyName; + std::string dummyDescription; + return DecodeTokenCreateOpRet(scriptPubKey, dummyPubkey, dummyName, dummyDescription, oprets); + } case 't': - - // compatibility with old-style rogue or assets data (with no opretid): - // try to unmarshal old-style rogue or assets data: - foundOldstyle = E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> tokenid; ss >> ccType; - if (ccType >= 1) ss >> voutPubkey1; - if (ccType == 2) ss >> voutPubkey2; - if (!ss.eof()) { - ss >> voldstyledata; - }) && voldstyledata.size() >= 2 && - (voldstyledata.begin()[0] == 0x11 /*EVAL_ROGUE*/ && IS_CHARINSTR(voldstyledata.begin()[1], "RHQKG") || - voldstyledata.begin()[0] == EVAL_ASSETS && IS_CHARINSTR(voldstyledata.begin()[1], "sbSBxo")) ; - - if (foundOldstyle || // fix for compatibility with old style data (no opretid) - E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> tokenid; ss >> ccType; - if (ccType >= 1) ss >> voutPubkey1; - if (ccType == 2) ss >> voutPubkey2; - while (!ss.eof()) { - ss >> opretId; - if (!ss.eof()) { - ss >> vblob; - oprets.push_back(std::make_pair(opretId, vblob)); - } - })) { - if (!(ccType >= 0 && ccType <= 2)) { //incorrect ccType - LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() incorrect ccType=" << (int)ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl); - return (uint8_t)0; - } - - // add verification pubkeys: - voutPubkeys.clear(); - if (voutPubkey1.IsValid()) - voutPubkeys.push_back(voutPubkey1); - if (voutPubkey2.IsValid()) - voutPubkeys.push_back(voutPubkey2); - - tokenid = revuint256(tokenid); - - if (foundOldstyle) { //patch for old-style opret data with no opretid - LOGSTREAM((char *)"cctokens", CCLOG_DEBUG1, stream << "DecodeTokenOpRet() found old-style rogue/asset data, evalcode=" << (int)voldstyledata.begin()[0] << " funcid=" << (char)voldstyledata.begin()[1] << " for tokenid=" << revuint256(tokenid).GetHex() << std::endl); - uint8_t opretIdRestored; - if (voldstyledata.begin()[0] == 0x11 /*EVAL_ROGUE*/) - opretIdRestored = OPRETID_ROGUEGAMEDATA; - else // EVAL_ASSETS - opretIdRestored = OPRETID_ASSETSDATA; - - oprets.push_back(std::make_pair(opretIdRestored, voldstyledata)); + vscript_t voldstyledata; + vscript_t vblob; + uint8_t dummyEvalCode; + uint8_t dummyFuncId; + uint8_t ccType; + uint8_t opretId = 0; + CPubKey voutPubkey1; + CPubKey voutPubkey2; + // compatibility with old-style rogue or assets data (with no opretid): + // try to unmarshal old-style rogue or assets data: + bool foundOldstyle = E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> tokenid; ss >> ccType; + if (ccType >= 1) ss >> voutPubkey1; + if (ccType == 2) ss >> voutPubkey2; + if (!ss.eof()) { + ss >> voldstyledata; + }) && voldstyledata.size() >= 2 && + (voldstyledata.begin()[0] == 0x11 /*EVAL_ROGUE*/ && IS_CHARINSTR(voldstyledata.begin()[1], "RHQKG") || + voldstyledata.begin()[0] == EVAL_ASSETS && IS_CHARINSTR(voldstyledata.begin()[1], "sbSBxo")) ; + + if (foundOldstyle || // fix for compatibility with old style data (no opretid) + E_UNMARSHAL(vopret, ss >> dummyEvalCode; ss >> dummyFuncId; ss >> tokenid; ss >> ccType; + if (ccType >= 1) ss >> voutPubkey1; + if (ccType == 2) ss >> voutPubkey2; + while (!ss.eof()) { + ss >> opretId; + if (!ss.eof()) { + ss >> vblob; + oprets.push_back(std::make_pair(opretId, vblob)); + } + })) + { + if (!(ccType >= 0 && ccType <= 2)) { //incorrect ccType + LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() incorrect ccType=" << (int)ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl); + return (uint8_t)0; + } + + // add verification pubkeys: + voutPubkeys.clear(); + if (voutPubkey1.IsValid()) + voutPubkeys.push_back(voutPubkey1); + if (voutPubkey2.IsValid()) + voutPubkeys.push_back(voutPubkey2); + + tokenid = revuint256(tokenid); + + if (foundOldstyle) { //patch for old-style opret data with no opretid + LOGSTREAM((char *)"cctokens", CCLOG_DEBUG1, stream << "DecodeTokenOpRet() found old-style rogue/asset data, evalcode=" << (int)voldstyledata.begin()[0] << " funcid=" << (char)voldstyledata.begin()[1] << " for tokenid=" << revuint256(tokenid).GetHex() << std::endl); + uint8_t opretIdRestored; + if (voldstyledata.begin()[0] == 0x11 /*EVAL_ROGUE*/) + opretIdRestored = OPRETID_ROGUEGAMEDATA; + else // EVAL_ASSETS + opretIdRestored = OPRETID_ASSETSDATA; + + oprets.push_back(std::make_pair(opretIdRestored, voldstyledata)); + } + + return(funcId); } - - return(funcId); + LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() bad opret format," << " ccType=" << (int)ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl); + return (uint8_t)0; } - LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() bad opret format," << " ccType=" << (int)ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl); - return (uint8_t)0; - default: LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() illegal funcid=" << (int)funcId << std::endl); return (uint8_t)0; diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ff4102796d6..e95e042a26f 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -63,7 +63,7 @@ UniValue FinalizeCCTxExt(bool remote, uint64_t CCmask, struct CCcontract_info *c UniValue sigData(UniValue::VARR),result(UniValue::VOBJ); const UniValue sigDataNull = NullUniValue; - globalpk = GetUnspendable(cp,0); + globalpk = cp->GetUnspendable(); n = mtx.vout.size(); for (i=0; ievalcode,mypk); // to spend from single-eval evalcode 'unspendable' cc addr - unspendablepk = GetUnspendable(cp, unspendablepriv); + unspendablepk = cp->GetUnspendable(unspendablepriv); GetCCaddress(cp, unspendable, unspendablepk); othercond = MakeCCcond1(cp->evalcode, unspendablepk); GetCCaddress1of2(cp,CC1of2CCaddr,unspendablepk,unspendablepk); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 768e15939e9..3fcdf7c5049 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -323,7 +323,7 @@ bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) { destaddr[0] = 0; if ( pk.size() == 0 ) - pk = GetUnspendable(cp,0); + pk = cp->GetUnspendable(); return(_GetCCaddress(destaddr,cp->evalcode,pk)); } @@ -344,7 +344,7 @@ bool GetTokensCCaddress(struct CCcontract_info *cp, char *destaddr, CPubKey pk) { destaddr[0] = 0; if (pk.size() == 0) - pk = GetUnspendable(cp, 0); + pk = cp->GetUnspendable(); return(_GetTokensCCaddress(destaddr, cp->evalcode, cp->additionalTokensEvalcode2, pk)); } @@ -503,13 +503,6 @@ bool Myprivkey(uint8_t myprivkey[]) return(false); } -CPubKey GetUnspendable(CCcontract_info *cp,uint8_t *unspendablepriv) -{ - if ( unspendablepriv != 0 ) - memcpy(unspendablepriv,cp->CCpriv,32); - return(pubkey2pk(ParseHex(cp->CChexstr))); -} - /*** * Clear the unspendable eval codes and addresses * @param cp the contract diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 7d3baa6e31f..cf3caa7744d 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -169,7 +169,7 @@ bool CCAssetContract_info::validate(Eval* eval, const CTransaction &tx, uint32_t additionalTokensEvalcode2 = vopretNonfungible.begin()[0]; // find dual-eval tokens unspendable addr: - GetTokensCCaddress(this, tokensDualEvalUnspendableCCaddr, GetUnspendable(this, NULL)); + GetTokensCCaddress(this, tokensDualEvalUnspendableCCaddr, GetUnspendable()); // this is for marker validation: GetCCaddress(this, origAssetsCCaddr, origpubkey); diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 5337b1d56a7..d5f2a29d2c9 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -155,7 +155,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) CCAuctionContract_info C; if ( txfee == 0 ) txfee = 10000; - Auctionpk = GetUnspendable(&C,0); + Auctionpk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( (inputs= AddAuctionInputs(&C,mtx,Auctionpk,nValue+txfee,60)) > 0 ) { @@ -176,7 +176,7 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) CCAuctionContract_info C; if ( txfee == 0 ) txfee = 10000; - Auctionpk = GetUnspendable(&C,0); + Auctionpk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( (inputs= AddAuctionInputs(&C,mtx,Auctionpk,nValue+txfee,60)) > 0 ) { @@ -198,7 +198,7 @@ std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *tit if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - Auctionpk = GetUnspendable(&C,0); + Auctionpk = C.GetUnspendable(); if ( AddNormalinputs(mtx,mypk,txfee,64) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_AUCTION,funds,Auctionpk)); diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 5f31573b3f1..79e9f120232 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -569,7 +569,7 @@ std::string Faucet2Fund(struct CCcontract_info *cp,uint64_t txfee,int64_t funds) if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - cclibpk = GetUnspendable(cp,0); + cclibpk = cp->GetUnspendable(); if ( AddNormalinputs2(mtx,funds+txfee,64) > 0 ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,cclibpk)); @@ -594,7 +594,7 @@ std::string CClib_rawtxgen(struct CCcontract_info *cp,uint8_t funcid,cJSON *para } else if ( funcid != 'G' ) return(""); - cclibpk = GetUnspendable(cp,0); + cclibpk = cp->GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( (inputs= AddCClibInputs(cp,mtx,cclibpk,nValue+txfee,60,cp->unspendableCCaddr,1)) > 0 ) { diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0944eb15ff9..ddb513f55d4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -336,8 +336,8 @@ void *dicefinish(void *_ptr) mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); CCDiceContract_info C; - dicepk = GetUnspendable(&C,0); - GetCCaddress(&C,CCaddr,GetUnspendable(&C,0)); + dicepk = C.GetUnspendable(); + GetCCaddress(&C,CCaddr,C.GetUnspendable()); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); if ( (newht= KOMODO_INSYNC) == 0 ) sleep(7); @@ -1277,7 +1277,7 @@ CCDiceContract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid, CCD if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - dicepk = GetUnspendable(&C,0); + dicepk = C.GetUnspendable(); sbits = stringbits(planstr); if ( reffundingtxid == zeroid ) cmpflag = 0; @@ -1324,7 +1324,7 @@ UniValue DiceInfo(uint256 diceid) result.push_back(Pair("maxodds",maxodds)); result.push_back(Pair("timeoutblocks",timeoutblocks)); CCDiceContract_info C; - dicepk = GetUnspendable(&C,0); + dicepk = C.GetUnspendable(); int32_t entropytxs; funding = DicePlanFunds(entropyval,entropytxid,sbits,&C,dicepk,diceid,entropytxs,false); sprintf(numstr,"%.8f",(double)funding/COIN); diff --git a/src/cc/dilithium.cpp b/src/cc/dilithium.cpp index ade351206e8..02e3b9b9e8c 100644 --- a/src/cc/dilithium.cpp +++ b/src/cc/dilithium.cpp @@ -3156,7 +3156,7 @@ UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *para CPubKey Faucet_pubkeyget() { CCFaucetContract_info C; - return(GetUnspendable(&C,0)); + return C.GetUnspendable(); } UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) @@ -3167,7 +3167,7 @@ UniValue dilithium_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *par txfee = DILITHIUM_TXFEE; faucetpk = Faucet_pubkeyget(); mypk = pubkey2pk(Mypubkey()); - dilithiumpk = GetUnspendable(cp,0); + dilithiumpk = cp->GetUnspendable(); if ( params != 0 && ((n= cJSON_GetArraySize(params)) == 1 || n == 2) ) { std::string handle(jstr(jitem(params,0),0)); @@ -3294,7 +3294,7 @@ UniValue dilithium_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( txfee == 0 ) txfee = DILITHIUM_TXFEE; mypk = pubkey2pk(Mypubkey()); - dilithiumpk = GetUnspendable(cp,0); + dilithiumpk = cp->GetUnspendable(); if ( params != 0 && (n= cJSON_GetArraySize(params)) == 3 ) { amount = jdouble(jitem(params,2),0)*COIN + 0.0000000049; @@ -3583,7 +3583,7 @@ void dilithium_handleinit(struct CCcontract_info *cp) if ( didinit != 0 ) return; pthread_mutex_init(&DILITHIUM_MUTEX,NULL); - dilithiumpk = GetUnspendable(cp,0); + dilithiumpk = cp->GetUnspendable(); GetCCaddress(cp,CCaddr,dilithiumpk); SetCCtxids(txids,CCaddr,true,cp->evalcode,zeroid,'R'); for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) @@ -3645,7 +3645,7 @@ bool dilithium_Rvalidate(struct CCcontract_info *cp,int32_t height,Eval *eval,co if ( height < 14500 ) return(true); dilithium_handleinit(cp); - dilithiumpk = GetUnspendable(cp,0); + dilithiumpk = cp->GetUnspendable(); if ( (numvouts= tx.vout.size()) <= 1 ) return eval->Invalid("not enough vouts for registration tx"); else if ( dilithium_registeropretdecode(handle,pub33,bigpub,tx.vout[numvouts-1].scriptPubKey) == 'R' ) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index f4ef1ba02a7..0959a9ec551 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -194,7 +194,7 @@ UniValue FaucetGet(const CPubKey& pk, uint64_t txfee) if ( txfee == 0 ) txfee = 10000; - faucetpk = GetUnspendable(&C,0); + faucetpk = C.GetUnspendable(); CPubKey mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); if ( (inputs= AddFaucetInputs(&C,mtx,faucetpk,nValue+txfee,60)) > 0 ) { @@ -236,7 +236,7 @@ UniValue FaucetFund(const CPubKey& pk, uint64_t txfee,int64_t funds) if ( txfee == 0 ) txfee = 10000; CPubKey mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - faucetpk = GetUnspendable(&C,0); + faucetpk = C.GetUnspendable(); if ( AddNormalinputs(mtx,mypk,funds+txfee,64,pk.IsValid()) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,funds,faucetpk)); @@ -249,7 +249,7 @@ UniValue FaucetInfo() { CCFaucetContract_info C; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey faucetpk = GetUnspendable(&C,nullptr); + CPubKey faucetpk = C.GetUnspendable(); int64_t funding = AddFaucetInputs(&C,mtx,faucetpk,0,0); UniValue result(UniValue::VOBJ); result.push_back(Pair("result","success")); diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index c24bdde3633..673da1f287e 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -162,7 +162,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) CCFSMContract_info C; if ( txfee == 0 ) txfee = 10000; - fsmpk = GetUnspendable(&C,0); + fsmpk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( (inputs= AddFSMInputs(&C,mtx,fsmpk,nValue+txfee,60)) > 0 ) { @@ -181,7 +181,7 @@ std::string FSMInfo(uint256 fsmtxid) CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); CPubKey mypk = pubkey2pk(Mypubkey()); CCFSMContract_info C; - CPubKey fsmpk = GetUnspendable(&C,0); + CPubKey fsmpk = C.GetUnspendable(); return ""; } diff --git a/src/cc/games/prices.cpp b/src/cc/games/prices.cpp index 5c8437e5d03..0187c152d3c 100644 --- a/src/cc/games/prices.cpp +++ b/src/cc/games/prices.cpp @@ -135,7 +135,7 @@ UniValue games_settle(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } mypk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); acpk = buf2pk(ASSETCHAINS_OVERRIDE_PUBKEY33); Getscriptaddress(acaddr,CScript() << ParseHex(HexStr(acpk)) << OP_CHECKSIG); if ( params != 0 && cJSON_GetArraySize(params) == 1 ) @@ -178,7 +178,7 @@ UniValue games_bet(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) return(result); } mypk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); acpk = buf2pk(ASSETCHAINS_OVERRIDE_PUBKEY33); if ( params != 0 && cJSON_GetArraySize(params) == 2 ) { diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index c45d8e28389..441ebd93c9c 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1128,7 +1128,7 @@ UniValue games_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( maxplayers < 1 || maxplayers > GAMES_MAXPLAYERS ) return(cclib_error(result,"illegal maxplayers")); mypk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); games_univalue(result,"newgame",maxplayers,buyin); required = (3*txfee + maxplayers*(GAMES_REGISTRATIONSIZE+txfee)); if ( (inputsum= AddCClibInputs(cp,mtx,gamespk,required,16,cp->unspendableCCaddr,1)) >= required ) @@ -1151,7 +1151,7 @@ UniValue games_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 txid,hashBlock; CTransaction tx; int32_t openslots,maxplayers,numplayers,gameheight,nextheight,vout,numvouts; CPubKey gamespk; char coinaddr[64]; std::vector > unspentOutputs; - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); GetCCaddress(cp,coinaddr,gamespk); SetCCunspents(unspentOutputs,coinaddr,true); nextheight = komodo_nextheight(); @@ -1192,7 +1192,7 @@ UniValue games_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) result.push_back(Pair("result","success")); result.push_back(Pair("gameheight",(int64_t)gameheight)); mypk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); GetCCaddress1of2(cp,myaddr,gamespk,mypk); seed = games_gamefields(result,maxplayers,buyin,txid,myaddr); result.push_back(Pair("seed",(int64_t)seed)); @@ -1240,7 +1240,7 @@ UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) txfee = 10000; mypk = pubkey2pk(Mypubkey()); burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY)); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); games_univalue(result,"register",-1,-1); playertxid = tokenid = zeroid; if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) @@ -1276,7 +1276,7 @@ UniValue games_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) char unspendableTokenAddr[64]; uint8_t tokenpriv[32]; CCTokensContract_info tokensC; - CPubKey unspPk = GetUnspendable(&tokensC, tokenpriv); + CPubKey unspPk = tokensC.GetUnspendable(tokenpriv); GetCCaddress(&tokensC, unspendableTokenAddr, unspPk); CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); } @@ -1334,7 +1334,7 @@ UniValue games_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param result.push_back(Pair("keystrokes",keystrokestr)); keystrokes = ParseHex(keystrokestr); mypk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); GetCCaddress1of2(cp,destaddr,gamespk,mypk); if ( games_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1) == 0 ) { @@ -1361,7 +1361,7 @@ UniValue games_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param gamesevent *games_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *gamesaddr) { CPubKey gamespk; int32_t i,num,retval,maxplayers,gameheight,batonht,batonvout,numplayers,regslot,numkeys,err; std::string symbol,pname; CTransaction gametx; int64_t buyin,batonvalue; char fname[64]; gamesevent *keystrokes = 0; std::vector playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct games_player P,endP; - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); *numkeysp = 0; seed = 0; num = numkeys = 0; @@ -1437,7 +1437,7 @@ UniValue games_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); CPubKey pk,gamespk; int32_t i,n,numkeys,flag = 0; uint64_t seed; char str[512],gamesaddr[64],*pubstr,*hexstr; gamesevent *keystrokes = 0; std::vector newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; pk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); result.push_back(Pair("name","games")); result.push_back(Pair("method","extract")); gamesaddr[0] = 0; @@ -1524,7 +1524,7 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,ch if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); GetCCaddress1of2(cp,mygamesaddr,gamespk,mypk); result.push_back(Pair("name","games")); result.push_back(Pair("method",method)); @@ -1577,7 +1577,7 @@ UniValue games_finish(uint64_t txfee,struct CCcontract_info *cp,cJSON *params,ch else { CCTokensContract_info tokensC; - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(&tokensC,NULL))); // marker to token cc addr, burnable and validated + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, tokensC.GetUnspendable())); // marker to token cc addr, burnable and validated mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); cashout = games_cashout(&P); fprintf(stderr,"\ncashout %.8f extracted %s\n",(double)cashout/COIN,str); @@ -1647,7 +1647,7 @@ UniValue games_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 tokenid,gametxid,txid,hashBlock; CTransaction playertx,tx; int32_t maxplayers,vout,numvouts; std::vector playerdata; CPubKey gamespk,mypk,pk; std::string symbol,pname; char coinaddr[64]; std::vector > unspentOutputs; - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); mypk = pubkey2pk(Mypubkey()); GetTokensCCaddress(cp,coinaddr,mypk); SetCCunspents(unspentOutputs,coinaddr,true); @@ -1674,7 +1674,7 @@ UniValue games_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); uint256 txid,hashBlock,gametxid,tokenid,playertxid; int32_t vout,maxplayers,gameheight,numvouts; CPubKey gamespk,mypk; char coinaddr[64]; CTransaction tx,gametx; int64_t buyin; std::vector txids; - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); mypk = pubkey2pk(Mypubkey()); GetCCaddress1of2(cp,coinaddr,gamespk,mypk); SetCCtxids(txids,coinaddr,true,cp->evalcode,zeroid,'R'); @@ -1731,7 +1731,7 @@ UniValue games_fund(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( params != 0 && cJSON_GetArraySize(params) == 1 ) { amount = jdouble(jitem(params,0),0) * COIN + 0.0000000049; - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( amount > GAMES_TXFEE ) { @@ -1766,7 +1766,7 @@ int32_t games_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C static uint32_t good,bad; static uint256 prevgame; char str[512],gamesaddr[64],str2[67],fname[64]; gamesevent *keystrokes; int32_t i,numkeys; std::vector newdata; uint64_t seed; CPubKey gamespk; struct games_player P; *cashoutp = 0; - gamespk = GetUnspendable(cp,0); + gamespk = cp->GetUnspendable(); GetCCaddress1of2(cp,gamesaddr,gamespk,pk); if ( (keystrokes= games_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,gamesaddr)) != 0 ) { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 693729cdd42..566f287c288 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -163,7 +163,7 @@ CScript EncodeGatewaysBindOpRet(uint8_t funcid,uint256 tokenid,std::string coin, std::vector pubkeys; vscript_t vopret; - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); pubkeys.push_back(gatewayspk); vopret = E_MARSHAL(ss << evalcode << funcid << coin << totalsupply << oracletxid << M << N << gatewaypubkeys << taddr << prefix << prefix2 << wiftype); return(EncodeTokenOpRet(tokenid,pubkeys, std::make_pair(OPRETID_GATEWAYSDATA, vopret))); @@ -259,7 +259,7 @@ CScript EncodeGatewaysWithdrawOpRet(uint8_t funcid,uint256 tokenid,uint256 bindt std::vector pubkeys; vscript_t vopret; - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); pubkeys.push_back(gatewayspk); vopret = /*opret << OP_RETURN << */ E_MARSHAL(ss << evalcode << funcid << bindtxid << refcoin << withdrawpub << amount); return(EncodeTokenOpRet(tokenid,pubkeys, std::make_pair(OPRETID_GATEWAYSDATA, vopret))); @@ -539,7 +539,7 @@ bool CCGatewaysContract_info::validate(Eval *eval,const CTransaction &tx, uint32 // } // else // { - gatewayspk = GetUnspendable(this,0); + gatewayspk = GetUnspendable(); GetTokensCCaddress(this, gatewaystokensaddr, gatewayspk); if ( (funcid = DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey)) != 0) { @@ -903,7 +903,7 @@ UniValue GatewaysBind(const CPubKey& pk, uint64_t txfee,std::string coin,uint256 txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); _GetCCaddress(myTokenCCaddr,EVAL_TOKENS,mypk); - gatewayspk = GetUnspendable(&gatewaysC,0); + gatewayspk = gatewaysC.GetUnspendable(); if ( _GetCCaddress(destaddr,EVAL_GATEWAYS,gatewayspk) == 0 ) CCERR_RESULT("gatewayscc",CCLOG_INFO, stream << "Gateway bind." << coin << " (" << tokenid.GetHex() << ") cant create globaladdr"); if ( (fullsupply=CCfullsupply(tokenid)) != totalsupply ) @@ -993,7 +993,7 @@ UniValue GatewaysClaim(const CPubKey& pk, uint64_t txfee,uint256 bindtxid,std::s txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCGatewaysContract_info C; - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) CCERR_RESULT("gatewayscc",CCLOG_INFO, stream << "cant find bindtxid " << bindtxid.GetHex()); if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin ) @@ -1034,7 +1034,7 @@ UniValue GatewaysWithdraw(const CPubKey& pk, uint64_t txfee,uint256 bindtxid,std if ( txfee == 0 ) txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(&C, 0); + gatewayspk = C.GetUnspendable(); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) CCERR_RESULT("gatewayscc",CCLOG_INFO, stream << "cant find bindtxid " << bindtxid.GetHex()); if ( DecodeGatewaysBindOpRet(depositaddr,tx.vout[numvouts-1].scriptPubKey,tokenid,coin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B' || refcoin != coin ) @@ -1090,7 +1090,7 @@ UniValue GatewaysPartialSign(const CPubKey& pk, uint64_t txfee,uint256 lasttxid, if ( txfee == 0 ) txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 || (funcid=DecodeGatewaysOpRet(tx.vout[numvouts-1].scriptPubKey))==0 || (funcid!='W' && funcid!='P')) CCERR_RESULT("gatewayscc",CCLOG_INFO, stream << "can't find last tx " << lasttxid.GetHex()); @@ -1143,7 +1143,7 @@ UniValue GatewaysCompleteSigning(const CPubKey& pk, uint64_t txfee,uint256 lastt uint8_t K=0,M,N,taddr,prefix,prefix2,wiftype; std::vector pubkeys; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); if ( txfee == 0 ) txfee = 10000; if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 @@ -1235,7 +1235,7 @@ UniValue GatewaysPendingDeposits(const CPubKey& pk, uint256 bindtxid,std::string std::vector > unspentOutputs; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); _GetCCaddress(coinaddr,EVAL_GATEWAYS,mypk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { @@ -1289,7 +1289,7 @@ UniValue GatewaysPendingWithdraws(const CPubKey& pk, uint256 bindtxid,std::strin std::vector > unspentOutputs; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); _GetCCaddress(coinaddr,EVAL_GATEWAYS,gatewayspk); GetTokensCCaddress(&C,tokensaddr,gatewayspk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) @@ -1378,7 +1378,7 @@ UniValue GatewaysProcessedWithdraws(const CPubKey& pk, uint256 bindtxid,std::str std::vector > unspentOutputs; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); - gatewayspk = GetUnspendable(&C,0); + gatewayspk = C.GetUnspendable(); _GetCCaddress(coinaddr,EVAL_GATEWAYS,gatewayspk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { @@ -1511,7 +1511,7 @@ UniValue GatewaysInfo(uint256 bindtxid) int32_t i; int64_t numvouts,totalsupply,remaining; std::vector msigpubkeys; CCGatewaysContract_info C; - Gatewayspk = GetUnspendable(&C,0); + Gatewayspk = C.GetUnspendable(); GetTokensCCaddress(&C,gatewaystokens,Gatewayspk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 633fff086d6..6cada9df5c2 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -636,7 +636,7 @@ template UniValue _HeirFund(int64_t txfee, int64_t amount, std // add a marker for finding all plans in HeirList() // TODO: change marker either to cc or normal txidaddr unspendable CCHeirContract_info heirC; - CPubKey heirUnspendablePubKey = GetUnspendable(&heirC, 0); + CPubKey heirUnspendablePubKey = heirC.GetUnspendable(); // mtx.vout.push_back(CTxOut(txfee, CScript() << ParseHex(HexStr(heirUnspendablePubKey)) << OP_CHECKSIG)); <-- bad marker cause it was spendable by anyone mtx.vout.push_back(MakeCC1vout(EVAL_HEIR, markerfee, heirUnspendablePubKey)); // this marker spending is disabled in the validation code @@ -1219,7 +1219,7 @@ void _HeirList(struct CCcontract_info *cp, UniValue &result) std::vector> unspentOutputs; char markeraddr[64]; - GetCCaddress(cp, markeraddr, GetUnspendable(cp, NULL)); + GetCCaddress(cp, markeraddr, cp->GetUnspendable()); SetCCunspents(unspentOutputs, markeraddr,true); //std::cerr << "HeirList() finding heir marker from unspendable addr=" << markeraddr << " unspentOutputs.size()=" << unspentOutputs.size() << '\n'; diff --git a/src/cc/importgateway.cpp b/src/cc/importgateway.cpp index 404908bd9ed..b317347003d 100644 --- a/src/cc/importgateway.cpp +++ b/src/cc/importgateway.cpp @@ -317,7 +317,7 @@ bool CCImportGatewayContract_info::validate(Eval *eval,const CTransaction &tx, u // } // else // { - importgatewaypk = GetUnspendable(this,0); + importgatewaypk = GetUnspendable(); GetCCaddress(this, importgatewayaddr, importgatewaypk); if ( (funcid = DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey)) != 0) { @@ -520,7 +520,7 @@ std::string ImportGatewayBind(uint64_t txfee,std::string coin,uint256 oracletxid txfee = 10000; mypk = pubkey2pk(Mypubkey()); _GetCCaddress(myTokenCCaddr,EVAL_TOKENS,mypk); - importgatewaypk = GetUnspendable(&C,0); + importgatewaypk = C.GetUnspendable(); if ( _GetCCaddress(destaddr,EVAL_IMPORTGATEWAY,importgatewaypk) == 0 ) { CCerror = strprintf("ImportGateway bind.%s can't create globaladdr",coin.c_str()); @@ -656,7 +656,7 @@ std::string ImportGatewayWithdraw(uint64_t txfee,uint256 bindtxid,std::string re txfee = 10000; mypk = pubkey2pk(Mypubkey()); CCImportGatewayContract_info C; - importgatewaypk = GetUnspendable(&C, 0); + importgatewaypk = C.GetUnspendable(); if( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { @@ -729,7 +729,7 @@ std::string ImportGatewayPartialSign(uint64_t txfee,uint256 lasttxid,std::string if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - importgatewaypk = GetUnspendable(&C,0); + importgatewaypk = C.GetUnspendable(); if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 || (funcid=DecodeImportGatewayOpRet(tx.vout[numvouts-1].scriptPubKey))==0 || (funcid!='W' && funcid!='P')) { @@ -840,7 +840,7 @@ std::string ImportGatewayCompleteSigning(uint64_t txfee,uint256 lasttxid,std::st mypk = pubkey2pk(Mypubkey()); CCImportGatewayContract_info C; - importgatewaypk = GetUnspendable(&C,0); + importgatewaypk = C.GetUnspendable(); if ( txfee == 0 ) txfee = 10000; if (myGetTransaction(lasttxid,tx,hashBlock)==0 || (numvouts= tx.vout.size())<=0 @@ -1032,7 +1032,7 @@ UniValue ImportGatewayPendingWithdraws(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); CCImportGatewayContract_info C; - importgatewaypk = GetUnspendable(&C,0); + importgatewaypk = C.GetUnspendable(); _GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,importgatewaypk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { @@ -1120,7 +1120,7 @@ UniValue ImportGatewayProcessedWithdraws(uint256 bindtxid,std::string refcoin) mypk = pubkey2pk(Mypubkey()); CCImportGatewayContract_info C; - importgatewaypk = GetUnspendable(&C,0); + importgatewaypk = C.GetUnspendable(); _GetCCaddress(coinaddr,EVAL_IMPORTGATEWAY,importgatewaypk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { @@ -1254,7 +1254,7 @@ UniValue ImportGatewayInfo(uint256 bindtxid) CPubKey ImportGatewaypk; int32_t i; int64_t numvouts,remaining; std::vector msigpubkeys; CCImportGatewayContract_info C; - ImportGatewaypk = GetUnspendable(&C,0); + ImportGatewaypk = C.GetUnspendable(); GetTokensCCaddress(&C,gatewaystokens,ImportGatewaypk); if ( myGetTransaction(bindtxid,tx,hashBlock) == 0 || (numvouts= tx.vout.size()) <= 0 ) { diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index af3f5631336..3135bbb0635 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -257,7 +257,7 @@ UniValue LottoInfo(uint256 lottoid) result.push_back(Pair("ticketsize",ticketsize)); result.push_back(Pair("odds",odds)); CCLottoContract_info C; - lottopk = GetUnspendable(&C,0); + lottopk = C.GetUnspendable(); lockedfunds = LottoPlanFunds(sbits,&C,lottopk,lottoid); sprintf(numstr,"%.8f",(double)lockedfunds/COIN); result.push_back(Pair("jackpot",numstr)); @@ -292,7 +292,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic if ( txfee == 0 ) txfee = 10000; CCLottoContract_info C; - lottopk = GetUnspendable(&C,0); + lottopk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); sbits = stringbits(planstr); if ( AddNormalinputs(mtx,mypk,funding+txfee,60) > 0 ) @@ -312,7 +312,7 @@ std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) CCLottoContract_info C; if ( txfee == 0 ) txfee = 10000; - lottopk = GetUnspendable(&C,0); + lottopk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( (inputs= AddLottoInputs(&C,mtx,lottopk,nValue+txfee,60)) > 0 ) { @@ -335,7 +335,7 @@ std::string LottoWinner(uint64_t txfee) txfee = 10000; mypk = pubkey2pk(Mypubkey()); CCLottoContract_info C; - lottopk = GetUnspendable(&C,0); + lottopk = C.GetUnspendable(); if ( AddNormalinputs(mtx,mypk,txfee,64) > 0 ) { mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,winnings,lottopk)); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index eb431788db9..42721a75ab7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -190,7 +190,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { CTxOut ccvout; CPubKey Marmarapk; CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) { ccvout = MakeCC1of2vout(EVAL_MARMARA,0,Marmarapk,pk); @@ -211,7 +211,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { CPubKey Marmarapk,pk; int32_t ht,unlockht; CTxOut ccvout; CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); if ( 0 ) { int32_t d,histo[365*2+30]; @@ -259,7 +259,7 @@ bool MarmaraPoScheck(char *destaddr,CScript opret,CTransaction staketx) { funcid = DecodeMaramaraCoinbaseOpRet(opret,pk,height,unlockht); CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,Marmarapk,pk); return(strcmp(destaddr,coinaddr) == 0); } @@ -345,7 +345,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { char coinaddr[64]; CPubKey Marmarapk,pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; - Marmarapk = GetUnspendable(cp,0); + Marmarapk = cp->GetUnspendable(); GetCCaddress1of2(cp,coinaddr,Marmarapk,poolpk); SetCCunspents(unspentOutputs,coinaddr,true); unlocks = MarmaraUnlockht(firstheight); @@ -436,7 +436,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) height++; mypk = pubkey2pk(Mypubkey()); CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG); if ( (val= CCaddress_balance(coinaddr,0)) < amount ) val -= txfee; @@ -555,7 +555,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) txfee = 10000; mypk = pubkey2pk(Mypubkey()); CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); remaining = change = 0; height = chainActive.LastTip()->GetHeight(); if ( (n= MarmaraGetbatontxid(creditloop,batontxid,refbatontxid)) > 0 ) @@ -671,7 +671,7 @@ int32_t MarmaraGetCreditloops(int64_t &totalamount,std::vector &issuanc { char coinaddr[64]; CPubKey Marmarapk,senderpk; int64_t amount; uint256 createtxid,txid,hashBlock; CTransaction tx; int32_t numvouts,vout,matures,n=0; std::string currency; std::vector > unspentOutputs; - Marmarapk = GetUnspendable(cp,0); + Marmarapk = cp->GetUnspendable(); GetCCaddress(cp,coinaddr,Marmarapk); SetCCunspents(unspentOutputs,coinaddr,true); // do all txid, conditional on spent/unspent @@ -769,7 +769,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a txfee = 10000; // make sure less than maxlength CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); if ( MarmaraGetcreatetxid(createtxid,approvaltxid) < 0 ) errorstr = (char *)"cant get createtxid from approvaltxid"; @@ -988,7 +988,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * if ( txfee == 0 ) txfee = 10000; CCMaramaContract_info C; - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); if ( (array= cJSON_Parse(jsonstr)) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; iGetUnspendable(); if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) { if ( n == 2 && (hexstr= jstr(jitem(params,0),0)) != 0 && is_hexstr(hexstr,0) == 66 ) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index e50f44e324c..0286c4ffae4 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -626,7 +626,7 @@ bool CCOraclesContract_info::validate(Eval* eval,const CTransaction &tx, uint32_ GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); if ( vopret.size() > 2 ) { - oraclespk=GetUnspendable(this,0); + oraclespk=GetUnspendable(); Getscriptaddress(oraclesaddr,CScript() << ParseHex(HexStr(oraclespk)) << OP_CHECKSIG); script = (uint8_t *)vopret.data(); switch ( script[1] ) @@ -851,7 +851,7 @@ UniValue OracleCreate(const CPubKey& pk, int64_t txfee,std::string name,std::str txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCOraclesContract_info C; - Oraclespk = GetUnspendable(&C,0); + Oraclespk = C.GetUnspendable(); if ( AddNormalinputs(mtx,mypk,2*txfee,3,pk.IsValid()) > 0 ) { mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(Oraclespk)) << OP_CHECKSIG)); @@ -899,7 +899,7 @@ UniValue OracleRegister(const CPubKey& pk, int64_t txfee,uint256 oracletxid,int6 CCERR_RESULT("oraclescc",CCLOG_INFO, stream << "datafee must be txfee or more"); mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCOraclesContract_info C; - oraclespk = GetUnspendable(&C,0); + oraclespk = C.GetUnspendable(); batonpk = OracleBatonPk(batonaddr,&C); markerpubkey = CCtxidaddr(markeraddr,oracletxid); if (AddNormalinputs(mtx,mypk,3*txfee,4,pk.IsValid())) diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 1d2ce7d8c0b..7c56f664f97 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -347,7 +347,7 @@ bool CCPaymentsContract_info::validate(Eval* eval,const CTransaction &tx, uint32 return(eval->Invalid("negative values")); if ( minimum < 10000 ) return(eval->Invalid("minimum must be over 10000")); - Paymentspk = GetUnspendable(this,0); + Paymentspk = GetUnspendable(); txidpk = CCtxidaddr(txidaddr,createtxid); GetCCaddress1of2(this,txidaddr,Paymentspk,txidpk); //fprintf(stderr, "lockedblocks.%i minrelease.%i totalallocations.%i txidopret1.%s txidopret2.%s\n",lockedblocks, minrelease, totalallocations, txidoprets[0].ToString().c_str(), txidoprets[1].ToString().c_str() ); @@ -562,7 +562,7 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract else threshold = total; } else threshold = 0; - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); for (iter=0; iter<2; iter++) { if ( GetBalance == 1 && iter == 1 ) @@ -714,7 +714,7 @@ UniValue PaymentsRelease(struct CCcontract_info *cp,char *jsonstr) mpz_t mpzTotalAllocations, mpzAllocation; mpz_init(mpzTotalAllocations); cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); if ( params != 0 && n >= 2 ) { createtxid = payments_juint256(jitem(params,0)); @@ -971,7 +971,7 @@ UniValue PaymentsFund(struct CCcontract_info *cp,char *jsonstr) uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); if ( params != 0 && n > 1 && n <= 4 ) { txid = payments_juint256(jitem(params,0)); @@ -1037,7 +1037,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr) uint256 tokenid; int8_t fixedAmount; cJSON *params = payments_reparse(&n,jsonstr); mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); if ( params != 0 && n == 1 ) { createtxid = payments_juint256(jitem(params,0)); @@ -1192,7 +1192,7 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) return(result); } mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) { mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); @@ -1275,7 +1275,7 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) } } mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) { mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); @@ -1357,7 +1357,7 @@ UniValue PaymentsAirdropTokens(struct CCcontract_info *cp,char *jsonstr) } } mypk = pubkey2pk(Mypubkey()); - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) { mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); @@ -1397,7 +1397,7 @@ UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) cJSON *params = payments_reparse(&n,jsonstr); if ( params != 0 && n == 1 ) { - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); createtxid = payments_juint256(jitem(params,0)); if ( myGetTransaction(createtxid,tx,hashBlock) != 0 && tx.vout.size() > 0 ) { @@ -1543,7 +1543,7 @@ UniValue PaymentsList(struct CCcontract_info *cp,char *jsonstr) std::vector > addressIndex; uint256 txid,hashBlock,tokenid; UniValue result(UniValue::VOBJ),a(UniValue::VARR); char markeraddr[64],str[65]; CPubKey Paymentspk; CTransaction tx; int32_t lockedblocks,minrelease; std::vector txidoprets; int64_t totalallocations=0; int32_t top=0,bottom=0,minimum=10000; std::vector> excludeScriptPubKeys; int8_t fixedAmount = 0; - Paymentspk = GetUnspendable(cp,0); + Paymentspk = cp->GetUnspendable(); GetCCaddress1of2(cp,markeraddr,Paymentspk,Paymentspk); SetCCtxids(addressIndex,markeraddr,true); for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 581f3af3c02..a9cb8a30651 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -131,7 +131,7 @@ CScript EncodePegsFundOpRet(uint256 tokenid,uint256 pegstxid,CPubKey srcpub,int6 std::vector pubkeys; vscript_t vopret; CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); pubkeys.push_back(srcpub); pubkeys.push_back(pegspk); LOGSTREAM("pegscc", CCLOG_DEBUG1, stream << "EncodePegsFundOpRet [" << account.first << "," << account.second << "]" << std::endl); @@ -206,7 +206,7 @@ CScript EncodePegsExchangeOpRet(uint256 tokenid,uint256 pegstxid,CPubKey pk1,CPu std::vector pubkeys; vscript_t vopret; CPubKey pegspk; CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); pubkeys.push_back(pk1); pubkeys.push_back(pk2); vopret = E_MARSHAL(ss << evalcode << funcid << pegstxid << pk1 << amount << account); @@ -479,7 +479,7 @@ char PegsFindAccount(struct CCcontract_info *cp,CPubKey pk,uint256 pegstxid, uin ImportProof proof; CTransaction burntx; std::vector payouts; accounttxid=zeroid; - pegspk = GetUnspendable(cp,0); + pegspk = cp->GetUnspendable(); GetCCaddress1of2(cp,coinaddr,pk,pegspk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -594,7 +594,7 @@ double PegsGetGlobalRatio(uint256 pegstxid) std::map> globalaccounts; CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,pegspk,pegspk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -658,7 +658,7 @@ std::string PegsFindBestAccount(struct CCcontract_info *cp,uint256 pegstxid, uin std::pair tmpaccount; accounttxid=zeroid; - pegspk = GetUnspendable(cp,0); + pegspk = cp->GetUnspendable(); GetCCaddress1of2(cp,coinaddr,pegspk,pegspk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -695,7 +695,7 @@ UniValue PegsCreate(const CPubKey& pk,uint64_t txfee,int64_t amount, std::vector txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); for(auto txid : bindtxids) { if (myGetTransaction(txid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) @@ -722,7 +722,7 @@ UniValue PegsFund(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 tok txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) CCERR_RESULT("pegscc",CCLOG_INFO, stream << "cant find pegstxid " << pegstxid.GetHex()); if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') @@ -790,7 +790,7 @@ UniValue PegsGet(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 toke txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) CCERR_RESULT("pegscc",CCLOG_INFO, stream << "cant find pegstxid " << pegstxid.GetHex()); if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') @@ -843,7 +843,7 @@ UniValue PegsRedeem(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 t txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) CCERR_RESULT("pegscc",CCLOG_INFO, stream << "cant find pegstxid " << pegstxid.GetHex()); if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') @@ -925,7 +925,7 @@ UniValue PegsExchange(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint256 txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) CCERR_RESULT("pegscc",CCLOG_INFO, stream << "cant find pegstxid " << pegstxid.GetHex()); if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') @@ -1012,7 +1012,7 @@ UniValue PegsLiquidate(const CPubKey& pk,uint64_t txfee,uint256 pegstxid, uint25 txfee = 10000; mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); if (myGetTransaction(pegstxid,tx,hashBlock)==0 || (numvouts=tx.vout.size())<=0) CCERR_RESULT("pegscc",CCLOG_INFO, stream << "cant find pegstxid " << pegstxid.GetHex()); if (DecodePegsCreateOpRet(tx.vout[numvouts-1].scriptPubKey,bindtxids)!='C') @@ -1094,7 +1094,7 @@ UniValue PegsAccountHistory(const CPubKey& pk,uint256 pegstxid) result.push_back(Pair("name","pegsaccounthistory")); mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,mypk,pegspk); SetCCtxids(txids,coinaddr,true,EVAL_PEGS,pegstxid,0); for (std::vector::const_iterator it=txids.begin(); it!=txids.end(); it++) @@ -1132,7 +1132,7 @@ UniValue PegsAccountInfo(const CPubKey& pk,uint256 pegstxid) result.push_back(Pair("name","pegsaccountinfo")); mypk = pk.IsValid()?pk:pubkey2pk(Mypubkey()); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,mypk,pegspk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -1178,7 +1178,7 @@ UniValue PegsWorstAccounts(uint256 pegstxid) result.push_back(Pair("result","success")); result.push_back(Pair("name","pegsworstaccounts")); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,pegspk,pegspk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -1233,7 +1233,7 @@ UniValue PegsInfo(uint256 pegstxid) result.push_back(Pair("result","success")); result.push_back(Pair("name","pegsinfo")); CCPegsContract_info C; - pegspk = GetUnspendable(&C,0); + pegspk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,pegspk,pegspk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index fe3b6f9325d..42fa67db3d5 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -252,7 +252,7 @@ static bool ValidateBetTx(struct CCcontract_info *cp, Eval *eval, const CTransac if( prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) != 'B') return eval->Invalid("cannot decode opreturn for bet tx"); - pricespk = GetUnspendable(cp, 0); + pricespk = cp->GetUnspendable(); if (MakeCC1vout(cp->evalcode, bettx.vout[0].nValue, pk) != bettx.vout[0]) return eval->Invalid("cannot validate vout0 in bet tx with pk from opreturn"); @@ -305,7 +305,7 @@ static bool ValidateAddFundingTx(struct CCcontract_info *cp, Eval *eval, const C if (prices_addopretdecode(addfundingtx.vout.back().scriptPubKey, bettxid, pk, amount) != 'A') return eval->Invalid("cannot decode opreturn for add funding tx"); - pricespk = GetUnspendable(cp, 0); + pricespk = cp->GetUnspendable(); uint8_t vintxFuncId = PricesCheckOpret(vintx, vintxOpret); if (vintxFuncId != 'A' && vintxFuncId != 'B') { // if vintx is bettx return eval->Invalid("incorrect vintx funcid"); @@ -351,7 +351,7 @@ static bool ValidateCostbasisTx(struct CCcontract_info *cp, Eval *eval, const CT if (prices_costbasisopretdecode(costbasistx.vout.back().scriptPubKey, bettxid, pk, height, costbasisInOpret) != 'C') return eval->Invalid("cannot decode opreturn for costbasis tx"); - pricespk = GetUnspendable(cp, 0); + pricespk = cp->GetUnspendable(); if (CTxOut(costbasistx.vout[0].nValue, CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG) != costbasistx.vout[0]) //might go to any pk who calculated costbasis return eval->Invalid("cannot validate vout0 in costbasis tx with pk from opreturn"); if (MakeCC1vout(cp->evalcode, costbasistx.vout[1].nValue, pricespk) != costbasistx.vout[1]) @@ -423,7 +423,7 @@ static bool ValidateFinalTx(struct CCcontract_info *cp, Eval *eval, const CTrans if (bettx.GetHash() != bettxid) return eval->Invalid("incorrect bettx id"); - pricespk = GetUnspendable(cp, 0); + pricespk = cp->GetUnspendable(); if (CTxOut(finaltx.vout[0].nValue, CScript() << ParseHex(HexStr(pk)) << OP_CHECKSIG) != finaltx.vout[0]) return eval->Invalid("cannot validate vout0 in final tx with pk from opreturn"); @@ -1471,7 +1471,7 @@ UniValue PricesBet(int64_t txfee, int64_t amount, int16_t leverage, std::vector< if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(&C, 0); + pricespk = C.GetUnspendable(); if (prices_syntheticvec(vec, synthetic) < 0 || (firstprice = prices_syntheticprice(vec, nextheight - 1, 1, leverage)) < 0 || vec.size() == 0 || vec.size() > 4096) { @@ -1530,7 +1530,7 @@ UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); CCPricesContract_info C; - pricespk = GetUnspendable(&C, 0); + pricespk = C.GetUnspendable(); if (!myGetTransaction(bettxid, bettx, hashBlock) || bettx.vout.size() <= 3 || @@ -1650,7 +1650,7 @@ UniValue PricesRefillFund(int64_t amount) if (AddNormalinputs(mtx, mypk, amount + txfee, 64) >= amount + txfee) { CCPricesContract_info C; - pricespk = GetUnspendable(&C, 0); + pricespk = C.GetUnspendable(); mtx.vout.push_back(MakeCC1vout(C.evalcode, amount, pricespk)); // vout1 added amount rawtx = FinalizeCCTx(0, &C, mtx, mypk, txfee, CScript()); return(prices_rawtxresult(result, rawtx, 0)); @@ -1816,7 +1816,7 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); CCPricesContract_info C; - pricespk = GetUnspendable(&C, 0); + pricespk = C.GetUnspendable(); GetCCaddress(&C, destaddr, pricespk); BetInfo betinfo; @@ -1928,7 +1928,7 @@ UniValue PricesCashout(int64_t txfee, uint256 bettxid) mypk = pubkey2pk(Mypubkey()); CCPricesContract_info C; - pricespk = GetUnspendable(&C, 0); + pricespk = C.GetUnspendable(); GetCCaddress(&C, destaddr, pricespk); BetInfo betinfo; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index c14ea3b78f1..d43046e6b12 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -410,7 +410,7 @@ UniValue RewardsInfo(uint256 rewardsid) sprintf(numstr,"%.8f",(double)mindeposit/COIN); result.push_back(Pair("mindeposit",numstr)); CCRewardsContract_info C; - rewardspk = GetUnspendable(&C,0); + rewardspk = C.GetUnspendable(); funding = RewardsPlanFunds(lockedfunds,sbits,&C,rewardspk,rewardsid); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); @@ -459,7 +459,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 txfee = 10000; mypk = pubkey2pk(Mypubkey()); CCRewardsContract_info C; - rewardspk = GetUnspendable(&C,0); + rewardspk = C.GetUnspendable(); sbits = stringbits(planstr); if ( RewardsPlanExists(&C,sbits,rewardspk,a,b,c,d) != 0 ) { @@ -490,7 +490,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i txfee = 10000; mypk = pubkey2pk(Mypubkey()); CCRewardsContract_info C; - rewardspk = GetUnspendable(&C,0); + rewardspk = C.GetUnspendable(); sbits = stringbits(planstr); if ( RewardsPlanExists(&C,sbits,rewardspk,a,b,c,d) == 0 ) { @@ -527,7 +527,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t txfee = 10000; mypk = pubkey2pk(Mypubkey()); CCRewardsContract_info C; - rewardspk = GetUnspendable(&C,0); + rewardspk = C.GetUnspendable(); sbits = stringbits(planstr); if ( RewardsPlanExists(&C,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { @@ -566,7 +566,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 if ( txfee == 0 ) txfee = 10000; CCRewardsContract_info C; - rewardspk = GetUnspendable(&C,0); + rewardspk = C.GetUnspendable(); mypk = pubkey2pk(Mypubkey()); sbits = stringbits(planstr); if ( locktxid == fundingtxid ) diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index 0961edb3365..525d2f8882a 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -803,7 +803,7 @@ UniValue rogue_newgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) if ( maxplayers < 1 || maxplayers > ROGUE_MAXPLAYERS ) return(cclib_error(result,"illegal maxplayers")); mypk = pubkey2pk(Mypubkey()); - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); rogue_univalue(result,"newgame",maxplayers,buyin); required = (3*txfee + maxplayers*(ROGUE_REGISTRATIONSIZE+txfee)); if ( (inputsum= AddCClibInputs(cp,mtx,roguepk,required,16,cp->unspendableCCaddr,1)) >= required ) @@ -859,7 +859,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) txfee = 10000; mypk = pubkey2pk(Mypubkey()); burnpk = pubkey2pk(ParseHex(CC_BURNPUBKEY)); - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); rogue_univalue(result,"register",-1,-1); playertxid = tokenid = zeroid; if ( params != 0 && (n= cJSON_GetArraySize(params)) > 0 ) @@ -894,7 +894,7 @@ UniValue rogue_register(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) mtx.vin.push_back(CTxIn(tokenid,0)); // spending cc marker as token is burned char unspendableTokenAddr[64]; uint8_t tokenpriv[32]; CCTokensContract_info tokensC; - CPubKey unspPk = GetUnspendable(&tokensC, tokenpriv); + CPubKey unspPk = tokensC.GetUnspendable(tokenpriv); GetCCaddress(&tokensC, unspendableTokenAddr, unspPk); CCaddr2set(cp, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); } @@ -952,7 +952,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param result.push_back(Pair("keystrokes",keystrokestr)); keystrokes = ParseHex(keystrokestr); mypk = pubkey2pk(Mypubkey()); - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); GetCCaddress1of2(cp,destaddr,roguepk,mypk); if ( rogue_isvalidgame(cp,gameheight,tx,buyin,maxplayers,gametxid,1) == 0 ) { @@ -979,7 +979,7 @@ UniValue rogue_keystrokes(uint64_t txfee,struct CCcontract_info *cp,cJSON *param char *rogue_extractgame(int32_t makefiles,char *str,int32_t *numkeysp,std::vector &newdata,uint64_t &seed,uint256 &playertxid,struct CCcontract_info *cp,uint256 gametxid,char *rogueaddr) { CPubKey roguepk; int32_t i,num,retval,maxplayers,gameheight,batonht,batonvout,numplayers,regslot,numkeys,err; std::string symbol,pname; CTransaction gametx; int64_t buyin,batonvalue; char fname[64],*keystrokes = 0; std::vector playerdata; uint256 batontxid; FILE *fp; uint8_t newplayer[10000]; struct rogue_player P,endP; - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); *numkeysp = 0; seed = 0; num = numkeys = 0; @@ -1065,7 +1065,7 @@ UniValue rogue_extract(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ); CPubKey pk,roguepk; int32_t i,n,numkeys,flag = 0; uint64_t seed; char str[512],rogueaddr[64],*pubstr,*hexstr,*keystrokes = 0; std::vector newdata; uint256 gametxid,playertxid; FILE *fp; uint8_t pub33[33]; pk = pubkey2pk(Mypubkey()); - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); result.push_back(Pair("name","rogue")); result.push_back(Pair("method","extract")); rogueaddr[0] = 0; @@ -1137,7 +1137,7 @@ int32_t rogue_playerdata_validate(int64_t *cashoutp,uint256 &playertxid,struct C static uint32_t good,bad; static uint256 prevgame; char str[512],*keystrokes,rogueaddr[64],str2[67],fname[64]; int32_t i,dungeonlevel,numkeys; std::vector newdata; uint64_t seed,mult = 10; CPubKey roguepk; struct rogue_player P; *cashoutp = 0; - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); GetCCaddress1of2(cp,rogueaddr,roguepk,pk); if ( (keystrokes= rogue_extractgame(0,str,&numkeys,newdata,seed,playertxid,cp,gametxid,rogueaddr)) != 0 ) { @@ -1231,7 +1231,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); GetCCaddress1of2(cp,myrogueaddr,roguepk,mypk); result.push_back(Pair("name","rogue")); result.push_back(Pair("method",method)); @@ -1286,7 +1286,7 @@ UniValue rogue_finishgame(uint64_t txfee,struct CCcontract_info *cp,cJSON *param else { CCTokensContract_info tokensC; - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(&tokensC,NULL))); // marker to token cc addr, burnable and validated + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, tokensC.GetUnspendable())); // marker to token cc addr, burnable and validated mtx.vout.push_back(MakeTokensCC1vout(cp->evalcode,1,mypk)); cashout = rogue_cashout(&P); fprintf(stderr,"\nextracted $$$gold.%d -> %.8f ROGUE hp.%d strength.%d/%d level.%d exp.%d dl.%d n.%d amulet.%d\n",P.gold,(double)cashout/COIN,P.hitpoints,P.strength&0xffff,P.strength>>16,P.level,P.experience,P.dungeonlevel,n,P.amulet); @@ -1371,7 +1371,7 @@ UniValue rogue_gameinfo(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) result.push_back(Pair("result","success")); result.push_back(Pair("gameheight",(int64_t)gameheight)); mypk = pubkey2pk(Mypubkey()); - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); GetCCaddress1of2(cp,myrogueaddr,roguepk,mypk); //fprintf(stderr,"myrogueaddr.%s\n",myrogueaddr); seed = rogue_gamefields(result,maxplayers,buyin,txid,myrogueaddr); @@ -1401,7 +1401,7 @@ UniValue rogue_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 txid,hashBlock; CTransaction tx; int32_t openslots,maxplayers,numplayers,gameheight,nextheight,vout,numvouts; CPubKey roguepk; char coinaddr[64]; std::vector > unspentOutputs; - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); GetCCaddress(cp,coinaddr,roguepk); SetCCunspents(unspentOutputs,coinaddr,true); nextheight = komodo_nextheight(); @@ -1430,7 +1430,7 @@ UniValue rogue_players(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); int64_t buyin; uint256 tokenid,gametxid,txid,hashBlock; CTransaction playertx,tx; int32_t maxplayers,vout,numvouts; std::vector playerdata; CPubKey roguepk,mypk,pk; std::string symbol,pname; char coinaddr[64]; std::vector > unspentOutputs; - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); mypk = pubkey2pk(Mypubkey()); GetTokensCCaddress(cp,coinaddr,mypk); SetCCunspents(unspentOutputs,coinaddr,true); @@ -1458,7 +1458,7 @@ UniValue rogue_games(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ),a(UniValue::VARR),b(UniValue::VARR); uint256 txid,hashBlock,gametxid,tokenid,playertxid; int32_t vout,maxplayers,gameheight,numvouts; CPubKey roguepk,mypk; char coinaddr[64]; CTransaction tx,gametx; int64_t buyin; std::vector txids; //std::vector > unspentOutputs; - roguepk = GetUnspendable(cp,0); + roguepk = cp->GetUnspendable(); mypk = pubkey2pk(Mypubkey()); GetCCaddress1of2(cp,coinaddr,roguepk,mypk); //SetCCunspents(unspentOutputs,coinaddr); diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 8017799ba72..9202ef74a3a 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -2676,7 +2676,7 @@ UniValue sudoku_generate(uint64_t txfee,struct CCcontract_info *cp,cJSON *params } priv2addr(coinaddr,pub33,privkey); pk = buf2pk(pub33); - sudokupk = GetUnspendable(cp,0); + sudokupk = cp->GetUnspendable(); result.push_back(Pair("srand",(int)srandi)); result.push_back(Pair("amount",ValueFromAmount(amount))); if ( (inputsum= AddCClibInputs(cp,mtx,sudokupk,amount+2*txfee,16,cp->unspendableCCaddr,1)) >= amount+2*txfee ) @@ -2770,7 +2770,7 @@ UniValue sudoku_pending(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) UniValue result(UniValue::VOBJ),a(UniValue::VARR); char coinaddr[64],unsolved[82]; int64_t nValue,total=0; uint256 txid,hashBlock; CTransaction tx; int32_t vout,numvouts; CPubKey sudokupk; CBlockIndex *pindex; std::vector > unspentOutputs; - sudokupk = GetUnspendable(cp,0); + sudokupk = cp->GetUnspendable(); GetCCaddress(cp,coinaddr,sudokupk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 776dc834cdf..76f5fe7a8e9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2748,7 +2748,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt uint256 txid; int32_t vout,ht,unlockht; CAmount nValue; char coinaddr[64]; CPubKey mypk,Marmarapk,pk; std::vector > unspentOutputs; mypk = pubkey2pk(Mypubkey()); - Marmarapk = GetUnspendable(&C,0); + Marmarapk = C.GetUnspendable(); GetCCaddress1of2(&C,coinaddr,Marmarapk,mypk); SetCCunspents(unspentOutputs,coinaddr,true); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index 4c022a690c0..fec4881b599 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -382,7 +382,7 @@ UniValue migrate_createburntransaction(const UniValue& params, bool fHelp, const throw runtime_error("No token inputs found (please try to consolidate tokens)\n"); // make payouts (which will be in the import tx with token): - mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, GetUnspendable(&tokensC, NULL))); // new marker to token cc addr, burnable and validated, vout position now changed to 0 (from 1) + mtx.vout.push_back(MakeCC1vout(EVAL_TOKENS, txfee, tokensC.GetUnspendable())); // new marker to token cc addr, burnable and validated, vout position now changed to 0 (from 1) mtx.vout.push_back(MakeTokensCC1vout(destEvalCode, burnAmount, destPubKey)); std::vector> voprets; diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp index b25485acc18..793447433df 100644 --- a/src/rpc/testtransactions.cpp +++ b/src/rpc/testtransactions.cpp @@ -165,7 +165,7 @@ UniValue test_burntx(const UniValue& params, bool fHelp, const CPubKey& mypk) uint8_t tokenpriv[33]; char unspendableTokenAddr[64]; - CPubKey unspPk = GetUnspendable(&C, tokenpriv); + CPubKey unspPk = C.GetUnspendable(tokenpriv); GetCCaddress(&C, unspendableTokenAddr, unspPk); CCaddr2set(&C, EVAL_TOKENS, unspPk, tokenpriv, unspendableTokenAddr); return(FinalizeCCTx(0, &C, mtx, myPubkey, 10000, EncodeTokenOpRet(tokenid, voutPubkeys, std::make_pair(0, vscript_t())))); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ba428619258..08890f18bf4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5636,7 +5636,7 @@ int32_t ensure_CCrequirements(uint8_t evalcode) UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector &pubkey) { UniValue result(UniValue::VOBJ); char destaddr[64],str[64]; CPubKey mypk,pk; - pk = GetUnspendable(cp,0); + pk = cp->GetUnspendable(); GetCCaddress(cp,destaddr,pk); if ( strcmp(destaddr,cp->unspendableCCaddr) != 0 ) { @@ -6060,7 +6060,7 @@ UniValue pricesaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) result = CCaddress(&C,(char *)"Prices",pubkey); if (mypk.IsValid()) pk=mypk; else pk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(&C,0); + pricespk = C.GetUnspendable(); CCPricesContract_info C2; GetCCaddress(&C2,myaddr,pk); @@ -7269,7 +7269,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp, const CPubKey& mypk) char coinaddr[64]; CTxOut v; CCFaucetContract_info C; - v = MakeCC1vout(EVAL_FAUCET,funds,GetUnspendable(&C,0)); + v = MakeCC1vout(EVAL_FAUCET,funds,C.GetUnspendable()); Getscriptaddress(coinaddr,CScript() << ParseHex(HexStr(pubkey2pk(Mypubkey()))) << OP_CHECKSIG); return(NSPV_spend(coinaddr,(char *)HexStr(v.scriptPubKey.begin()+1,v.scriptPubKey.end()-1).c_str(),funds)); } From 43ec71c7e86c5129cb128f19a58832b6938f0fcc Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 4 Jun 2021 17:01:00 -0500 Subject: [PATCH 2/3] Use CCinit with CCinfos --- src/cc/eval.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 69765730366..25e6418ec48 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -94,11 +94,10 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) else return Invalid("mismatched -ac_cclib vs CClib_name"); } - //NOTE: ecode will be between EVAL_FIRSTUSER and EVAL_LASTUSER std::shared_ptr cp = CCinfos[(int32_t)ecode]; if ( cp == nullptr ) { - cp = std::make_shared(ecode); + cp = CCinit(ecode); } switch ( ecode ) From 3699bd998b9c7b0d77ba5461606ce26419dbaf7f Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 6 Aug 2021 09:33:13 -0500 Subject: [PATCH 3/3] fix missing header --- src/cc/CClib.h | 1 + src/cryptoconditions/src/utils.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/CClib.h b/src/cc/CClib.h index 725c45fda27..18511016e75 100644 --- a/src/cc/CClib.h +++ b/src/cc/CClib.h @@ -1,5 +1,6 @@ #pragma once #include "CCinclude.h" +#include "hex.h" struct CClibContract_info : public CCcontract_info { diff --git a/src/cryptoconditions/src/utils.c b/src/cryptoconditions/src/utils.c index b4d961d6e2c..32454c8e441 100644 --- a/src/cryptoconditions/src/utils.c +++ b/src/cryptoconditions/src/utils.c @@ -216,7 +216,7 @@ void hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp, uint8_t * ASN_STRUCT_FREE(*asnType, fp); if (rc.encoded < 1) { fprintf(stderr, "Encoding fingerprint failed\n"); - return 0; + return; } sha256(buf, rc.encoded, out); }