fixes for import coin

This commit is contained in:
Scott Sadler
2018-06-10 15:12:10 +02:00
parent 7776d00b9a
commit 89cfc4272d
6 changed files with 36 additions and 7 deletions

View File

@@ -57,10 +57,11 @@ bool Eval::ImportCoin(const std::vector<uint8_t> 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");
}

View File

@@ -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<uint256> 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<uint256> leaves, tree;
uint32_t md = np->MoMdepth & 0xffff; // MoMdepth shares space with ccid
for (int i=0; i<md; i++) {
uint256 mRoot = chainActive[np->notarized_height - i]->hashMerkleRoot;
leaves.push_back(mRoot);

View File

@@ -25,7 +25,7 @@ uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth)
{
static uint256 zero; CBlockIndex *pindex; int32_t i; std::vector<uint256> tree, leaves;
bool fMutated;
MoMdepth &= 0xffff;
MoMdepth &= 0xffff; // In case it includes the ccid
if ( MoMdepth >= height )
return(zero);
for (i=0; i<MoMdepth; i++)

View File

@@ -63,19 +63,23 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n)
*/
void WriteBackNotarisations(const NotarisationsInBlock notarisations)
{
CLevelDBBatch batch;
BOOST_FOREACH(const Notarisation &n, notarisations)
{
if (!n.second.txHash.IsNull())
pnotarisations->Write(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);
}

View File

@@ -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));

View File

@@ -29,6 +29,26 @@ TEST(TestParseNotarisation, test__)
ASSERT_FALSE(E_UNMARSHAL(opret, ss >> nd));
}
TEST(TestParseNotarisation, test__a)
{
// be55101e6c5a93fb3611a44bd66217ad8714d204275ea4e691cfff9d65dff85c TXSCL
std::vector<uint8_t> opret = ParseHex("fb9ea2818eec8b07f8811bab49d64379db074db478997f8114666f239bd79803cc460000d0fac4e715b7e2b917a5d79f85ece0c423d27bd3648fd39ac1dc7db8e1bd4b16545853434c00a69eab9f23d7fb63c4624973e7a9079d6ada2f327040936356d7af5e849f6d670a0003001caf7b7b9e1c9bc59d0c7a619c9683ab1dd0794b6f3ea184a19f8fda031150e700000000");
NotarisationData nd(1);
bool res = E_UNMARSHAL(opret, ss >> nd);
ASSERT_TRUE(res);
}
TEST(TestParseNotarisation, test__b)
{
// 03085dafed656aaebfda25bf43ffe9d1fb72565bb1fc8b2a12a631659f28f877 TXSCL
std::vector<uint8_t> 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
}