COOPENOMICS  v1
Кооперативная Экономика
table_soviet_decisions.hpp
См. документацию.
1#pragma once
2
3#include <algorithm>
4#include <eosio/binary_extension.hpp>
5#include <eosio/crypto.hpp>
6#include <eosio/eosio.hpp>
7#include <utility>
8#include <vector>
9
10#include "../consts.hpp"
11#include "document_core.hpp"
12
13using namespace eosio;
14
20struct [[eosio::table, eosio::contract(SOVIET)]] decision {
21 uint64_t id;
22 eosio::name coopname;
23 eosio::name username;
24
25 eosio::name type;
26 uint64_t batch_id;
28
29 std::vector<eosio::name> votes_for;
30 std::vector<eosio::name> votes_against;
31
32 bool validated = false;
33 bool approved = false;
34 bool authorized = false;
35 eosio::name authorized_by;
37
38 eosio::time_point_sec created_at;
39
40 eosio::binary_extension<eosio::time_point_sec> expired_at;
41 eosio::binary_extension<std::string> meta;
42
43 eosio::binary_extension<name> callback_contract;
44 eosio::binary_extension<name> confirm_callback;
45 eosio::binary_extension<name> decline_callback;
46 eosio::binary_extension<checksum256> hash;
47
48 uint64_t primary_key() const { return id; }
49
50 uint64_t by_secondary() const { return batch_id; }
51
52 uint64_t bytype() const { return type.value; }
53
54 uint64_t byapproved() const { return approved; }
55
56 uint64_t byvalidated() const { return validated; }
57
58 uint64_t byauthorized() const { return authorized; }
59
60 checksum256 byhash() const { return hash.value(); }
61
62 void check_for_any_vote_exist(eosio::name member) const {
63 eosio::check(std::find(votes_for.begin(), votes_for.end(), member) == votes_for.end(),
64 "Участник уже голосовал за данное решение.");
65
66 eosio::check(std::find(votes_against.begin(), votes_against.end(), member) == votes_against.end(),
67 "Участник уже голосовал против данного решения.");
68 }
69
70 std::pair<uint64_t, uint64_t> get_votes_count() const {
71 return std::make_pair(votes_for.size(), votes_against.size());
72 }
73};
74
75typedef eosio::multi_index<
76 "decisions"_n, decision,
77 eosio::indexed_by<"bysecondary"_n, eosio::const_mem_fun<decision, uint64_t, &decision::by_secondary>>,
78 eosio::indexed_by<"bytype"_n, eosio::const_mem_fun<decision, uint64_t, &decision::bytype>>,
79 eosio::indexed_by<"byapproved"_n, eosio::const_mem_fun<decision, uint64_t, &decision::byapproved>>,
80 eosio::indexed_by<"byvalidated"_n, eosio::const_mem_fun<decision, uint64_t, &decision::byvalidated>>,
81 eosio::indexed_by<"byauthorized"_n, eosio::const_mem_fun<decision, uint64_t, &decision::byauthorized>>,
82 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<decision, checksum256, &decision::byhash>>>
contract
Definition: eosio.msig_tests.cpp:977
Definition: eosio.msig.hpp:34
Definition: table_soviet_decisions.hpp:20
bool validated
Definition: table_soviet_decisions.hpp:32
document2 authorization
Definition: table_soviet_decisions.hpp:36
eosio::binary_extension< name > confirm_callback
Definition: table_soviet_decisions.hpp:44
uint64_t by_secondary() const
Definition: table_soviet_decisions.hpp:50
eosio::name coopname
Definition: table_soviet_decisions.hpp:22
bool approved
Definition: table_soviet_decisions.hpp:33
eosio::binary_extension< checksum256 > hash
Definition: table_soviet_decisions.hpp:46
eosio::name type
Definition: table_soviet_decisions.hpp:25
uint64_t byauthorized() const
Definition: table_soviet_decisions.hpp:58
eosio::binary_extension< eosio::time_point_sec > expired_at
Definition: table_soviet_decisions.hpp:40
uint64_t batch_id
Definition: table_soviet_decisions.hpp:26
std::vector< eosio::name > votes_against
Definition: table_soviet_decisions.hpp:30
uint64_t bytype() const
Definition: table_soviet_decisions.hpp:52
uint64_t id
Definition: table_soviet_decisions.hpp:21
eosio::binary_extension< std::string > meta
Definition: table_soviet_decisions.hpp:41
std::pair< uint64_t, uint64_t > get_votes_count() const
Definition: table_soviet_decisions.hpp:70
bool authorized
Definition: table_soviet_decisions.hpp:34
document2 statement
Definition: table_soviet_decisions.hpp:27
checksum256 byhash() const
Definition: table_soviet_decisions.hpp:60
eosio::name username
Definition: table_soviet_decisions.hpp:23
std::vector< eosio::name > votes_for
Definition: table_soviet_decisions.hpp:29
uint64_t byvalidated() const
Definition: table_soviet_decisions.hpp:56
uint64_t byapproved() const
Definition: table_soviet_decisions.hpp:54
eosio::binary_extension< name > callback_contract
Definition: table_soviet_decisions.hpp:43
uint64_t primary_key() const
Definition: table_soviet_decisions.hpp:48
eosio::binary_extension< name > decline_callback
Definition: table_soviet_decisions.hpp:45
eosio::name authorized_by
Definition: table_soviet_decisions.hpp:35
eosio::time_point_sec created_at
Definition: table_soviet_decisions.hpp:38
void check_for_any_vote_exist(eosio::name member) const
Definition: table_soviet_decisions.hpp:62
Definition: document_core.hpp:27
eosio::multi_index< "decisions"_n, decision, eosio::indexed_by<"bysecondary"_n, eosio::const_mem_fun< decision, uint64_t, &decision::by_secondary > >, eosio::indexed_by<"bytype"_n, eosio::const_mem_fun< decision, uint64_t, &decision::bytype > >, eosio::indexed_by<"byapproved"_n, eosio::const_mem_fun< decision, uint64_t, &decision::byapproved > >, eosio::indexed_by<"byvalidated"_n, eosio::const_mem_fun< decision, uint64_t, &decision::byvalidated > >, eosio::indexed_by<"byauthorized"_n, eosio::const_mem_fun< decision, uint64_t, &decision::byauthorized > >, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< decision, checksum256, &decision::byhash > > > decisions_index
Definition: table_soviet_decisions.hpp:83