From 89cfc4272dd6c3a3a7f1a70e6b144b6aea193ccf Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 10 Jun 2018 15:12:10 +0200 Subject: [PATCH] fixes for import coin --- src/cc/import.cpp | 3 ++- src/crosschain.cpp | 7 ++++--- src/komodo_ccdata.h | 2 +- src/notarisationdb.cpp | 8 ++++++-- src/rpcrawtransaction.cpp | 3 +++ src/test-komodo/test_parse_notarisation.cpp | 20 ++++++++++++++++++++ 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 506b2a989..5f0b804e8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -57,10 +57,11 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // Check proof confirms existance of burnTx { - uint256 momom; + uint256 momom, target; if (!GetProofRoot(proof.first, momom)) return Invalid("coudnt-load-momom"); + target = proof.second.Exec(burnTx.GetHash()); if (momom != proof.second.Exec(burnTx.GetHash())) return Invalid("momom-check-fail"); } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 94959544b..dd352b025 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -148,7 +148,7 @@ void CompleteImportTransaction(CTransaction &importTx) proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); - importTx = MakeImportCoinTransaction(proof, burnTx, importTx.vout); + importTx = MakeImportCoinTransaction(proof, burnTx, payouts); } @@ -187,7 +187,7 @@ struct notarized_checkpoint* komodo_npptr(int32_t height); */ TxProof GetAssetchainProof(uint256 hash) { - int nIndex; + int nIndex, md; CBlockIndex* blockIndex; struct notarized_checkpoint* np; std::vector branch; @@ -207,12 +207,13 @@ TxProof GetAssetchainProof(uint256 hash) // index of block in MoM leaves nIndex = np->notarized_height - blockIndex->nHeight; + // MoMdepth shares space with ccid + md = np->MoMdepth & 0xffff; } // build merkle chain from blocks to MoM { std::vector leaves, tree; - uint32_t md = np->MoMdepth & 0xffff; // MoMdepth shares space with ccid for (int i=0; inotarized_height - i]->hashMerkleRoot; leaves.push_back(mRoot); diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 6fd065953..012183fc7 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -25,7 +25,7 @@ uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth) { static uint256 zero; CBlockIndex *pindex; int32_t i; std::vector tree, leaves; bool fMutated; - MoMdepth &= 0xffff; + MoMdepth &= 0xffff; // In case it includes the ccid if ( MoMdepth >= height ) return(zero); for (i=0; iWrite(n.second.txHash, n); + batch.Write(n.second.txHash, n); } + pnotarisations->WriteBatch(batch, true); } void EraseBackNotarisations(const NotarisationsInBlock notarisations) { + CLevelDBBatch batch; BOOST_FOREACH(const Notarisation &n, notarisations) { if (!n.second.txHash.IsNull()) - pnotarisations->Erase(n.second.txHash); + batch.Erase(n.second.txHash); } + pnotarisations->WriteBatch(batch, true); } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 5f349096a..91dff8bf9 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -134,6 +134,9 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); + else if (tx.IsCoinImport()) { + in.push_back(Pair("is_import", "1")); + } else { in.push_back(Pair("txid", txin.prevout.hash.GetHex())); in.push_back(Pair("vout", (int64_t)txin.prevout.n)); diff --git a/src/test-komodo/test_parse_notarisation.cpp b/src/test-komodo/test_parse_notarisation.cpp index a61ca2aa3..2910e2f96 100644 --- a/src/test-komodo/test_parse_notarisation.cpp +++ b/src/test-komodo/test_parse_notarisation.cpp @@ -29,6 +29,26 @@ TEST(TestParseNotarisation, test__) ASSERT_FALSE(E_UNMARSHAL(opret, ss >> nd)); } +TEST(TestParseNotarisation, test__a) +{ + // be55101e6c5a93fb3611a44bd66217ad8714d204275ea4e691cfff9d65dff85c TXSCL + std::vector opret = ParseHex("fb9ea2818eec8b07f8811bab49d64379db074db478997f8114666f239bd79803cc460000d0fac4e715b7e2b917a5d79f85ece0c423d27bd3648fd39ac1dc7db8e1bd4b16545853434c00a69eab9f23d7fb63c4624973e7a9079d6ada2f327040936356d7af5e849f6d670a0003001caf7b7b9e1c9bc59d0c7a619c9683ab1dd0794b6f3ea184a19f8fda031150e700000000"); + NotarisationData nd(1); + bool res = E_UNMARSHAL(opret, ss >> nd); + ASSERT_TRUE(res); +} + +TEST(TestParseNotarisation, test__b) +{ + // 03085dafed656aaebfda25bf43ffe9d1fb72565bb1fc8b2a12a631659f28f877 TXSCL + std::vector opret = ParseHex("48c71a10aa060eab1a43f52acefac3b81fb2a2ce310186b06141884c0501d403c246000052e6d49afd82d9ab3d97c996dd9b6a78a554ffa1625e8dadf0494bd1f8442e3e545853434c007cc5c07e3b67520fd14e23cd5b49f2aa022f411500fd3326ff91e6dc0544a1c90c0003008b69117bb1376ac8df960f785d8c208c599d3a36248c98728256bb6d4737e59600000000"); + NotarisationData nd(1); + bool res = E_UNMARSHAL(opret, ss >> nd); + ASSERT_TRUE(res); +} + + + // for l in `g 'parse notarisation' ~/.komodo/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/komodo-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done }