COOPENOMICS  v1
Кооперативная Экономика
table_gateway_outcomes.hpp
См. документацию.
1#pragma once
2
3#include <eosio/asset.hpp>
4#include <eosio/crypto.hpp>
5#include <eosio/eosio.hpp>
6#include <optional>
7#include <string>
8
9#include "../consts.hpp"
10
11namespace Gateway {
12
18struct [[eosio::table, eosio::contract(GATEWAY)]] outcome {
19 uint64_t id;
20 eosio::name coopname;
21 eosio::name username;
22 eosio::name type;
23 checksum256 outcome_hash;
24 eosio::name callback_contract;
25 eosio::name confirm_callback;
26 eosio::name decline_callback;
27
28 eosio::asset quantity;
29 eosio::name status;
30
31 eosio::time_point_sec created_at = current_time_point();
32
33 uint64_t primary_key() const { return id; }
34 uint64_t by_username() const { return username.value; }
35 checksum256 by_hash() const { return outcome_hash; }
36 uint64_t by_status() const { return status.value; }
37};
38
39typedef eosio::multi_index<
40 "outcomes"_n, outcome,
41 eosio::indexed_by<"byhash"_n, eosio::const_mem_fun<outcome, checksum256, &outcome::by_hash>>,
42 eosio::indexed_by<"byusername"_n, eosio::const_mem_fun<outcome, uint64_t, &outcome::by_username>>,
43 eosio::indexed_by<"bystatus"_n, eosio::const_mem_fun<outcome, uint64_t, &outcome::by_status>>>
45
46inline std::optional<outcome> get_outcome(eosio::name coopname, const checksum256 &hash) {
47 outcomes_index primary_index(_gateway, coopname.value);
48 auto secondary_index = primary_index.get_index<"byhash"_n>();
49
50 auto itr = secondary_index.find(hash);
51 if (itr == secondary_index.end()) {
52 return std::nullopt;
53 }
54
55 return *itr;
56}
57
58} // namespace Gateway
static constexpr eosio::name _gateway
Definition: consts.hpp:152
contract
Definition: eosio.msig_tests.cpp:977
Definition: gateway.hpp:20
std::optional< outcome > get_outcome(eosio::name coopname, const checksum256 &hash)
Definition: table_gateway_outcomes.hpp:46
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: table_gateway_outcomes.hpp:44
Definition: eosio.msig.hpp:34
Definition: table_gateway_outcomes.hpp:18
checksum256 outcome_hash
Definition: table_gateway_outcomes.hpp:23
eosio::name status
Definition: table_gateway_outcomes.hpp:29
eosio::name type
Definition: table_gateway_outcomes.hpp:22
eosio::name callback_contract
Definition: table_gateway_outcomes.hpp:24
eosio::name username
Definition: table_gateway_outcomes.hpp:21
uint64_t id
Definition: table_gateway_outcomes.hpp:19
eosio::name coopname
Definition: table_gateway_outcomes.hpp:20
eosio::name confirm_callback
Definition: table_gateway_outcomes.hpp:25
uint64_t primary_key() const
Definition: table_gateway_outcomes.hpp:33
eosio::asset quantity
Definition: table_gateway_outcomes.hpp:28
eosio::name decline_callback
Definition: table_gateway_outcomes.hpp:26
uint64_t by_status() const
Definition: table_gateway_outcomes.hpp:36
uint64_t by_username() const
Definition: table_gateway_outcomes.hpp:34
checksum256 by_hash() const
Definition: table_gateway_outcomes.hpp:35