Thanks in advance for any help.
I can't seem to get on_notify to work (attempting to trigger for any tokens sent to the contract, but for the example I've tested both * and eosio.token)
The method:
[[eosio::on_notify("eosio.token::transfer")]]void mycontract::transfer( name from, name to, asset quantity, string memo){
addstatest(1000);
}
Addstats/table declaration:
void competeos::addstatest(int amount){
stats_def statstable(_self, _self.value);
stat newstats;
if(!statstable.exists()){
statstable.set(newstats, _self);
}else{
newstats = statstable.get();
}
newstats.counter += amount;
statstable.set((newstats), _self);
}
typedef eosio::singleton<"stats"_n, stat> stats_def;
//tested with and without this stats line, here for another issue...
typedef eosio::multi_index<"stats"_n, stat> dump_for_stats_def;
I'm sure that the addstattest method works because an exact copy of it is also set up as addstat as an action, and it works reliably.
As a side note, although the stats table counter does increase over time, whenever i query the table/singleton using cleos/a ram explorer, it always displays 1111115 - although other methods in my code show such as the addstat action show that it is increasing when I access it in ways that it sets the value, it just isn't directly query-able for some reason. If anyone has any insight here as well, it would be appreciated.
Anyways back to the initial question - I can't get the on_notify transfer method to trigger when tokens (eosio.token EOS tokens on the kylin network from another test account, in this case) are sent to it. This addstattest method seems like the easiest trace-able way to seeing whether it's triggering or not, as there's no requireauth in there or anything, but the only other requirement I've seen are to set permissions, which I've done using two methods:
cleos -u $BP_URL set account permission myaccountname myaccountname --add-code -p myaccountname@owner
as well as
cleos -u $BP_URL set account permission myaccountname active '{"threshold" : 1, "keys" : [{"key": "ActiveAccountPublicKey", "weight": 1}], "accounts" : [{"permission":{"actor": "myaccountname" ,"permission":"eosio.code"},"weight":1}], "waits":[]}}' owner -p nyaccountname@owner
Finally, I've also separated my code into an hpp file and cpp file so that the declaration for the on_notify is instantiated in the header (this was recommended to me by someone in the telegram channel).
Otherwise, there's little documentation on the use of this functionality, but it also seems like it should be pretty straight-forward. Any help would be greatly appreciated.