COOPENOMICS  v1
Кооперативная Экономика
document.hpp
См. документацию.
1#pragma once
2
3#include "../domain/document_core.hpp"
4#include "utils.hpp"
5
6namespace Document {
12 inline void validate_registry_id(document2 document, uint64_t expected_registry_id) {
13 uint64_t registry_id = extract_registry_id_from_meta(document.meta);
14 eosio::check(registry_id == expected_registry_id, "Передан неверный шаблон документа");
15 }
16
23 };
24
31 inline void add_document(std::vector<named_document>& docs, const name& name, const document2& doc) {
32 docs.push_back({name, doc});
33 }
34
42 inline bool find_document(const std::vector<named_document>& docs, const name& name, document2& found_doc) {
43 for (const auto& nd : docs) {
44 if (nd.name == name) {
45 found_doc = nd.document;
46 return true;
47 }
48 }
49 return false;
50 }
51
58 inline bool has_document(const std::vector<named_document>& docs, const name& name) {
59 for (const auto& nd : docs) {
60 if (nd.name == name) {
61 return true;
62 }
63 }
64 return false;
65 }
66
72 inline bool is_document_empty(const document2& document) {
73 return document.hash == checksum256{};
74 }
75
76}
Definition: document.hpp:6
bool has_document(const std::vector< named_document > &docs, const name &name)
Проверить наличие документа
Definition: document.hpp:58
void add_document(std::vector< named_document > &docs, const name &name, const document2 &doc)
Добавить документ с проверкой длины имени
Definition: document.hpp:31
bool is_document_empty(const document2 &document)
Проверить, является ли документ пустым по хэшу
Definition: document.hpp:72
void validate_registry_id(document2 document, uint64_t expected_registry_id)
Проверяет, что переданный документ соответствует ожидаемому шаблону
Definition: document.hpp:12
bool find_document(const std::vector< named_document > &docs, const name &name, document2 &found_doc)
Найти документ по имени
Definition: document.hpp:42
Структура именованного документа
Definition: document.hpp:20
name name
Definition: document.hpp:21
document2 document
Definition: document.hpp:22
Definition: document_core.hpp:27
Definition: document_core.hpp:10
checksum256 hash
Definition: document_core.hpp:11
std::string meta
Definition: document_core.hpp:14
uint64_t extract_registry_id_from_meta(const std::string &meta_json)
Definition: utils.hpp:75