Skip to content

Commit

Permalink
Migrate to auto-generated dispatchers #286
Browse files Browse the repository at this point in the history
  • Loading branch information
soft-bagel-93 committed Jan 31, 2020
1 parent 3e19f14 commit 603aef2
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 59 deletions.
3 changes: 3 additions & 0 deletions common/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 10 additions & 14 deletions common/dispatchers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "config.hpp"
#include <eosio/dispatcher.hpp>
#include <cyber.token/cyber.token.hpp>

template<typename T, typename... Args>
bool dispatch_with_transfer_helper( eosio::name self, eosio::name code, void (T::*func)(Args...) ) {
Expand Down Expand Up @@ -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<eosio::token::recipient> recipients) { \
for (auto& recipient : recipients) { \
ON_TRANSFER_HANDLER(from, recipient.to, recipient.quantity, recipient.memo); \
} \
} \
ON_SIMPLE_TRANSFER(TOKEN)
5 changes: 3 additions & 2 deletions cyber.bios/include/cyber.bios/cyber.bios.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <eosio/producer_schedule.hpp>
#include <eosio/singleton.hpp>
#include <eosio/time.hpp>
#include <common/dispatchers.hpp>

namespace cyber {
using eosio::permission_level;
Expand Down Expand Up @@ -163,8 +164,8 @@ namespace cyber {

[[eosio::action]] void onblock(ignore<block_header> 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);

};

Expand Down
7 changes: 0 additions & 7 deletions cyber.bios/src/cyber.bios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <cyber.govern/cyber.govern.hpp>
#include <cyber.token/cyber.token.hpp>
#include <cyber.stake/cyber.stake.hpp>
#include <common/dispatchers.hpp>

#include <eosio/system.hpp>

Expand Down Expand Up @@ -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)
)


6 changes: 0 additions & 6 deletions cyber.domain/cyber.domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <common/config.hpp>
#include <cyber.token/cyber.token.hpp>
#include <eosio/eosio.hpp>
#include <eosio/dispatcher.hpp>

#include "domain_validate.cpp"

Expand Down Expand Up @@ -169,8 +168,3 @@ void domain::declarenames(const std::vector<name_info>& domains) {
}

} // eosiosystem


EOSIO_DISPATCH(eosiosystem::domain,
(newdomain)(checkwin)(biddomain)(biddmrefund)(declarenames)
)
2 changes: 0 additions & 2 deletions cyber.govern/src/cyber.govern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,3 @@ void govern::maybe_promote_producers() {
}

}

EOSIO_DISPATCH( cyber::govern, (onblock)(setactprods))
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>
#include <common/dispatchers.hpp>

namespace eosio {

class [[eosio::contract("cyber.incomereject")]] incomereject : public contract {
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
14 changes: 0 additions & 14 deletions cyber.incomereject/src/cyber.incomereject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <cyber.incomereject/cyber.incomereject.hpp>
#include <cyber.token/cyber.token.hpp>
#include <common/dispatchers.hpp>

namespace eosio {

Expand All @@ -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);
}
}
}
}
2 changes: 0 additions & 2 deletions cyber.msig/src/cyber.msig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,3 @@ void multisig::invalidate( name account ) {
}

} /// namespace eosio

EOSIO_DISPATCH( eosio::multisig, (propose)(approve)(unapprove)(cancel)(exec)(invalidate) )
3 changes: 2 additions & 1 deletion cyber.stake/include/cyber.stake/cyber.stake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <tuple>
#include <eosio/privileged.hpp>
#include <common/util.hpp>
#include <common/dispatchers.hpp>

#define table_owner name()

Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions cyber.stake/src/cyber.stake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <algorithm>
#include <cyber.stake/cyber.stake.hpp>
#include <cyber.token/cyber.token.hpp>
#include <common/dispatchers.hpp>
#include <common/parameter_ops.hpp>

namespace cyber {
Expand Down Expand Up @@ -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)
)
2 changes: 0 additions & 2 deletions cyber.token/src/cyber.token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,3 @@ void token::bulkpayment(name from, vector<recipient> recipients)
}

} /// namespace eosio

EOSIO_DISPATCH( eosio::token, (create)(issue)(transfer)(bulktransfer)(payment)(bulkpayment)(claim)(open)(close)(retire) )

0 comments on commit 603aef2

Please sign in to comment.