diff --git a/include/docs.hpp b/include/docs.hpp index 4cef01c..d878651 100644 --- a/include/docs.hpp +++ b/include/docs.hpp @@ -23,26 +23,26 @@ namespace hypha // Any account/member can creator a new document ACTION create(eosio::name & creator, ContentGroups & content_groups); - ACTION createroot(const std::string ¬es); + // ACTION createroot(const std::string ¬es); - ACTION getornewget(const name &creator, ContentGroups &content_groups); - ACTION getornewnew(const name &creator, ContentGroups &content_groups); + // ACTION getornewget(const name &creator, ContentGroups &content_groups); + // ACTION getornewnew(const name &creator, ContentGroups &content_groups); - ACTION newedge(eosio::name & creator, const checksum256 &from_node, const checksum256 &to_node, const name &edge_name); + // ACTION newedge(eosio::name & creator, const checksum256 &from_node, const checksum256 &to_node, const name &edge_name); - ACTION removeedge(const checksum256 &from_node, const checksum256 &to_node, const name &edge_name); + // ACTION removeedge(const checksum256 &from_node, const checksum256 &to_node, const name &edge_name); - ACTION erase(const checksum256 &hash); + // ACTION erase(const checksum256 &hash); - ACTION testgetasset(const checksum256 &hash, - const std::string &groupLabel, - const std::string &contentLabel, - const asset &contentValue); + // ACTION testgetasset(const checksum256 &hash, + // const std::string &groupLabel, + // const std::string &contentLabel, + // const asset &contentValue); - ACTION testgetgroup(const checksum256 &hash, - const std::string &groupLabel); + // ACTION testgetgroup(const checksum256 &hash, + // const std::string &groupLabel); - ACTION testcntnterr(string test); + // ACTION testcntnterr(string test); // // Fork creates a new document (node in a graph) from an existing document. // // The forked content should contain only new or updated entries to avoid data duplication. (lazily enforced?) diff --git a/include/document_graph/document.hpp b/include/document_graph/document.hpp index f625787..247513b 100644 --- a/include/document_graph/document.hpp +++ b/include/document_graph/document.hpp @@ -26,15 +26,11 @@ namespace hypha Document(eosio::name contract, eosio::name creator, const std::string &label, const Content::FlexValue &value); // this constructor reads the hash from the table and populates the object from storage - Document(eosio::name contract, uint64_t id); + Document(eosio::name contract, const uint64_t &id); ~Document(); - // actual sha256 of "DO_NOT_HASH" is d15ddfec8899ee7bf14aea64c77719d99101ae034fadd02e455476d59a8ec0f9 - // when the document.hash value is set to this, the document contents is never hashed - // need to hardcode that to this constant - const eosio::checksum256 DO_NOT_HASH = eosio::fixed_bytes<32UL>{}; - void emplace(); + void modify(); /** * @brief Updates the document in the multi_index table with the given content groups @@ -43,12 +39,9 @@ namespace hypha */ void update(const eosio::name &updater, ContentGroups updatedData); - static bool exists(eosio::name contract, uint64_t _id); - - // certificates are not yet used - void certify(const eosio::name &certifier, const std::string ¬es); + static bool exists(eosio::name contract, const uint64_t &documentId); - // static helpers + // static helpers static ContentGroups rollup(ContentGroup contentGroup); static ContentGroups rollup(Content content); static void insertOrReplace(ContentGroup &contentGroup, Content &newContent); @@ -59,8 +52,10 @@ namespace hypha ContentWrapper getContentWrapper() { return ContentWrapper(content_groups); } ContentGroups &getContentGroups() { return content_groups; } const ContentGroups &getContentGroups() const { return content_groups; } - const eosio::checksum256 &getHash() const { return hash; } + + const std::uint64_t &getId() const { return id; } const eosio::time_point &getCreated() const { return created_date; } + const eosio::time_point &getUpdated() const { return updated_date; } const eosio::name &getCreator() const { return creator; } const eosio::name &getContract() const { return contract; } @@ -70,18 +65,29 @@ namespace hypha uint64_t by_updated() const { return updated_date.sec_since_epoch(); } uint64_t by_creator() const { return creator.value; } - eosio::checksum256 by_hash() const { return hash; } - - inline uint64_t getID() { return id; } - + // TODO: this should be implemented in HashDocument preferably, but I dunno how + // to do that whilst also impacting the ABI correctly :| (help!) + eosio::checksum256 by_hash() const + { + auto cgs = getContentGroups(); + ContentWrapper cw (cgs); + if (const auto [_, hash] = cw.get("DETAILS", "HASH"); hash) + { + return std::get(hash->value); + } + // default value, for cases where hash is not used, would be all zeros + return eosio::checksum256{}; + } private: // members, with names as serialized - these must be public for EOSIO tables std::uint64_t id; - eosio::checksum256 hash = DO_NOT_HASH; eosio::name creator; ContentGroups content_groups; eosio::time_point created_date; eosio::time_point updated_date; + + // I think we should remove this- it shouldn't be saved + // because it can be derived and it wastes 64-bytes per document eosio::name contract; // toString iterates through all content, all levels, concatenating all values @@ -90,18 +96,18 @@ namespace hypha static const std::string toString(const ContentGroups &contentGroups); static const std::string toString(const ContentGroup &contentGroup); - EOSLIB_SERIALIZE(Document, (id)(hash)(creator)(content_groups)(created_date)(updated_date)(contract)) + EOSLIB_SERIALIZE(Document, (id)(creator)(content_groups)(updated_date)(created_date)(contract)) public: // for unknown reason, primary_key() must be public uint64_t primary_key() const { return id; } typedef eosio::multi_index>, + eosio::indexed_by>, eosio::indexed_by>, eosio::indexed_by>, eosio::indexed_by>> - document_table; }; + } // namespace hypha \ No newline at end of file diff --git a/include/document_graph/document_graph.hpp b/include/document_graph/document_graph.hpp index 94e5c4c..d1f98fa 100644 --- a/include/document_graph/document_graph.hpp +++ b/include/document_graph/document_graph.hpp @@ -57,7 +57,8 @@ using contract_document = contract##_document;\ using document_table = eosio::multi_index>,\ eosio::indexed_by>,\ - eosio::indexed_by>>;\ + eosio::indexed_by>,\ + eosio::indexed_by>>;\ using root_edge = hypha::Edge;\ TABLE contract##_edge : public root_edge {};\ using contract_edge = contract##_edge;\ diff --git a/include/document_graph/hash_document.hpp b/include/document_graph/hash_document.hpp index 2f5099f..5ffe23f 100644 --- a/include/document_graph/hash_document.hpp +++ b/include/document_graph/hash_document.hpp @@ -14,18 +14,15 @@ namespace hypha HashDocument(eosio::name *contract, const eosio::checksum256 &hash); // returns a document, saves to RAM if it doesn't already exist - static HashDocument getOrNew(eosio::name contract, eosio::name creator, ContentGroups contentGroups); - static HashDocument getOrNew(eosio::name contract, eosio::name creator, ContentGroup contentGroup); - static HashDocument getOrNew(eosio::name contract, eosio::name creator, Content content); - static HashDocument getOrNew(eosio::name contract, eosio::name creator, const std::string &label, const Content::FlexValue &value); + // static HashDocument getOrNew(eosio::name contract, eosio::name creator, ContentGroups contentGroups); + // static HashDocument getOrNew(eosio::name contract, eosio::name creator, ContentGroup contentGroup); + // static HashDocument getOrNew(eosio::name contract, eosio::name creator, Content content); + // static HashDocument getOrNew(eosio::name contract, eosio::name creator, const std::string &label, const Content::FlexValue &value); + void update(const eosio::name& updater, ContentGroups updatedData); static bool exists(eosio::name contract, const eosio::checksum256 &hash); const void hashContents(); static const eosio::checksum256 hashContents(const ContentGroups &contentGroups); - - bool isHash(); - std::string getLabel(); - std::string getReadable(); }; } // namespace hypha \ No newline at end of file diff --git a/src/docs.cpp b/src/docs.cpp index c858856..145e677 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -11,83 +11,83 @@ namespace hypha Document document(get_self(), creator, content_groups); } - void docs::getornewget(const name &creator, ContentGroups &content_groups) - { - Document document = Document::getOrNew(get_self(), creator, content_groups); - eosio::check(document.getCreated().sec_since_epoch() > 0, "created new instead of reading from existing"); - } + // void docs::getornewget(const name &creator, ContentGroups &content_groups) + // { + // Document document = Document::getOrNew(get_self(), creator, content_groups); + // eosio::check(document.getCreated().sec_since_epoch() > 0, "created new instead of reading from existing"); + // } - void docs::getornewnew(const name &creator, ContentGroups &content_groups) - { - bool docExists = Document::exists(get_self(), Document::hashContents(content_groups)); - check(!docExists, "document already exists"); + // void docs::getornewnew(const name &creator, ContentGroups &content_groups) + // { + // bool docExists = Document::exists(get_self(), Document::hashContents(content_groups)); + // check(!docExists, "document already exists"); - Document document = Document::getOrNew(get_self(), creator, content_groups); - eosio::check(document.getCreated().sec_since_epoch() > 0, "created_date not populated when saved"); - } + // Document document = Document::getOrNew(get_self(), creator, content_groups); + // eosio::check(document.getCreated().sec_since_epoch() > 0, "created_date not populated when saved"); + // } - void docs::newedge(name &creator, const checksum256 &from_node, const checksum256 &to_node, const name &edge_name) - { - Edge edge(get_self(), creator, from_node, to_node, edge_name); - } + // void docs::newedge(name &creator, const checksum256 &from_node, const checksum256 &to_node, const name &edge_name) + // { + // Edge edge(get_self(), creator, from_node, to_node, edge_name); + // } - void docs::removeedge(const checksum256 &from_node, const checksum256 &to_node, const name &edge_name) - { - Edge edge = Edge::get(get_self(), from_node, to_node, edge_name); - edge.erase(); - } + // void docs::removeedge(const checksum256 &from_node, const checksum256 &to_node, const name &edge_name) + // { + // Edge edge = Edge::get(get_self(), from_node, to_node, edge_name); + // edge.erase(); + // } - void docs::erase(const checksum256 &hash) - { - DocumentGraph dg(get_self()); - dg.eraseDocument(hash); - } + // void docs::erase(const checksum256 &hash) + // { + // DocumentGraph dg(get_self()); + // dg.eraseDocument(hash); + // } - void docs::testgetasset(const checksum256 &hash, - const std::string &groupLabel, - const std::string &contentLabel, - const asset &contentValue) - { - Document document(get_self(), hash); + // void docs::testgetasset(const checksum256 &hash, + // const std::string &groupLabel, + // const std::string &contentLabel, + // const asset &contentValue) + // { + // Document document(get_self(), hash); - eosio::print(" testgetasset:: looking for groupLabel: " + groupLabel + "\n"); - eosio::print(" testgetasset:: looking for contentLabel: " + contentLabel + "\n"); - asset readValue = document.getContentWrapper().getOrFail(groupLabel, contentLabel, "contentGroup or contentLabel does not exist")->getAs(); + // eosio::print(" testgetasset:: looking for groupLabel: " + groupLabel + "\n"); + // eosio::print(" testgetasset:: looking for contentLabel: " + contentLabel + "\n"); + // asset readValue = document.getContentWrapper().getOrFail(groupLabel, contentLabel, "contentGroup or contentLabel does not exist")->getAs(); - eosio::check(readValue == contentValue, "read value does not equal content value. read value: " + - readValue.to_string() + " expected value: " + contentValue.to_string()); - eosio::print(" testgetasset:: asset found: " + readValue.to_string() + "\n"); - } + // eosio::check(readValue == contentValue, "read value does not equal content value. read value: " + + // readValue.to_string() + " expected value: " + contentValue.to_string()); + // eosio::print(" testgetasset:: asset found: " + readValue.to_string() + "\n"); + // } - void docs::testgetgroup(const checksum256 &hash, - const std::string &groupLabel) - { - Document document(get_self(), hash); - eosio::print(" testgetasset:: looking for groupLabel: " + groupLabel + "\n"); + // void docs::testgetgroup(const checksum256 &hash, + // const std::string &groupLabel) + // { + // Document document(get_self(), hash); + // eosio::print(" testgetasset:: looking for groupLabel: " + groupLabel + "\n"); - auto [idx, contentGroup] = document.getContentWrapper().getGroup(groupLabel); - check(idx > -1, "group was not found"); - } + // auto [idx, contentGroup] = document.getContentWrapper().getGroup(groupLabel); + // check(idx > -1, "group was not found"); + // } - void docs::testcntnterr(string test) - { - ContentGroups cgs{ - ContentGroup{ - Content{CONTENT_GROUP_LABEL, "test"}, - Content{"test_label", string("hello world")} - } - }; - ContentWrapper cw(cgs); - - cw.getOrFail("test", "test_label")->getAs(); - } + // void docs::testcntnterr(string test) + // { + // ContentGroups cgs{ + // ContentGroup{ + // Content{CONTENT_GROUP_LABEL, "test"}, + // Content{"test_label", string("hello world")} + // } + // }; + // ContentWrapper cw(cgs); + + // cw.getOrFail("test", "test_label")->getAs(); + // } - void docs::createroot(const std::string ¬es) - { - require_auth(get_self()); + // void docs::createroot(const std::string ¬es) + // { + // require_auth(get_self()); - Document rootDoc(get_self(), get_self(), Content("root_node", get_self())); - } + // Document rootDoc(get_self(), get_self(), Content("root_node", get_self())); + // } // void docs::fork (const checksum256 &hash, const name &creator, const vector &content_groups ) // { diff --git a/src/document_graph/document.cpp b/src/document_graph/document.cpp index 85ba55c..e02786f 100644 --- a/src/document_graph/document.cpp +++ b/src/document_graph/document.cpp @@ -9,7 +9,6 @@ namespace hypha { - Document::~Document() {} Document::Document() {} @@ -34,30 +33,26 @@ namespace hypha { } - Document::Document(eosio::name contract, uint64_t _id) : contract{contract} + Document::Document(eosio::name contract, const uint64_t &documentId) : contract{contract} { TRACE_FUNCTION() document_table d_t(contract, contract.value); - auto h_itr = d_t.find(_id); - - EOS_CHECK( - h_itr != d_t.end(), - util::to_str("document not found: ", _id) - ); - - id = h_itr->id; - creator = h_itr->creator; - created_date = h_itr->created_date; - content_groups = h_itr->content_groups; + auto d_itr = d_t.find(documentId); + EOS_CHECK(d_itr != d_t.end(), "document not found: " + std::to_string(documentId)); + + id = d_itr->id; + creator = d_itr->creator; + created_date = d_itr->created_date; + updated_date = eosio::current_time_point(); + content_groups = d_itr->content_groups; } - bool Document::exists(eosio::name contract, uint64_t _id) + bool Document::exists(eosio::name contract, const uint64_t &documentId) { document_table d_t(contract, contract.value); - - auto h_itr = d_t.find(_id); + auto d_itr = d_t.find(documentId); - if (h_itr != d_t.end()) + if (d_itr != d_t.end()) { return true; } @@ -69,57 +64,34 @@ namespace hypha TRACE_FUNCTION() document_table d_t(getContract(), getContract().value); - d_t.emplace(getContract(), [&](auto &d) { - id = d_t.available_primary_key(); - created_date = eosio::current_time_point(); - d = *this; - }); + + d_t.emplace(getContract(), [&](auto &d) + { + id = d_t.available_primary_key(); + created_date = eosio::current_time_point(); + updated_date = eosio::current_time_point(); + d = *this; + }); } - void Document::update(const eosio::name& updater, ContentGroups updatedData) + void Document::modify() { - TRACE_FUNCTION(); - - auto oldHash = hash; - - creator = updater; - - content_groups = std::move(updatedData); - - hashContents(); + TRACE_FUNCTION() document_table d_t(getContract(), getContract().value); - auto hash_index = d_t.get_index(); - - { - auto h_itr = hash_index.find(hash); - - // if this content exists already, error out and send back the hash of the existing document - EOS_CHECK( - h_itr == hash_index.end(), - util::to_str("There is an existing document with hash: ", hash, " Previous hash: ", oldHash) - ) - } - - auto it = d_t.find(id); + auto d_itr = d_t.find(getId()); - EOS_CHECK( - it != d_t.end(), - util::to_str("Couldn't find document in table with id: ", id) - ) + EOS_CHECK(d_itr != d_t.end(), "document does not exist: " + std::to_string(getId())); - d_t.modify(it, getContract(), [&](Document& doc) { - doc = *this; - }); + require_auth(d_itr->creator); - EOS_CHECK( - it->hash == hash, - util::to_str("Coundn't update document") - ); + d_t.modify(d_itr, getContract(), [&](auto &d) + { + updated_date = eosio::current_time_point(); + d = *this; + }); } - - // void Document::certify(const eosio::name &certifier, const std::string ¬es) // { // // check if document is already saved?? @@ -136,22 +108,23 @@ namespace hypha // }); // } - const void Document::hashContents() + ContentGroups Document::rollup(ContentGroup contentGroup) { - // save/cache the hash in the member - hash = hashContents(content_groups); + ContentGroups contentGroups; + contentGroups.push_back(contentGroup); + return contentGroups; } - const std::string Document::toString() + ContentGroups Document::rollup(Content content) { - return toString(content_groups); + ContentGroup contentGroup; + contentGroup.push_back(content); + return rollup(contentGroup); } - // static version cannot cache the hash in a member - const eosio::checksum256 Document::hashContents(const ContentGroups &contentGroups) + const std::string Document::toString() { - std::string string_data = toString(contentGroups); - return eosio::sha256(const_cast(string_data.c_str()), string_data.length()); + // return toString(content_groups); } const std::string Document::toString(const ContentGroups &contentGroups) @@ -198,20 +171,6 @@ namespace hypha return results; } - ContentGroups Document::rollup(ContentGroup contentGroup) - { - ContentGroups contentGroups; - contentGroups.push_back(contentGroup); - return contentGroups; - } - - ContentGroups Document::rollup(Content content) - { - ContentGroup contentGroup; - contentGroup.push_back(content); - return rollup(contentGroup); - } - /** Example * Original Doc { * content_groups: [ @@ -271,71 +230,83 @@ namespace hypha */ Document Document::merge(Document original, Document &deltas) { - TRACE_FUNCTION() - const auto& deltasGroups = deltas.getContentGroups(); - auto& originalGroups = original.getContentGroups(); - auto deltasWrapper = deltas.getContentWrapper(); - auto originalWrapper = original.getContentWrapper(); - - //unordered_map not available with eosio atm - std::map> groupsByLabel; - - for (size_t i = 0; i < originalGroups.size(); ++i) { - auto label = ContentWrapper::getGroupLabel(originalGroups[i]); - if (!label.empty()) { - groupsByLabel[string(label)] = std::pair{i, &originalGroups[i]}; - } - } - - for (size_t i = 0; i < deltasGroups.size(); ++i) { - - auto label = ContentWrapper::getGroupLabel(deltasGroups[i]); - - //If there is no group label just append it to the original doc - if (label.empty()) { - originalGroups.push_back(deltasGroups[i]); - continue; - } - - //Check if we need to delete the group - if (auto [idx, c] = deltasWrapper.get(i, "delete_group"); - c) { - originalWrapper.removeGroup(string(label)); - continue; - } + TRACE_FUNCTION() + const auto &deltasGroups = deltas.getContentGroups(); + auto &originalGroups = original.getContentGroups(); + auto deltasWrapper = deltas.getContentWrapper(); + auto originalWrapper = original.getContentWrapper(); - //Check if we need to skip this group from merge - if (auto [_, c] = deltasWrapper.get(i, "skip_from_merge"); - c) { - continue; - } - - //If group is not present on original document we should append it - if (auto groupIt = groupsByLabel.find(string(label)); - groupIt == groupsByLabel.end()) { - originalGroups.push_back(deltasGroups[i]); + //unordered_map not available with eosio atm + std::map> groupsByLabel; + + for (size_t i = 0; i < originalGroups.size(); ++i) + { + auto label = ContentWrapper::getGroupLabel(originalGroups[i]); + if (!label.empty()) + { + groupsByLabel[string(label)] = std::pair{i, &originalGroups[i]}; + } } - else { - auto [oriGroupIdx, oriGroup] = groupIt->second; - - //It doesn't matter if it replaces content_group_label as they should be equal - for (auto& deltaContent : deltasGroups[i]) { - // Proposed fix is to use ballot_title & ballot_description as - // a separated item - // if (deltaContent.label == "title") { - // // TODO: fix hack: we need to separate 'ballot title' from the assignment/document title - // continue; - // } - if (std::holds_alternative(deltaContent.value)) { - originalWrapper.removeContent(oriGroupIdx, deltaContent.label); + + for (size_t i = 0; i < deltasGroups.size(); ++i) + { + + auto label = ContentWrapper::getGroupLabel(deltasGroups[i]); + + //If there is no group label just append it to the original doc + if (label.empty()) + { + originalGroups.push_back(deltasGroups[i]); + continue; + } + + //Check if we need to delete the group + if (auto [idx, c] = deltasWrapper.get(i, "delete_group"); + c) + { + originalWrapper.removeGroup(string(label)); + continue; } - else { - originalWrapper.insertOrReplace(oriGroupIdx, deltaContent); + + //Check if we need to skip this group from merge + if (auto [_, c] = deltasWrapper.get(i, "skip_from_merge"); + c) + { + continue; + } + + //If group is not present on original document we should append it + if (auto groupIt = groupsByLabel.find(string(label)); + groupIt == groupsByLabel.end()) + { + originalGroups.push_back(deltasGroups[i]); + } + else + { + auto [oriGroupIdx, oriGroup] = groupIt->second; + + //It doesn't matter if it replaces content_group_label as they should be equal + for (auto &deltaContent : deltasGroups[i]) + { + // Proposed fix is to use ballot_title & ballot_description as + // a separated item + // if (deltaContent.label == "title") { + // // TODO: fix hack: we need to separate 'ballot title' from the assignment/document title + // continue; + // } + if (std::holds_alternative(deltaContent.value)) + { + originalWrapper.removeContent(oriGroupIdx, deltaContent.label); + } + else + { + originalWrapper.insertOrReplace(oriGroupIdx, deltaContent); + } + } } - } } - } - return original; + return original; } + } // namespace hypha diff --git a/src/document_graph/document_graph.cpp b/src/document_graph/document_graph.cpp index 6bf773d..1f026bb 100644 --- a/src/document_graph/document_graph.cpp +++ b/src/document_graph/document_graph.cpp @@ -165,12 +165,12 @@ namespace hypha } Document DocumentGraph::updateDocument(const eosio::name &updater, - uint64_t documentHash, + uint64_t documentId, ContentGroups contentGroups) { TRACE_FUNCTION() - Document currentDoc(m_contract, documentHash); + Document currentDoc(m_contract, documentId); currentDoc.update(updater, std::move(contentGroups)); @@ -178,27 +178,27 @@ namespace hypha } // for now, permissions should be handled in the contract action rather than this class - void DocumentGraph::eraseDocument(uint64_t documentID, const bool includeEdges) + void DocumentGraph::eraseDocument(uint64_t documentId, const bool includeEdges) { Document::document_table d_t(m_contract, m_contract.value); - auto h_itr = d_t.find(documentID); + auto h_itr = d_t.find(documentId); EOS_CHECK( h_itr != d_t.end(), - util::to_str("Cannot erase document; does not exist: ", documentID) + util::to_str("Cannot erase document; does not exist: ", documentId) ); if (includeEdges) { - removeEdges(documentID); + removeEdges(documentId); } d_t.erase(h_itr); } - void DocumentGraph::eraseDocument(uint64_t documentID) + void DocumentGraph::eraseDocument(uint64_t documentId) { TRACE_FUNCTION() - return eraseDocument(documentID, true); + return eraseDocument(documentId, true); } } // namespace hypha \ No newline at end of file diff --git a/src/document_graph/hash_document.cpp b/src/document_graph/hash_document.cpp index 4bf1c4a..867b635 100644 --- a/src/document_graph/hash_document.cpp +++ b/src/document_graph/hash_document.cpp @@ -4,46 +4,45 @@ namespace hypha { HashDocument::HashDocument(eosio::name contract, eosio::name creator, ContentGroups contentGroups) - : Document(contract, creator, contentGroups) + : Document(contract, creator, contentGroups) { - // run the hashing steps - hashContents(); + // run the hashing steps + // hashContents(); } HashDocument::HashDocument(eosio::name *contract, const eosio::checksum256 &hash) { // look up the document by the hash index - document_table d_t(getContract(), getContract().value); - auto hash_index = d_t.get_index(); - auto h_itr = hash_index.find(hash); - EOS_CHECK(h_itr != hash_index.end(), "document not found: " + readableHash(hash)); - - // convert the found hashed document to an integer and load - Document (*contract, h_itr->id); - // this should never happen, only if hash algorithm somehow changed - EOS_CHECK(hash == hash, "fatal error: provided and indexed hash does not match newly generated hash"); - + // document_table d_t(getContract(), getContract().value); + // auto hash_index = d_t.get_index(); + // auto h_itr = hash_index.find(hash); + // EOS_CHECK(h_itr != hash_index.end(), "document not found: " + readableHash(hash)); + + // // convert the found hashed document to an integer and load + // Document (*contract, h_itr->id); + // // this should never happen, only if hash algorithm somehow changed + // EOS_CHECK(hash == hash, "fatal error: provided and indexed hash does not match newly generated hash"); } - HashDocument HashDocument::getOrNew(eosio::name _contract, eosio::name _creator, ContentGroups contentGroups) + HashDocument HashDocument::getOrNew(eosio::name _contract, eosio::name _creator, ContentGroups contentGroups) { - HashDocument document{}; - document.content_groups = contentGroups; - document.hashContents(); - - Document::document_table d_t(_contract, _contract.value); - auto hash_index = d_t.get_index(); - auto h_itr = hash_index.find(document.hash); - - // if this content exists already, return this one - if (h_itr != hash_index.end()) - { - document.contract = _contract; - document.creator = h_itr->creator; - document.created_date = h_itr->created_date; - document.id = h_itr->id; - return document; - } + // HashDocument document{}; + // document.content_groups = contentGroups; + // document.hashContents(); + + // Document::document_table d_t(_contract, _contract.value); + // auto hash_index = d_t.get_index(); + // auto h_itr = hash_index.find(document.hash); + + // // if this content exists already, return this one + // if (h_itr != hash_index.end()) + // { + // document.contract = _contract; + // document.creator = h_itr->creator; + // document.created_date = h_itr->created_date; + // document.id = h_itr->id; + // return document; + // } return Document(_contract, _creator, contentGroups); } @@ -63,10 +62,7 @@ namespace hypha return getOrNew(contract, creator, rollup(Content(label, value))); } - bool HashDocument::isHash() { - return (getHash() == DO_NOT_HASH); - } - + bool HashDocument::exists(eosio::name contract, const eosio::checksum256& _hash) { document_table d_t(contract, contract.value); @@ -81,4 +77,4 @@ namespace hypha } -} +}