4

I know a very similar question has been asked here (How to do something when your contract is an action notification recipient (like when it receives funds)?), however I don't have enough reputation to ask a follow up question to that answer, so I open a new question.

As mentioned in that answer, extending the EOSIO_ABI macro with a statement like "if( code == self || code == N(eosio.token) || action == N(onerror) )" can trigger the "transfer" function in your contract when a eosio.token transfer notification is received. However, what if I already have another function named "transfer" with a different purpose? How can I map the eosio.token transfer notification to a function that has a different name?

1
  • can't understand, can you speak Chinese?
    – Jimmy Guo
    Commented Jun 25, 2018 at 14:41

2 Answers 2

1

Create a transfer action and a transfer_b action in the contract. Call tranfer_b as an inline action in the transfer action.

Do not change 'apply' and use it as macro generated it.

Use 'SEND_INLINE_ACTION' when calling 'transfer_b' in an inline action with a transfer action.

For an example of this, see the issue action of the following code. https://sourcegraph.com/github.com/EOSIO/eos/-/blob/contracts/eosio.token/eosio.token.cpp#L32:65

0

code is the contract processing the message, action is which action is called. these two condition is enough to identify which transfer is used.

2
  • Thanks for your reply!! I understand how to identify which contract the action is from, however I don't understand how to call the action that has a different name from the original action. Say I want to call an action named transfer_b when I receive a transfer notification from eosio.token, I believe I need to modify the "MEMBERS" in "switch( action ) {EOSIO_API( TYPE, MEMBERS)}" in the macro, however I just have no idea how to modify it, I couldn't find any documentation about these macros.
    – mochunhei
    Commented Jun 27, 2018 at 5:38
  • if(code == N(eosio.token) && action == N(transfer)) {you call trasnfer_b}
    – bread1984
    Commented Jul 8, 2018 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.