require_auth2 is used in action.hpp's require_auth.

void require_auth(const permission_level& level) {
    require_auth2( level.actor, level.permission );

require_auth2 is declared in action.h.

void require_auth2( account_name name, permission_name permission );

I can not find a definition for require_auth2. Where is the definition of this? What logic does it handle?


What does it do:

With require_auth2 you are specifying both the account name and the permission level you need.

You would call require_auth2 as follows:

    require_auth2(account_name, N(permission));

Where permission can be owner, active, or some other permission that you may have configured for this account.

require_auth is a shortcut to:

     require_auth2(account_name, N(active));

Where is it defined:

require_auth2 appears to be defined via REGISTER_INTRINSICS and eventually it calls (in apply_context.cpp):

 void apply_context::require_authorization

But I don't have the C++ chops to understand how that works exactly.

  • can you give me some explanation of the REGISTER_INTRINSICS, the macro is too difficult to understand – Jimmy Guo Jul 13 '18 at 2:18

require_auth2 is defined via REGISTER_INTRINSICS,it call the function of class authorization_api. Finally,it's implemented in apply_context.require_authorization( account, permission ).

The macro REGISTER_INTRINSICS is apply for compiler intrinsics,it expand to:

_REGISTER_INTRINSIC(r,authorization_api,(require_authorization, void(int64_t, int64_t), "require_auth2", void(authorization_api::*)(const account_name&, const permission_name& permission) ))

According to args number,continue to expand to:

_REGISTER_INTRINSIC4(authorization_api,MOD,require_authorization,void(int64_t, int64_t),"require_auth2",void(authorization_api::*)(const account_name&, const permission_name& permission))(authorization_api,"env",(require_authorization, void(int64_t, int64_t), "require_auth2", void(authorization_api::*)(const account_name&, const permission_name& permission) ))

Eventually,choose wavm or binaryen compiler to process it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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