COOPENOMICS  v1
Кооперативная Экономика
commits.hpp
См. документацию.
1#pragma once
2
4
5using namespace eosio;
6using std::string;
7
8namespace Capital::Commits {
15 namespace Status {
16 constexpr eosio::name CREATED = "created"_n;
17 }
18}
19
20namespace Capital::Commits {
21
30 struct [[eosio::table, eosio::contract(CAPITAL)]] commit {
31 uint64_t id;
32 name coopname;
33 name username;
34 name status;
35 checksum256 project_hash;
36 checksum256 commit_hash;
37 std::string description;
38 std::string meta;
40 time_point_sec created_at;
41
42 uint64_t primary_key() const { return id; }
43 uint64_t by_username() const { return username.value; }
44 checksum256 by_commit_hash() const { return commit_hash; }
45 checksum256 by_project_hash() const { return project_hash; }
46 };
47
48typedef eosio::multi_index<
49 "commits"_n, commit,
50 indexed_by<"byusername"_n, const_mem_fun<commit, uint64_t, &commit::by_username>>,
51 indexed_by<"byhash"_n, const_mem_fun<commit, checksum256, &commit::by_commit_hash>>,
52 indexed_by<"byprojhash"_n, const_mem_fun<commit, checksum256, &commit::by_project_hash>>
54
55
56
63 inline std::optional<commit> get_commit(eosio::name coopname, const checksum256 &hash) {
64 commit_index commits(_capital, coopname.value);
65 auto commit_index = commits.get_index<"byhash"_n>();
66
67 auto itr = commit_index.find(hash);
68 if (itr == commit_index.end()) {
69 return std::nullopt;
70 }
71
72 return *itr;
73
74}
75
76
83 inline commit get_commit_or_fail(eosio::name coopname, const checksum256 &hash) {
84 auto commit = get_commit(coopname, hash);
85 eosio::check(commit.has_value(), "Коммит не найден");
86
87 return commit.value();
88}
89
95inline void delete_commit(eosio::name coopname, const checksum256 &hash) {
96 commit_index commits(_capital, coopname.value);
97 auto commit_index = commits.get_index<"byhash"_n>();
98
99 auto itr = commit_index.find(hash);
100 eosio::check(itr != commit_index.end(), "Коммит не найден");
101
102 commits.erase(*itr);
103}
104
113inline void create_commit(
114 eosio::name coopname,
115 eosio::name username,
116 checksum256 project_hash,
117 checksum256 commit_hash,
118 std::string description,
119 std::string meta,
120 const generation_amounts &calculated_fact
121) {
122 // Создаем коммит
123 commit_index commits(_capital, coopname.value);
124 auto commit_id = get_global_id_in_scope(_capital, coopname, "commits"_n);
125
126 // Создаем коммит в таблице commits
127 commits.emplace(coopname, [&](auto &c) {
128 c.id = commit_id;
130 c.coopname = coopname;
131 c.username = username;
132 c.project_hash = project_hash;
133 c.commit_hash = commit_hash;
134 c.description = description;
135 c.meta = meta;
136 c.amounts = calculated_fact;
137 c.created_at = current_time_point();
138 });
139}
140
141} // namespace Capital::Commits
static constexpr eosio::name _capital
Definition: consts.hpp:150
contract
Definition: eosio.msig_tests.cpp:977
uint64_t get_global_id_in_scope(eosio::name _me, eosio::name scope, eosio::name key)
Definition: counts.hpp:61
constexpr eosio::name CREATED
Коммит создан
Definition: commits.hpp:16
Definition: commits.hpp:8
eosio::multi_index< "commits"_n, commit, indexed_by<"byusername"_n, const_mem_fun< commit, uint64_t, &commit::by_username > >, indexed_by<"byhash"_n, const_mem_fun< commit, checksum256, &commit::by_commit_hash > >, indexed_by<"byprojhash"_n, const_mem_fun< commit, checksum256, &commit::by_project_hash > > > commit_index
Definition: commits.hpp:53
void delete_commit(eosio::name coopname, const checksum256 &hash)
Удаляет коммит по хэшу действия.
Definition: commits.hpp:95
void create_commit(eosio::name coopname, eosio::name username, checksum256 project_hash, checksum256 commit_hash, std::string description, std::string meta, const generation_amounts &calculated_fact)
Создает коммит без отправки на утверждение.
Definition: commits.hpp:113
commit get_commit_or_fail(eosio::name coopname, const checksum256 &hash)
Получает действие по хэшу действия.
Definition: commits.hpp:83
std::optional< commit > get_commit(eosio::name coopname, const checksum256 &hash)
Получает действие по хэшу действия.
Definition: commits.hpp:63
Definition: eosio.msig.hpp:34
Таблица коммитов хранит данные о выполненных операциях в проекте.
Definition: commits.hpp:30
checksum256 by_commit_hash() const
Индекс по хэшу коммита (3)
Definition: commits.hpp:44
checksum256 project_hash
Хэш проекта, связанного с действием
Definition: commits.hpp:35
time_point_sec created_at
Дата и время создания действия
Definition: commits.hpp:40
checksum256 commit_hash
Хэш действия
Definition: commits.hpp:36
generation_amounts amounts
Рассчитанные показатели генерации
Definition: commits.hpp:39
uint64_t primary_key() const
Первичный ключ (1)
Definition: commits.hpp:42
name username
Имя пользователя, совершившего действие
Definition: commits.hpp:33
std::string meta
Метаданные коммита
Definition: commits.hpp:38
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: commits.hpp:43
uint64_t id
ID коммита (внутренний ключ)
Definition: commits.hpp:31
name coopname
Имя кооператива
Definition: commits.hpp:32
checksum256 by_project_hash() const
Индекс по хэшу проекта (4)
Definition: commits.hpp:45
std::string description
Описание действия
Definition: commits.hpp:37
name status
Статус коммита (created | approved | authorized | act1 | act2)
Definition: commits.hpp:34
Структура для результатов расчета генерации коммита Содержит только те поля, которые рассчитываются п...
Definition: generation_amounts.hpp:14