Is there any possibility to implement conditional require_auth(<condition>)
or what is a good practice to make contract accept invocations from a set of predetermined accounts? Is there any analogue of solidity's msg.sender
in EOS?
It seems that the documentation for require_auth2 is missing.
Example: I need the contract to require authorization from account walletxxxxxx
OR walletzzzzzz
.
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
using namespace eosio;
class [[eosio::contract("tmp")]] tmp : public eosio::contract {
public:
using contract::contract;
tmp(name receiver, name code, datastream<const char*> ds): contract(receiver, code, ds) {}
// Bad practice of multiauth implementation.
[[eosio::action]]
void multiauth(name user) {
// Allow only `walletxxxxxx` OR `walletzzzzzz`
// to call this function.
if (user == name("walletxxxxxx"))
{
require_auth(name("walletxxxxxx"));
}
else if (user == name("walletzzzzzz"))
{
require_auth(name("walletzzzzzz"));
}
else
{
require_auth(name(get_self()));
}
// DO SOMETHING
}
private:
};
EOSIO_DISPATCH( tmp, (multiauth) )
Honestly, the above contract can solve my problem, but it does not look like a good practice. I'm looking for any relevant documentation in regards to this issue.