From 603aef246c22d4f5acbb602247b0753a691ffb75 Mon Sep 17 00:00:00 2001 From: boostmultifruit Date: Fri, 31 Jan 2020 10:39:27 +0000 Subject: [PATCH] Migrate to auto-generated dispatchers #286 --- common/config.hpp | 3 +++ common/dispatchers.hpp | 24 ++++++++----------- cyber.bios/include/cyber.bios/cyber.bios.hpp | 5 ++-- cyber.bios/src/cyber.bios.cpp | 7 ------ cyber.domain/cyber.domain.cpp | 6 ----- cyber.govern/src/cyber.govern.cpp | 2 -- .../cyber.incomereject/cyber.incomereject.hpp | 3 ++- cyber.incomereject/src/cyber.incomereject.cpp | 14 ----------- cyber.msig/src/cyber.msig.cpp | 2 -- .../include/cyber.stake/cyber.stake.hpp | 3 ++- cyber.stake/src/cyber.stake.cpp | 8 ------- cyber.token/src/cyber.token.cpp | 2 -- 12 files changed, 20 insertions(+), 59 deletions(-) diff --git a/common/config.hpp b/common/config.hpp index a3a83dadc..0c14e3a03 100644 --- a/common/config.hpp +++ b/common/config.hpp @@ -16,6 +16,9 @@ inline eosio::chain::name operator ""_n() { } #endif +#define CYBER_TOKEN "cyber.token" +#define CYBER_STAKE "cyber.stake" + namespace cyber { namespace config { // contracts diff --git a/common/dispatchers.hpp b/common/dispatchers.hpp index d7673489d..3dbcaa698 100644 --- a/common/dispatchers.hpp +++ b/common/dispatchers.hpp @@ -2,6 +2,7 @@ #include "config.hpp" #include +#include template bool dispatch_with_transfer_helper( eosio::name self, eosio::name code, void (T::*func)(Args...) ) { @@ -50,19 +51,14 @@ extern "C" { \ } \ } \ +#define ON_SIMPLE_TRANSFER(TOKEN) [[eosio::on_notify(TOKEN "::transfer")]] -#define DISPATCH_WITH_UNSTAKING(TYPE, STAKE, WITHDRAW, PROVIDE, MEMBERS) \ -extern "C" { \ - void apply(uint64_t receiver, uint64_t code, uint64_t action) { \ - if (code == receiver) { \ - switch (action) { \ - EOSIO_DISPATCH_HELPER(TYPE, MEMBERS) \ - } \ - } else if (code == STAKE.value && action == "withdraw"_n.value) { \ - eosio::execute_action(eosio::name(receiver), eosio::name(code), &TYPE::WITHDRAW); \ - } else if (code == STAKE.value && action == "provide"_n.value) { \ - eosio::execute_action(eosio::name(receiver), eosio::name(code), &TYPE::PROVIDE); \ - } \ - } \ -} \ +#define ON_BULK_TRANSFER(TOKEN) [[eosio::on_notify(TOKEN "::bulktransfer")]] +#define ON_TRANSFER(TOKEN, ON_TRANSFER_HANDLER) \ + ON_BULK_TRANSFER(TOKEN) void on_bulk_transfer(name from, std::vector recipients) { \ + for (auto& recipient : recipients) { \ + ON_TRANSFER_HANDLER(from, recipient.to, recipient.quantity, recipient.memo); \ + } \ + } \ + ON_SIMPLE_TRANSFER(TOKEN) diff --git a/cyber.bios/include/cyber.bios/cyber.bios.hpp b/cyber.bios/include/cyber.bios/cyber.bios.hpp index 2ad9c0074..9e7f949c8 100644 --- a/cyber.bios/include/cyber.bios/cyber.bios.hpp +++ b/cyber.bios/include/cyber.bios/cyber.bios.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace cyber { using eosio::permission_level; @@ -163,8 +164,8 @@ namespace cyber { [[eosio::action]] void onblock(ignore header); - void on_stake_withdraw(name account, asset quantity); - void on_stake_provide(name provider_name, name consumer_name, asset quantity); + [[eosio::on_notify(CYBER_STAKE "::withdraw")]] void on_stake_withdraw(name account, asset quantity); + [[eosio::on_notify(CYBER_STAKE "::provide")]] void on_stake_provide(name provider_name, name consumer_name, asset quantity); }; diff --git a/cyber.bios/src/cyber.bios.cpp b/cyber.bios/src/cyber.bios.cpp index 1f4f1c277..0037c56d8 100644 --- a/cyber.bios/src/cyber.bios.cpp +++ b/cyber.bios/src/cyber.bios.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include @@ -178,9 +177,3 @@ void bios::on_stake_provide(name provider_name, name consumer_name, asset quanti } } - -DISPATCH_WITH_UNSTAKING(cyber::bios, cyber::config::stake_name, on_stake_withdraw, on_stake_provide, - (newaccount)(setprods)(setparams)(reqauth)(setabi)(setcode)(onblock)(checkwin)(bidname)(bidrefund) -) - - diff --git a/cyber.domain/cyber.domain.cpp b/cyber.domain/cyber.domain.cpp index 914b8bac9..be02702c5 100644 --- a/cyber.domain/cyber.domain.cpp +++ b/cyber.domain/cyber.domain.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "domain_validate.cpp" @@ -169,8 +168,3 @@ void domain::declarenames(const std::vector& domains) { } } // eosiosystem - - -EOSIO_DISPATCH(eosiosystem::domain, - (newdomain)(checkwin)(biddomain)(biddmrefund)(declarenames) -) diff --git a/cyber.govern/src/cyber.govern.cpp b/cyber.govern/src/cyber.govern.cpp index 9152cbd81..fdc70fa76 100644 --- a/cyber.govern/src/cyber.govern.cpp +++ b/cyber.govern/src/cyber.govern.cpp @@ -222,5 +222,3 @@ void govern::maybe_promote_producers() { } } - -EOSIO_DISPATCH( cyber::govern, (onblock)(setactprods)) diff --git a/cyber.incomereject/include/cyber.incomereject/cyber.incomereject.hpp b/cyber.incomereject/include/cyber.incomereject/cyber.incomereject.hpp index fb39f0b47..19a3ccee7 100644 --- a/cyber.incomereject/include/cyber.incomereject/cyber.incomereject.hpp +++ b/cyber.incomereject/include/cyber.incomereject/cyber.incomereject.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace eosio { @@ -13,7 +14,7 @@ namespace eosio { public: using contract::contract; - void on_transfer(name from, name to, asset quantity, std::string memo); + ON_TRANSFER(CYBER_TOKEN, on_transfer) void on_transfer(name from, name to, asset quantity, std::string memo); }; } /// namespace eosio diff --git a/cyber.incomereject/src/cyber.incomereject.cpp b/cyber.incomereject/src/cyber.incomereject.cpp index 551e18b9f..1bbcea36b 100644 --- a/cyber.incomereject/src/cyber.incomereject.cpp +++ b/cyber.incomereject/src/cyber.incomereject.cpp @@ -5,7 +5,6 @@ #include #include -#include namespace eosio { @@ -14,16 +13,3 @@ void incomereject::on_transfer(name from, name to, asset quantity, std::string m } } /// namespace eosio - -extern "C" { - [[eosio::wasm_entry]] - void apply( uint64_t receiver, uint64_t code, uint64_t action ) { - if (code == "cyber.token"_n.value) { - if (action == "transfer"_n.value) { - eosio::execute_action(eosio::name(receiver), eosio::name(code), &eosio::incomereject::on_transfer); - } else if (action == "bulktransfer"_n.value) { - dispatch_with_transfer_helper(eosio::name(receiver), eosio::name(code), &eosio::incomereject::on_transfer); - } - } - } -} diff --git a/cyber.msig/src/cyber.msig.cpp b/cyber.msig/src/cyber.msig.cpp index c82c30c07..b25b247ea 100644 --- a/cyber.msig/src/cyber.msig.cpp +++ b/cyber.msig/src/cyber.msig.cpp @@ -201,5 +201,3 @@ void multisig::invalidate( name account ) { } } /// namespace eosio - -EOSIO_DISPATCH( eosio::multisig, (propose)(approve)(unapprove)(cancel)(exec)(invalidate) ) diff --git a/cyber.stake/include/cyber.stake/cyber.stake.hpp b/cyber.stake/include/cyber.stake/cyber.stake.hpp index 186f6a4af..34c790a3f 100644 --- a/cyber.stake/include/cyber.stake/cyber.stake.hpp +++ b/cyber.stake/include/cyber.stake/cyber.stake.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #define table_owner name() @@ -343,7 +344,7 @@ struct structures { [[eosio::action]] void withdraw(name account, asset quantity); - void on_transfer(name from, name to, asset quantity, std::string memo); + ON_TRANSFER(CYBER_TOKEN, on_transfer) void on_transfer(name from, name to, asset quantity, std::string memo); [[eosio::action]] void setproxylvl(name account, symbol_code token_code, uint8_t level); [[eosio::action]] void setproxyfee(name account, symbol_code token_code, int16_t fee); diff --git a/cyber.stake/src/cyber.stake.cpp b/cyber.stake/src/cyber.stake.cpp index 6bd5d5fe2..381e21934 100644 --- a/cyber.stake/src/cyber.stake.cpp +++ b/cyber.stake/src/cyber.stake.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include namespace cyber { @@ -672,10 +671,3 @@ void stake::claim(name grantor_name, name recipient_name, symbol_code token_code } } /// namespace cyber - -DISPATCH_WITH_TRANSFER(cyber::stake, cyber::config::token_name, on_transfer, - (create)(enable)(open)(delegatevote)(setgrntterms)(recallvote)(withdraw) - (setproxylvl)(setproxyfee)(setminstaked)(setkey) - (updatefunds)(reward)(pick) - (delegateuse)(recalluse)(claim) -) diff --git a/cyber.token/src/cyber.token.cpp b/cyber.token/src/cyber.token.cpp index 694ced156..6fe75e6c9 100644 --- a/cyber.token/src/cyber.token.cpp +++ b/cyber.token/src/cyber.token.cpp @@ -281,5 +281,3 @@ void token::bulkpayment(name from, vector recipients) } } /// namespace eosio - -EOSIO_DISPATCH( eosio::token, (create)(issue)(transfer)(bulktransfer)(payment)(bulkpayment)(claim)(open)(close)(retire) )