def METHOD_NAME(next_timestamp):
    async def _backend_realm_generate_certif_and_update_roles(
        backend, author, realm_id, user_id, role, timestamp=None
    ):
        now = timestamp or next_timestamp()
        certif = RealmRoleCertificate(
            author=author.device_id, timestamp=now, realm_id=realm_id, user_id=user_id, role=role
        ).dump_and_sign(author.signing_key)
        await backend.realm.update_roles(
            author.organization_id,
            RealmGrantedRole(
                certificate=certif,
                realm_id=realm_id,
                user_id=user_id,
                role=role,
                granted_by=author.device_id,
                granted_on=now,
            ),
        )
        return certif
    return _backend_realm_generate_certif_and_update_roles