Sometimes we have to stop our service for system upgrades, repairs...
So is there any way to stop receiving token from another account?
Yes. You can freeze your contract by creating a multi_index
table that indicates whether the account is frozen or not.
When a token is received, you can assert on whether the account is frozen or not.
You can create an action to set the frozen status of the contract.
Example:
class [[eosio::table]] freeze
{
public:
uint64_t id;
bool frozen;
uint64_t primary_key() const {return id;}
};
typedef eosio::multi_index< eosio::name("freeze"), freeze > freeze_table;
void mycontract::freeze(bool frozen)
{
freeze_table.modify(freeze_table.find(0), _self, [&](auto & table)
{
table.frozen = frozen;
});
}
// This has to be linked to the eosio.token transfer in the apply function
void mycontract::transfer(eosio::name from,
eosio::name to,
eosio::asset quantity,
std::string memo)
{
freeze_table ftab(_self, _self.value);
auto isfrozen = ftab.find(0);
eosio::check(isfrozen != ftab.end(),"Freeze table not initialized");
eosio::check(!isfrozen->frozen,"Account is frozen, no funds currently being accepted");
}
frozen
to true) will see an error message and the transfer will fail.
Commented
Feb 16, 2019 at 15:37