-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9860b45
commit b92e3fd
Showing
13 changed files
with
180 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,41 @@ | ||
from datetime import datetime | ||
from typing import Tuple | ||
from typing import List, Optional, Tuple | ||
|
||
from app.context.epoch_state import EpochState | ||
from app.context.manager import state_context | ||
from app.modules.registry import get_services | ||
|
||
|
||
def get_user_antisybil_status(user_address: str) -> Tuple[int, datetime]: | ||
def get_user_antisybil_status( | ||
user_address: str, | ||
) -> Optional[Tuple[Tuple[int, datetime], Tuple[bool, List[str]]]]: | ||
context = state_context(EpochState.CURRENT) | ||
service = get_services(context.epoch_state).user_antisybil_passport_service | ||
return service.get_antisybil_status(context, user_address) | ||
passport = get_services(context.epoch_state).user_antisybil_passport_service | ||
passport_status = passport.get_antisybil_status(context, user_address) | ||
holonym = get_services(context.epoch_state).user_antisybil_holonym_service | ||
holonym_status = holonym.get_sbt_status(context, user_address) | ||
if passport_status is None or holonym_status is None: | ||
return None | ||
|
||
return (passport_status, holonym_status) | ||
|
||
def update_user_antisybil_status(user_address: str) -> Tuple[int, datetime]: | ||
|
||
def update_user_antisybil_status( | ||
user_address: str, | ||
) -> Tuple[Tuple[int, datetime], Tuple[bool, List[str]]]: | ||
context = state_context(EpochState.CURRENT) | ||
service = get_services(context.epoch_state).user_antisybil_passport_service | ||
passport = get_services(context.epoch_state).user_antisybil_passport_service | ||
|
||
score, expires_at, all_stamps = service.fetch_antisybil_status( | ||
score, expires_at, all_stamps = passport.fetch_antisybil_status( | ||
context, user_address | ||
) | ||
service.update_antisybil_status( | ||
passport.update_antisybil_status( | ||
context, user_address, score, expires_at, all_stamps | ||
) | ||
return service.get_antisybil_status(context, user_address) | ||
|
||
holonym = get_services(context.epoch_state).user_antisybil_holonym_service | ||
|
||
has_sbt, cred_type = holonym.fetch_sbt_status(context, user_address) | ||
holonym.update_sbt_status(context, user_address, has_sbt, cred_type) | ||
|
||
return ((score, expires_at), (has_sbt, cred_type)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from flask import current_app as app | ||
|
||
from eth_utils.address import to_checksum_address | ||
|
||
import json | ||
from typing import List, Optional, Tuple | ||
|
||
from app.extensions import db | ||
from app.infrastructure import database | ||
from app.context.manager import Context | ||
from app.pydantic import Model | ||
from app.exceptions import UserNotFound | ||
|
||
|
||
class HolonymAntisybil(Model): | ||
def get_sbt_status( | ||
self, _: Context, user_address: str | ||
) -> Optional[Tuple[bool, List[str]]]: | ||
user_address = to_checksum_address(user_address) | ||
try: | ||
entry = database.user_antisybil.get_sbt_by_address(user_address) | ||
except UserNotFound as ex: | ||
app.logger.debug( | ||
f"User {user_address} antisybil status: except UserNotFound" | ||
) | ||
raise ex | ||
|
||
if entry is not None: | ||
return entry.has_sbt, json.loads(entry.sbt_details) | ||
return None | ||
|
||
def fetch_sbt_status( | ||
self, _: Context, user_address: str | ||
) -> Optional[Tuple[bool, List[str]]]: | ||
from app.infrastructure.external_api.holonym.antisybil import check | ||
|
||
user_address = to_checksum_address(user_address) | ||
return check(user_address) | ||
|
||
def update_sbt_status( | ||
self, _: Context, user_address: str, has_sbt: bool, cred_type: List[str] | ||
): | ||
database.user_antisybil.add_sbt(user_address, has_sbt, cred_type) | ||
db.session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.