Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile failed in 1.6.1 when using [[eosio::on_notify("*::transfer")]] #497

Closed
darkdong opened this issue Apr 13, 2019 · 9 comments

Comments

@darkdong
Copy link

commented Apr 13, 2019

error: else expression without matching if
000035b: error: OnElseExpr callback failed

but if I use [[eosio::on_notify("eosio.token::transfer")]], compilation is success

@cc32d9

This comment has been minimized.

Copy link

commented Apr 13, 2019

@slyon

This comment has been minimized.

Copy link

commented Apr 17, 2019

@cc32d9 what was your solution to the problem?

@cc32d9

This comment has been minimized.

Copy link

commented Apr 17, 2019

@cc32d9 what was your solution to the problem?

well I keep the old version of the contract under CDT 1.5. Sitting pretty, waiting for it to resolve by itself :)

@slyon

This comment has been minimized.

Copy link

commented Apr 17, 2019

I see ;-)

I found another work around, by implementing a dummy action, to satisfy the compiler:
slyon/signup@3ed561f#diff-fec48f310f6df993532e742d7fec6b2aR28

@larryk85

This comment has been minimized.

Copy link
Contributor

commented Apr 18, 2019

There is a fix for this and a few other fixes in branch release_1.6.x_fixes, but yeah if you create another "dummy" notification with a non wildcard ("*") specifier that also works around the issue.

@cc32d9

This comment has been minimized.

Copy link

commented Apr 18, 2019

@larryk85 thanks for letting us know. I'm not in a hurry, will wait for a release

@pkuphy

This comment has been minimized.

Copy link

commented Jul 7, 2019

EDIT: you don't need this workaround since the release of eosio.cdt 1.6.2

Workaround in detail:

  • hello.hpp
#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>

using namespace eosio;
using namespace std;

CONTRACT hello : public contract {
public:
    using contract::contract;

    ACTION hi( name nm );

    using hi_action = action_wrapper<"hi"_n, &hello::hi>;

    [[eosio::on_notify("dummy::dummy")]]
    void dummy();

    [[eosio::on_notify("*::transfer")]]
    void transfer_handler(name from, name to, const asset &quantity, string memo);

};
  • hello.cpp
#include "hello.hpp"

ACTION hello::hi( name nm ) {
   /* fill in action body */
   print_f("Name : %\n",nm);
}

void hello::dummy() {print("DUMMY");}

void hello::transfer_handler(name from, name to, const asset &quantity, string memo) {
    print_f("Name : %\n",from);
}

As @larryk85 mentioned:

you create another "dummy" notification with a non wildcard ("*") specifier

@AaronZgl

This comment has been minimized.

Copy link

commented Jul 15, 2019

You have to specify a special account before using the “*“.
if you want to use [[eosio::on_notify("*::${action}")]],
you have to use [[eosio::on_notify("${account}::${action}")]] before that.
for example:

 [[eosio::on_notify("my_account::notify_action")]]
 void on_notify_self(){ print("This is a notice from myself."); }

 [[eosio::on_notify("*::notify_action")]]
 void on_notify_other(){ print("This is a notice from someone else."); }

the special account like if and the * like else.

@jeffreyssmith2nd

This comment has been minimized.

Copy link

commented Jul 17, 2019

This has been fixed in 1.6.2. You can see an example using the following code

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

using namespace eosio;
using namespace std;

CONTRACT hello : public contract {
public:
    using contract::contract;

    ACTION hi( name nm ) {
       /* fill in action body */
       print_f("Name : %\n",nm);
    }

    [[eosio::on_notify("*::transfer")]]
    void transfer_handler(name from, name to, const asset &quantity, string memo) {
        print_f("Name : %\n",from);
    }

};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.