I'm working on a contract that will run an action when receiving tokens. The following code does not run when the account receives EOS or JUNGLE tokens on the Jungle Testnet.
#include "./test.hpp"
...
void test::init(name username)
{
require_auth(_self);
}
void test::ontransfer(name from, name to, asset quantity, string memo)
{
check(true == false, "sorry not sorry");
}
#include <string>
#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>
#define EOS_SYMBOL symbol("EOS", 4)
CONTRACT test : public eosio::contract
{
using contract::contract;
public:
struct init
{
init(){};
eosio::name name;
EOSLIB_SERIALIZE(init, (name))
};
ACTION init(eosio::name username);
[[eosio::on_notify("eosio.token::transfer")]]
void ontransfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo);
// https://eosio.stackexchange.com/questions/4381/why-is-eosioon-notifyeosio-tokentransfer-not-working
using transfer_action = eosio::action_wrapper<eosio::name("transfer"), &test::ontransfer>;
};
EOSIO_DISPATCH(test, (init))
How can I debug this? Is this a problem of v1.6.1? Is there something wrong with my code?
on_notify
attribute does not work when you explicitly useEOSIO_DISPATCH
, so try to remove the dispatcher as it is no longer mandatory with CDT 1.6.