Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions include/docs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &notes);
// ACTION createroot(const std::string &notes);

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?)
Expand Down
46 changes: 26 additions & 20 deletions include/document_graph/document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 &notes);
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);
Expand All @@ -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; }

Expand All @@ -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<eosio::checksum256>(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
Expand All @@ -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::name("documents"), Document,
eosio::indexed_by<eosio::name("idhash"), eosio::const_mem_fun<Document, eosio::checksum256, &Document::by_hash>>,
eosio::indexed_by<eosio::name("byhash"), eosio::const_mem_fun<Document, eosio::checksum256, &Document::by_hash>>,
eosio::indexed_by<eosio::name("bycreator"), eosio::const_mem_fun<Document, uint64_t, &Document::by_creator>>,
eosio::indexed_by<eosio::name("bycreated"), eosio::const_mem_fun<Document, uint64_t, &Document::by_created>>,
eosio::indexed_by<eosio::name("byupdated"), eosio::const_mem_fun<Document, uint64_t, &Document::by_updated>>>

document_table;
};

} // namespace hypha
3 changes: 2 additions & 1 deletion include/document_graph/document_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ using contract_document = contract##_document;\
using document_table = eosio::multi_index<eosio::name("documents"), contract_document,\
eosio::indexed_by<name("idhash"), eosio::const_mem_fun<root_doc, eosio::checksum256, &root_doc::by_hash>>,\
eosio::indexed_by<name("bycreator"), eosio::const_mem_fun<root_doc, uint64_t, &root_doc::by_creator>>,\
eosio::indexed_by<name("bycreated"), eosio::const_mem_fun<root_doc, uint64_t, &root_doc::by_created>>>;\
eosio::indexed_by<name("bycreated"), eosio::const_mem_fun<root_doc, uint64_t, &root_doc::by_created>>,\
eosio::indexed_by<name("byupdated"), eosio::const_mem_fun<root_doc, uint64_t, &root_doc::by_updated>>>;\
using root_edge = hypha::Edge;\
TABLE contract##_edge : public root_edge {};\
using contract_edge = contract##_edge;\
Expand Down
13 changes: 5 additions & 8 deletions include/document_graph/hash_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
128 changes: 64 additions & 64 deletions src/docs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::asset>();
// 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::asset>();

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<int64_t>();
}
// 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<int64_t>();
// }

void docs::createroot(const std::string &notes)
{
require_auth(get_self());
// void docs::createroot(const std::string &notes)
// {
// 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<document_graph::content_group> &content_groups )
// {
Expand Down
Loading