/** * @file * @copyright defined in eos/LICENSE.txt */ #include #include #include #include #include using namespace eosio; namespace testsystem { template struct dispatchable { constexpr static uint64_t action_name = Val; }; struct set_account_limits : dispatchable { account_name account; int64_t ram_bytes; int64_t net_weight; int64_t cpu_weight; static void process(const set_account_limits& act) { set_resource_limits(act.account, act.ram_bytes, act.net_weight, act.cpu_weight, 0); } EOSLIB_SERIALIZE( set_account_limits, (account)(ram_bytes)(net_weight)(cpu_weight) ); }; struct set_global_limits : dispatchable { int64_t cpu_usec_per_period; static void process(const set_global_limits& act) { // TODO: support this } EOSLIB_SERIALIZE( set_global_limits, (cpu_usec_per_period) ); }; struct producer_key { account_name account; string public_key; EOSLIB_SERIALIZE( producer_key, (account)(public_key) ); }; struct set_producers : dispatchable { uint32_t version; vector producers; static void process(const set_producers&) { char buffer[action_size()]; read_action( buffer, sizeof(buffer) ); set_active_producers(buffer, sizeof(buffer)); } EOSLIB_SERIALIZE( set_producers, (version)(producers) ); }; struct require_auth : dispatchable { account_name from; static void process(const require_auth& r) { ::require_auth(r.from); } }; template struct dispatcher_impl; template struct dispatcher_impl { static bool dispatch(uint64_t action) { if (action == T::action_name) { T::process(current_action()); return true; } return false; } }; template struct dispatcher_impl { static bool dispatch(uint64_t action) { return dispatcher_impl::dispatch(action) || dispatcher_impl::dispatch(action); } }; using dispatcher = dispatcher_impl; }; extern "C" { /// The apply method implements the dispatch of events to this contract void apply( uint64_t code, uint64_t act ) { if (code == current_receiver()) { testsystem::dispatcher::dispatch(act); } } } // extern "C"