From f459487cd891f2b2626f504131e68f094b9eeb0d Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 28 Feb 2019 20:59:19 +0500 Subject: [PATCH 1/2] added decoding of old rogue data in token opret --- src/cc/CCtokensOpRet.cpp | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/cc/CCtokensOpRet.cpp b/src/cc/CCtokensOpRet.cpp index edbc59db4..7514f4bb6 100644 --- a/src/cc/CCtokensOpRet.cpp +++ b/src/cc/CCtokensOpRet.cpp @@ -193,6 +193,9 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, ui uint256 dummySrcTokenId; CPubKey voutPubkey1, voutPubkey2; + vscript_t vroguedata; + bool foundRogue = false; + GetOpReturnData(scriptPubKey, vopret); script = (uint8_t *)vopret.data(); tokenid = zeroid; @@ -222,16 +225,28 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, ui case 't': //not used yet: case 'l': // NOTE: 'E_UNMARSHAL result==false' means 'parse error' OR 'not eof state'. Consequently, 'result==false' but 'isEof==true' means just 'parse error' - if (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)); - } - })) + + // compatibility with rogue data: + // try to unmarshal rogue data: + + foundRogue = 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 >> vroguedata; + }) && vroguedata.size() > 2 && vroguedata.begin()[0] == 0x11 /*EVAL_ROGUE*/ && vroguedata.begin()[1] == 'R'; + + if(foundRogue || // fix for compatibility with old rogue 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); @@ -246,6 +261,11 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, ui voutPubkeys.push_back(voutPubkey2); tokenid = revuint256(tokenid); + + if (foundRogue) { + oprets.push_back(std::make_pair(OPRETID_ROGUEGAMEDATA, vroguedata)); + } + return(funcId); } LOGSTREAM((char *)"cctokens", CCLOG_INFO, stream << "DecodeTokenOpRet() bad opret format," << " ccType=" << (int)ccType << " tokenid=" << revuint256(tokenid).GetHex() << std::endl); From e385253b47e87d15b114a4e8bbce4629e19fd59c Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 28 Feb 2019 21:01:46 +0500 Subject: [PATCH 2/2] logging added --- src/cc/CCtokensOpRet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCtokensOpRet.cpp b/src/cc/CCtokensOpRet.cpp index 7514f4bb6..049319527 100644 --- a/src/cc/CCtokensOpRet.cpp +++ b/src/cc/CCtokensOpRet.cpp @@ -263,6 +263,7 @@ uint8_t DecodeTokenOpRet(const CScript scriptPubKey, uint8_t &evalCodeTokens, ui tokenid = revuint256(tokenid); if (foundRogue) { + LOGSTREAM((char *)"cctokens", CCLOG_DEBUG1, stream << "DecodeTokenOpRet() found old-style rogue data" << " for tokenid=" << revuint256(tokenid).GetHex() << std::endl); oprets.push_back(std::make_pair(OPRETID_ROGUEGAMEDATA, vroguedata)); }