COOPENOMICS  v1
Кооперативная Экономика
shared_gateway.hpp
См. документацию.
1#define CREATEOUTPAY_SIGNATURE name coopname, name username, checksum256 outcome_hash, asset quantity, name callback_contract, name confirm_callback, name decline_callback
2
4
5namespace Gateway {
6
13 static const std::set<eosio::name> gateway_income_actions = {
14 "deposit"_n, //паевой взнос по ЦПП Кошелёк
15 };
16
23 static const std::set<eosio::name> gateway_outcome_actions = {
24 "withdraw"_n, //возврат паевого взноса по ЦПП Кошелёк
25 };
26
27
28 inline eosio::name get_valid_income_action(const eosio::name& action) {
29 eosio::check(gateway_income_actions.contains(action), "Недопустимое имя действия");
30 return action;
31 }
32
33 inline eosio::name get_valid_outcome_action(const eosio::name& action) {
34 eosio::check(gateway_outcome_actions.contains(action), "Недопустимое имя действия");
35 return action;
36 }
37
46 struct [[eosio::table, eosio::contract(GATEWAY)]] income {
47 uint64_t id;
48 eosio::name coopname;
49 eosio::name username;
50 eosio::name type;
51 checksum256 income_hash;
55
56 eosio::asset quantity;
57 eosio::name status;
58
59 eosio::time_point_sec created_at = current_time_point();
60
61 uint64_t primary_key() const { return id; }
62 uint64_t by_username() const { return username.value; }
63 checksum256 by_hash() const { return income_hash; }
64 uint64_t by_status() const { return status.value; }
65 };
66
67 typedef eosio::multi_index<
68 "incomes"_n, income,
69 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<income, checksum256, &income::by_hash>>,
70 eosio::indexed_by<"byusername"_n, eosio::const_mem_fun<income, uint64_t, &income::by_username>>,
71 eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun<income, uint64_t, &income::by_status>>
81 inline std::optional<income> get_income(eosio::name coopname, const checksum256 &hash) {
82 incomes_index primary_index(_gateway, coopname.value);
83 auto secondary_index = primary_index.get_index<"byhash"_n>();
84
85 auto itr = secondary_index.find(hash);
86 if (itr == secondary_index.end()) {
87 return std::nullopt;
88 }
89
90 return *itr;
91 }
92
93
102 struct [[eosio::table, eosio::contract(GATEWAY)]] outcome {
103 uint64_t id;
104 eosio::name coopname;
105 eosio::name username;
106 eosio::name type;
107 checksum256 outcome_hash;
111
112 eosio::asset quantity;
113 eosio::name status;
114
115 eosio::time_point_sec created_at = current_time_point();
116
117 uint64_t primary_key() const { return id; }
118 uint64_t by_username() const { return username.value; }
119 checksum256 by_hash() const { return outcome_hash; }
120 uint64_t by_status() const { return status.value; }
121 };
122
123 typedef eosio::multi_index<
124 "outcomes"_n, outcome,
125 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<outcome, checksum256, &outcome::by_hash>>,
126 eosio::indexed_by<"byusername"_n, eosio::const_mem_fun<outcome, uint64_t, &outcome::by_username>>,
127 eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun<outcome, uint64_t, &outcome::by_status>>
131 inline std::optional<outcome> get_outcome(eosio::name coopname, const checksum256 &hash) {
132 outcomes_index primary_index(_gateway, coopname.value);
133 auto secondary_index = primary_index.get_index<"byhash"_n>();
134
135 auto itr = secondary_index.find(hash);
136 if (itr == secondary_index.end()) {
137 return std::nullopt;
138 }
139
140 return *itr;
141 }
142
143 inline void create_outcome(
144 name calling_contract,
146 ) {
147 Action::send<createoutpay_interface>(
148 _gateway,
150 calling_contract,
151 coopname,
152 username,
153 outcome_hash,
154 quantity,
155 callback_contract,
156 confirm_callback,
157 decline_callback
158 );
159 }
160
161}
static constexpr eosio::name _gateway
Definition: consts.hpp:152
contract
Definition: eosio.msig_tests.cpp:977
static const std::set< eosio::name > gateway_income_actions
Допустимые действия для входящих платежей
Definition: shared_gateway.hpp:13
static const std::set< eosio::name > gateway_outcome_actions
Допустимые действия для исходящих платежей
Definition: shared_gateway.hpp:23
Definition: shared_gateway.hpp:5
void create_outcome(name calling_contract, CREATEOUTPAY_SIGNATURE)
Definition: shared_gateway.hpp:143
eosio::name get_valid_outcome_action(const eosio::name &action)
Definition: shared_gateway.hpp:33
std::optional< outcome > get_outcome(eosio::name coopname, const checksum256 &hash)
Definition: shared_gateway.hpp:131
eosio::name get_valid_income_action(const eosio::name &action)
Definition: shared_gateway.hpp:28
std::optional< income > get_income(eosio::name coopname, const checksum256 &hash)
Получает возврат из кошелька по хэшу.
Definition: shared_gateway.hpp:81
eosio::multi_index< "outcomes"_n, outcome, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< outcome, checksum256, &outcome::by_hash > >, eosio::indexed_by<"byusername"_n, eosio::const_mem_fun< outcome, uint64_t, &outcome::by_username > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< outcome, uint64_t, &outcome::by_status > > > outcomes_index
Definition: shared_gateway.hpp:128
eosio::multi_index< "incomes"_n, income, eosio::indexed_by<"byhash"_n, eosio::const_mem_fun< income, checksum256, &income::by_hash > >, eosio::indexed_by<"byusername"_n, eosio::const_mem_fun< income, uint64_t, &income::by_username > >, eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun< income, uint64_t, &income::by_status > > > incomes_index
Definition: shared_gateway.hpp:72
constexpr eosio::name CREATE_OUTPAY
Definition: shared_names.hpp:79
Definition: eosio.msig.hpp:34
action(permission_level{ _gateway, "active"_n}, _gateway, "adduser"_n, std::make_tuple(coopname, deposit->username, to_spread, to_circulation, eosio::current_time_point(), true)).send()
#define CREATEOUTPAY_SIGNATURE
Definition: shared_gateway.hpp:1
void(CREATEOUTPAY_SIGNATURE) createoutpay_interface
Definition: shared_gateway.hpp:3
Таблица входящих платежей хранит информацию о входящих платежах в кооператив.
Definition: shared_gateway.hpp:46
eosio::name coopname
Имя аккаунта кооператива, в контексте которого совершается платеж
Definition: shared_gateway.hpp:48
checksum256 income_hash
Хэш входящего платежа
Definition: shared_gateway.hpp:51
name confirm_callback
Действие успеха
Definition: shared_gateway.hpp:53
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: shared_gateway.hpp:62
eosio::asset quantity
Количество средств во внутренней валюте
Definition: shared_gateway.hpp:56
checksum256 by_hash() const
Индекс по хэшу платежа (3)
Definition: shared_gateway.hpp:63
uint64_t by_status() const
Индекс по статусу платежа (4)
Definition: shared_gateway.hpp:64
uint64_t primary_key() const
Первичный ключ (1)
Definition: shared_gateway.hpp:61
eosio::name status
Статус платежа
Definition: shared_gateway.hpp:57
eosio::name username
Имя аккаунта пользователя, совершившего платеж
Definition: shared_gateway.hpp:49
uint64_t id
Уникальный идентификатор записи входящего платежа
Definition: shared_gateway.hpp:47
eosio::name type
Тип платежа
Definition: shared_gateway.hpp:50
name decline_callback
Действие отклонения
Definition: shared_gateway.hpp:54
name callback_contract
Контракт для вызова коллбэков
Definition: shared_gateway.hpp:52
Таблица исходящих платежей хранит информацию об исходящих платежах из кооператива.
Definition: shared_gateway.hpp:102
checksum256 outcome_hash
Хэш исходящего платежа
Definition: shared_gateway.hpp:107
eosio::name status
Статус платежа
Definition: shared_gateway.hpp:113
eosio::name type
Тип платежа
Definition: shared_gateway.hpp:106
eosio::name username
Имя аккаунта пользователя, совершившего платеж
Definition: shared_gateway.hpp:105
uint64_t id
Уникальный идентификатор записи исходящего платежа
Definition: shared_gateway.hpp:103
eosio::name coopname
Имя аккаунта кооператива, в контексте которого совершается платеж
Definition: shared_gateway.hpp:104
uint64_t primary_key() const
Первичный ключ (1)
Definition: shared_gateway.hpp:117
eosio::asset quantity
Количество средств во внутренней валюте
Definition: shared_gateway.hpp:112
name callback_contract
Контракт для вызова коллбэков
Definition: shared_gateway.hpp:108
name confirm_callback
Действие успеха
Definition: shared_gateway.hpp:109
uint64_t by_status() const
Индекс по статусу платежа (4)
Definition: shared_gateway.hpp:120
name decline_callback
Действие отклонения
Definition: shared_gateway.hpp:110
uint64_t by_username() const
Индекс по имени пользователя (2)
Definition: shared_gateway.hpp:118
checksum256 by_hash() const
Индекс по хэшу платежа (3)
Definition: shared_gateway.hpp:119