COOPENOMICS  v1
Кооперативная Экономика
ram_payer.hpp
См. документацию.
1#pragma once
2
3#include <eosio/eosio.hpp>
4#include <eosio/multi_index.hpp>
5#include <type_traits>
6#include <utility>
7
40namespace RamPayer {
41
42 enum class Class : uint8_t {
52 system,
53 };
54
56 template <typename Row>
57 struct class_of;
58
63 template <typename Table>
64 using row_t = std::decay_t<decltype(*std::declval<const Table &>().cbegin())>;
65
67 template <typename Table>
68 inline eosio::name cooperative_or_contract(const Table &table, eosio::name coopname) {
69 return eosio::has_auth(coopname) ? coopname : table.get_code();
70 }
71
77 template <typename Table>
78 inline eosio::name of(const Table &table, eosio::name coopname) {
79 constexpr Class cls = class_of<row_t<Table>>::value;
80
81 if constexpr (cls == Class::contract) {
82 return table.get_code();
83 } else if constexpr (cls == Class::system) {
84 // Шаблон в области кооператива заводит сам кооператив, без подписи
85 // системы, — тогда платит контракт реестра шаблонов.
86 const eosio::name system_account("eosio");
87 return eosio::has_auth(system_account) ? system_account : table.get_code();
88 } else {
89 return cooperative_or_contract(table, coopname);
90 }
91 }
92
98 template <typename Table>
99 inline eosio::name of(const Table &table) {
100 static_assert(class_of<row_t<Table>>::value != Class::cooperative,
101 "RamPayer: cooperative table needs coopname, call RamPayer::of(table, coopname)");
102 return of(table, eosio::name{});
103 }
104
105} // namespace RamPayer
106
113#define RAM_PAYER_CLASS(ROW, CLASS) \
114 template <> \
115 struct RamPayer::class_of<ROW> { \
116 static constexpr RamPayer::Class value = RamPayer::Class::CLASS; \
117 }
contract
Definition: eosio.msig_tests.cpp:977
Плательщик за оперативную память строки таблицы.
Definition: ram_payer.hpp:40
eosio::name of(const Table &table, eosio::name coopname)
Definition: ram_payer.hpp:78
eosio::name cooperative_or_contract(const Table &table, eosio::name coopname)
Definition: ram_payer.hpp:68
std::decay_t< decltype(*std::declval< const Table & >().cbegin())> row_t
Definition: ram_payer.hpp:64
Class
Definition: ram_payer.hpp:42
Definition: ram_payer.hpp:57
Definition: table_registrator_orgs.hpp:17