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;
38 time_point_sec created_at;
39
40 uint64_t primary_key() const { return id; }
41 uint64_t by_username() const { return username.value; }
42 checksum256 by_commit_hash() const { return commit_hash; }
43 checksum256 by_project_hash() const { return project_hash; }
44 };
45
46typedef eosio::multi_index<
47 "commits"_n, commit,
48 indexed_by<"byusername"_n, const_mem_fun<commit, uint64_t, &commit::by_username>>,
49 indexed_by<"byhash"_n, const_mem_fun<commit, checksum256, &commit::by_commit_hash>>,
50 indexed_by<"byprojhash"_n, const_mem_fun<commit, checksum256, &commit::by_project_hash>>
52
53
54
61 inline std::optional<commit> get_commit(eosio::name coopname, const checksum256 &hash) {
62 commit_index commits(_capital, coopname.value);
63 auto commit_index = commits.get_index<"byhash"_n>();
64
65 auto itr = commit_index.find(hash);
66 if (itr == commit_index.end()) {
67 return std::nullopt;
68 }
69
70 return *itr;
71
72}
73
74
81 inline commit get_commit_or_fail(eosio::name coopname, const checksum256 &hash) {
82 auto commit = get_commit(coopname, hash);
83 eosio::check(commit.has_value(), "Коммит не найден");
84
85 return commit.value();
86}
87
93inline void delete_commit(eosio::name coopname, const checksum256 &hash) {
94 commit_index commits(_capital, coopname.value);
95 auto commit_index = commits.get_index<"byhash"_n>();
96
97 auto itr = commit_index.find(hash);
98 eosio::check(itr != commit_index.end(), "Коммит не найден");
99
100 commits.erase(*itr);
101}
102
111inline void create_commit(
112 eosio::name coopname,
113 eosio::name username,
114 checksum256 project_hash,
115 checksum256 commit_hash,
116 const generation_amounts &calculated_fact
117) {
118 // Создаем коммит
119 commit_index commits(_capital, coopname.value);
120 auto commit_id = get_global_id_in_scope(_capital, coopname, "commits"_n);
121
122 // Создаем коммит в таблице commits
123 commits.emplace(coopname, [&](auto &c) {
124 c.id = commit_id;
126 c.coopname = coopname;
127 c.username = username;
128 c.project_hash = project_hash;
129 c.commit_hash = commit_hash;
130 c.amounts = calculated_fact;
131 c.created_at = current_time_point();
132 });
133}
134
135} // 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
void create_commit(eosio::name coopname, eosio::name username, checksum256 project_hash, checksum256 commit_hash, const generation_amounts &calculated_fact)
Создает коммит без отправки на утверждение.
Definition: commits.hpp:111
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:51
void delete_commit(eosio::name coopname, const checksum256 &hash)
Удаляет коммит по хэшу действия.
Definition: commits.hpp:93
commit get_commit_or_fail(eosio::name coopname, const checksum256 &hash)
Получает действие по хэшу действия.
Definition: commits.hpp:81
std::optional< commit > get_commit(eosio::name coopname, const checksum256 &hash)
Получает действие по хэшу действия.
Definition: commits.hpp:61
Definition: eosio.msig.hpp:34
Таблица коммитов хранит данные о выполненных операциях в проекте.
Definition: commits.hpp:30
checksum256 by_commit_hash() const
Индекс по хэшу коммита (3)
Definition: commits.hpp:42
checksum256 project_hash
Хэш проекта, связанного с действием
Definition: commits.hpp:35
time_point_sec created_at
Дата и время создания действия
Definition: commits.hpp:38
checksum256 commit_hash
Хэш действия
Definition: commits.hpp:36
generation_amounts amounts
Рассчитанные показатели генерации
Definition: commits.hpp:37
uint64_t primary_key() const
Первичный ключ (1)
Definition: commits.hpp:40
name username
Имя пользователя, совершившего действие
Definition: commits.hpp:33
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: commits.hpp:41
uint64_t id
ID коммита (внутренний ключ)
Definition: commits.hpp:31
name coopname
Имя кооператива
Definition: commits.hpp:32
checksum256 by_project_hash() const
Индекс по хэшу проекта (4)
Definition: commits.hpp:43
name status
Статус коммита (created | approved | authorized | act1 | act2)
Definition: commits.hpp:34
Структура для результатов расчета генерации коммита Содержит только те поля, которые рассчитываются п...
Definition: generation_amounts.hpp:14