2 #include "notarisationdb.h"
7 #include <boost/foreach.hpp>
10 NotarisationDB *pnotarisations;
13 NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) { }
16 NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight)
19 NotarisationsInBlock vNotarisations;
21 for (unsigned int i = 0; i < block.vtx.size(); i++) {
22 CTransaction tx = block.vtx[i];
24 // Special case for TXSCL. Should prob be removed at some point.
27 NotarisationData data;
28 if (ParseNotarisationOpReturn(tx, data))
29 if (IsTXSCL(data.symbol))
33 if (isTxscl || eval->CheckNotaryInputs(tx, nHeight, block.nTime)) {
34 NotarisationData data;
35 if (ParseNotarisationOpReturn(tx, data)) {
36 vNotarisations.push_back(std::make_pair(tx.GetHash(), data));
37 //printf("Parsed a notarisation for: %s, txid:%s, ccid:%i, momdepth:%i\n",
38 // data.symbol, tx.GetHash().GetHex().data(), data.ccId, data.MoMDepth);
39 //if (!data.MoMoM.IsNull()) printf("MoMoM:%s\n", data.MoMoM.GetHex().data());
42 LogPrintf("WARNING: Couldn't parse notarisation for tx: %s at height %i\n",
43 tx.GetHash().GetHex().data(), nHeight);
46 return vNotarisations;
49 bool IsTXSCL(const char* symbol)
51 return strlen(symbol) >= 5 && strncmp(symbol, "TXSCL", 5) == 0;
55 bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs)
57 return pnotarisations->Read(blockHash, nibs);
61 bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n)
63 return pnotarisations->Read(notarisationHash, n);
68 * Write an index of KMD notarisation id -> backnotarisation
70 void WriteBackNotarisations(const NotarisationsInBlock notarisations, CDBBatch &batch)
73 BOOST_FOREACH(const Notarisation &n, notarisations)
75 if (!n.second.txHash.IsNull()) {
76 batch.Write(n.second.txHash, n);
83 void EraseBackNotarisations(const NotarisationsInBlock notarisations, CDBBatch &batch)
85 BOOST_FOREACH(const Notarisation &n, notarisations)
87 if (!n.second.txHash.IsNull())
88 batch.Erase(n.second.txHash);
93 * Scan notarisationsdb backwards for blocks containing a notarisation
94 * for given symbol. Return height of matched notarisation or 0.
96 int ScanNotarisationsDB(int height, std::string symbol, int scanLimitBlocks, Notarisation& out)
98 if (height < 0 || height > chainActive.Height())
101 for (int i=0; i<scanLimitBlocks; i++) {
102 if (i > height) break;
103 NotarisationsInBlock notarisations;
104 uint256 blockHash = *chainActive[height-i]->phashBlock;
105 if (!GetBlockNotarisations(blockHash, notarisations))
108 BOOST_FOREACH(Notarisation& nota, notarisations) {
109 if (strcmp(nota.second.symbol, symbol.data()) == 0) {