COOPENOMICS  v1
Кооперативная Экономика
commits.hpp
См. документацию.
1#pragma once
2
3
4#include "../../../lib/core/ram_payer.hpp"
6
7using namespace eosio;
8using std::string;
9
17 namespace Status {
18 constexpr eosio::name CREATED = "created"_n;
19 }
20}
21
22namespace Capital::Commits {
23
32 struct [[eosio::table, eosio::contract(CAPITAL)]] commit {
33 uint64_t id;
34 name coopname;
35 name username;
36 name status;
37 checksum256 project_hash;
38 checksum256 commit_hash;
39 std::string description;
40 std::string meta;
42 time_point_sec created_at;
43
44 uint64_t primary_key() const { return id; }
45 uint64_t by_username() const { return username.value; }
46 checksum256 by_commit_hash() const { return commit_hash; }
47 checksum256 by_project_hash() const { return project_hash; }
48 };
49
50typedef eosio::multi_index<
51 "commits"_n, commit,
52 indexed_by<"byusername"_n, const_mem_fun<commit, uint64_t, &commit::by_username>>,
53 indexed_by<"byhash"_n, const_mem_fun<commit, checksum256, &commit::by_commit_hash>>,
54 indexed_by<"byprojhash"_n, const_mem_fun<commit, checksum256, &commit::by_project_hash>>
56
57
58
65 inline std::optional<commit> get_commit(eosio::name coopname, const checksum256 &hash) {
66 commit_index commits(_capital, coopname.value);
67 auto commit_index = commits.get_index<"byhash"_n>();
68
69 auto itr = commit_index.find(hash);
70 if (itr == commit_index.end()) {
71 return std::nullopt;
72 }
73
74 return commit(*itr);
75
76}
77
78
85 inline commit get_commit_or_fail(eosio::name coopname, const checksum256 &hash) {
86 auto commit = get_commit(coopname, hash);
87 eosio::check(commit.has_value(), "Коммит не найден");
88
89 return commit.value();
90}
91
97inline void delete_commit(eosio::name coopname, const uint64_t &commit_id) {
98 commit_index commits(_capital, coopname.value);
99 auto itr = commits.find(commit_id);
100 eosio::check(itr != commits.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(RamPayer::of(commits, 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
142
143// Плательщик за оперативную память строк таблицы — правило в lib/core/ram_payer.hpp.
RAM_PAYER_CLASS(Capital::Commits::commit, cooperative)
static constexpr eosio::name _capital
Definition: consts.hpp:171
contract
Definition: eosio.msig_tests.cpp:977
constexpr eosio::name CREATED
Коммит создан
Definition: commits.hpp:18
Definition: commits.hpp:10
void delete_commit(eosio::name coopname, const uint64_t &commit_id)
Удаляет коммит по хэшу действия.
Definition: commits.hpp:97
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:55
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:85
std::optional< commit > get_commit(eosio::name coopname, const checksum256 &hash)
Получает действие по хэшу действия.
Definition: commits.hpp:65
eosio::name of(const Table &table, eosio::name coopname)
Definition: ram_payer.hpp:78
Definition: eosio.msig.hpp:34
Таблица коммитов хранит данные о выполненных операциях в проекте.
Definition: commits.hpp:32
checksum256 by_commit_hash() const
Индекс по хэшу коммита (3)
Definition: commits.hpp:46
checksum256 project_hash
Хэш проекта, связанного с действием
Definition: commits.hpp:37
time_point_sec created_at
Дата и время создания действия
Definition: commits.hpp:42
checksum256 commit_hash
Хэш действия
Definition: commits.hpp:38
generation_amounts amounts
Рассчитанные показатели генерации
Definition: commits.hpp:41
uint64_t primary_key() const
Первичный ключ (1)
Definition: commits.hpp:44
name username
Имя пользователя, совершившего действие
Definition: commits.hpp:35
std::string meta
Метаданные коммита
Definition: commits.hpp:40
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: commits.hpp:45
uint64_t id
ID коммита (внутренний ключ)
Definition: commits.hpp:33
name coopname
Имя кооператива
Definition: commits.hpp:34
checksum256 by_project_hash() const
Индекс по хэшу проекта (4)
Definition: commits.hpp:47
std::string description
Описание действия
Definition: commits.hpp:39
name status
Статус коммита (created | approved | authorized | act1 | act2)
Definition: commits.hpp:36
Структура для результатов расчета генерации коммита Содержит только те поля, которые рассчитываются п...
Definition: generation_amounts.hpp:14
Definition: table_registrator_orgs.hpp:17
uint64_t get_global_id_in_scope(eosio::name _me, eosio::name scope, eosio::name key)
Definition: table_counts.hpp:62