From 5c35c03d60c68d9cb1db430c2f9492b4c537144d Mon Sep 17 00:00:00 2001 From: dimxy Date: Mon, 14 Jan 2019 01:27:45 +0500 Subject: [PATCH] added isTokenVout call to Add1of2address func in heir.cpp corrected ExtractTokensVinPubkeys call -> in isTokensVout --- src/cc/CCtokens.cpp | 16 +++++++++++----- src/cc/heir.cpp | 16 +++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index 70aa60d92..9b110992b 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -262,14 +262,17 @@ bool TokensValidate(struct CCcontract_info *cp, Eval* eval, const CTransaction & // helper funcs: // extract my vins pubkeys: -bool ExtractVinPubkeys(struct CCcontract_info *cp, CTransaction tx, std::vector &vinPubkeys) { +bool ExtractTokensVinPubkeys(CTransaction tx, std::vector &vinPubkeys) { bool found = false; CPubKey pubkey; + struct CCcontract_info *cpTokens, tokensC; + + cpTokens = CCinit(&tokensC, EVAL_TOKENS); for (int32_t i = 0; i < tx.vin.size(); i++) { // check for additional contracts which may send tokens to the Tokens contract - if( (*cp->ismyvin)(tx.vin[i].scriptSig) ) + if( (*cpTokens->ismyvin)(tx.vin[i].scriptSig) ) { auto findEval = [](CC *cond, struct CCVisitor _) { @@ -345,7 +348,7 @@ uint8_t ValidateTokenOpret(CTransaction tx, int32_t v, uint256 tokenid, std::vec // goDeeper is true: the func also validates amounts of the passed transaction: // it should be either sum(cc vins) == sum(cc vouts) or the transaction is the 'tokenbase' ('c') tx // checkPubkeys is true: validates if the vout is token vout1 or token vout1of2. Should always be true! -int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys) +int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *cp, Eval* eval, /*std::vector &vopretExtra,*/ const CTransaction& tx, int32_t v, uint256 reftokenid, std::vector vinPubkeys000) { // this is just for log messages indentation fur debugging recursive calls: @@ -421,6 +424,9 @@ int64_t IsTokensvout(bool goDeeper, bool checkPubkeys, struct CCcontract_info *c } // maybe it is token change? + std::vector vinPubkeys; + ExtractTokensVinPubkeys(tx, vinPubkeys); + for(std::vector::iterator it = vinPubkeys.begin(); it != vinPubkeys.end(); it++) { CTxOut testVout = MakeTokensCC1vout(evalCodeInOpret, tx.vout[v].nValue, *it); @@ -450,7 +456,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t //int32_t flag; int64_t tokenoshis; // std::vector tmporigpubkey; int64_t tmpprice; - std::vector vinPubkeys, vinPubkeysEmpty; + std::vector vinPubkeys; int32_t numvins = tx.vin.size(); int32_t numvouts = tx.vout.size(); @@ -459,7 +465,7 @@ bool TokensExactAmounts(bool goDeeper, struct CCcontract_info *cpTokens, int64_t // this is just for log messages indentation for debugging recursive calls: std::string indentStr = std::string().append(tokenValIndentSize, '.'); - ExtractVinPubkeys(cpTokens, tx, vinPubkeys); + ExtractTokensVinPubkeys(tx, vinPubkeys); for (int32_t i = 0; i int64_t Add1of2AddressInputs(struct CCcontract_info* cp, if (GetTransaction(txid, heirtx, hashBlock, false) != 0) { uint256 tokenid; uint256 fundingTxidInOpret; - uint8_t dummyHasHeirSpendingBegun; - uint8_t evalCodeTokens = 0; - std::vector vopretExtra; - std::vector voutPubkeys; + uint8_t hasHeirSpendingBegunDummy; + std::vector vinPubkeysEmpty; - CScript heirScript = heirtx.vout[heirtx.vout.size() - 1].scriptPubKey; - uint8_t funcId = DecodeTokenOpRet(heirScript, evalCodeTokens, tokenid, voutPubkeys, vopretExtra); - if (funcId != 0) { - heirScript = CScript(vopretExtra); - } - funcId = DecodeHeirOpRet(heirScript, fundingTxidInOpret, dummyHasHeirSpendingBegun, true); + CScript heirScript = (heirtx.vout.size() > 0) ? heirtx.vout[heirtx.vout.size() - 1].scriptPubKey : CScript(); + uint8_t funcId = DecodeHeirEitherOpRet(heirScript, tokenid, fundingTxidInOpret, hasHeirSpendingBegunDummy, false); if ((txid == fundingtxid || fundingTxidInOpret == fundingtxid) && funcId != 0 && isMyFuncId(funcId) && - // (typeid(Helper) == typeid(TokenHelper) && IsHeirvout(true, cp, nullptr, tokenid, vintx, voutIndex) > 0) && // deep validation for tokens - not used anymore + (typeid(Helper) == typeid(TokenHelper) && IsTokensvout(true, true, cp, nullptr, heirtx, voutIndex, tokenid, vinPubkeysEmpty) > 0) && // deep validation for tokens - not used anymore (voutValue = IsHeirFundingVout(cp, heirtx, voutIndex, ownerPubkey, heirPubkey)) > 0 && !myIsutxo_spentinmempool(txid, voutIndex)) {