Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Mart committed Dec 12, 2024
1 parent 46b0744 commit 0742dfc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ namespace SystemService
void setOwner(psibase::AccountNumber owner);

private:
Tables db{psibase::getReceiver()};
Tables db{psibase::getReceiver()};
psibase::AccountNumber getOwner(psibase::AccountNumber account);
};
PSIO_REFLECT(AuthDelegate, //
method(checkAuthSys, flags, requester, sender, action, allowedActions, claims),
Expand Down
19 changes: 11 additions & 8 deletions services/system/AuthDelegate/src/AuthDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ namespace SystemService

void AuthDelegate::canAuthUserSys(psibase::AccountNumber user)
{
auto row = db.open<AuthDelegateTable>().getIndex<0>().get(user);
check(row.has_value(), "sender does not have an owning account");
// Asserts if no owner is set for the user
getOwner(user);
}

bool AuthDelegate::isAuthSys(psibase::AccountNumber sender,
std::vector<psibase::AccountNumber> authorizers)
{
auto record = db.open<AuthDelegateTable>().getIndex<0>().get(sender);
check(record.has_value(), "sender does not have an owning account");
auto owner = record->owner;
auto owner = getOwner(sender);

if (std::ranges::contains(authorizers, owner))
return true;
Expand All @@ -57,9 +55,7 @@ namespace SystemService
bool AuthDelegate::isRejectSys(psibase::AccountNumber sender,
std::vector<psibase::AccountNumber> rejecters)
{
auto record = db.open<AuthDelegateTable>().getIndex<0>().get(sender);
check(record.has_value(), "sender does not have an owning account");
auto owner = record->owner;
auto owner = getOwner(sender);

if (std::ranges::contains(rejecters, owner))
return true;
Expand All @@ -76,6 +72,13 @@ namespace SystemService
authTable.put(AuthDelegateRecord{.account = getSender(), .owner = owner});
}

psibase::AccountNumber AuthDelegate::getOwner(psibase::AccountNumber account)
{
auto row = db.open<AuthDelegateTable>().getIndex<0>().get(account);
check(row.has_value(), "account does not have an owning account");
return row->owner;
}

} // namespace SystemService

PSIBASE_DISPATCH(SystemService::AuthDelegate)

0 comments on commit 0742dfc

Please sign in to comment.