Skip to content

Commit

Permalink
Merge pull request #228 from UnitapApp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Bastin authored Dec 17, 2023
2 parents 0bdf936 + 3203e2a commit cd1e771
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 201 deletions.
34 changes: 13 additions & 21 deletions authentication/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.db import models
from django.contrib.auth.models import User
from authentication.helpers import BRIGHTID_SOULDBOUND_INTERFACE
from django.utils import timezone
from django.core.validators import RegexValidator
from django.core.cache import cache
from django.core.validators import RegexValidator
from django.db import models
from django.utils import timezone

from authentication.helpers import BRIGHTID_SOULDBOUND_INTERFACE
from core.models import NetworkTypes


class ProfileManager(models.Manager):
Expand Down Expand Up @@ -73,6 +75,9 @@ def save(self, *args, **kwargs):
self.username = f"User{self.pk}"
super().save(*args, **kwargs)

def __str__(self) -> str:
return self.username if self.username else f"User{self.pk}"

@staticmethod
def user_count():
cached_user_count = cache.get("user_profile_count")
Expand All @@ -83,22 +88,6 @@ def user_count():
return count


class NetworkTypes:
EVM = "EVM"
SOLANA = "Solana"
LIGHTNING = "Lightning"
NONEVM = "NONEVM"
NONEVMXDC = "NONEVMXDC"

networks = (
(EVM, "EVM"),
(SOLANA, "Solana"),
(LIGHTNING, "Lightning"),
(NONEVM, "NONEVM"),
(NONEVMXDC, "NONEVMXDC"),
)


class Wallet(models.Model):
wallet_type = models.CharField(choices=NetworkTypes.networks, max_length=10)
user_profile = models.ForeignKey(
Expand All @@ -110,4 +99,7 @@ class Meta:
unique_together = (("wallet_type", "user_profile"),)

def __str__(self):
return f"{self.wallet_type} Wallet for profile with contextId {self.user_profile.initial_context_id}"
return (
f"{self.wallet_type} Wallet for profile with contextId "
f"{self.user_profile.initial_context_id}"
)
14 changes: 8 additions & 6 deletions core/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from django.core.exceptions import ImproperlyConfigured

from authentication.models import UserProfile


class ConstraintParam(Enum):
CHAIN = "chain"
Expand All @@ -25,7 +23,7 @@ class ConstraintVerification(ABC):
_param_keys = []
__response_text = ""

def __init__(self, user_profile: UserProfile) -> None:
def __init__(self, user_profile) -> None:
self.user_profile = user_profile
self._param_values = {}

Expand Down Expand Up @@ -61,7 +59,9 @@ def is_valid_param_keys(cls, keys):

@property
def response(self) -> str:
return self.__response_text or f"{self.__class__.__name__} constraint is violated"
return (
self.__response_text or f"{self.__class__.__name__} constraint is violated"
)

@response.setter
def response(self, text: str):
Expand All @@ -81,7 +81,7 @@ def is_observed(self, *args, **kwargs):
class HasNFTVerification(ConstraintVerification):
_param_keys = [ConstraintParam.CHAIN, ConstraintParam.ADDRESS, ConstraintParam.ID]

def __init__(self, user_profile: UserProfile, response: str = None) -> None:
def __init__(self, user_profile, response: str = None) -> None:
super().__init__(user_profile, response)

def is_observed(self, *args, **kwargs):
Expand All @@ -98,4 +98,6 @@ def get_constraint(constraint_label: str) -> ConstraintVerification:
constraint_class = getattr(constraints_module, constraint_name)
return constraint_class
except (ModuleNotFoundError, AttributeError):
raise ImproperlyConfigured(f"Constraint '{constraint_name}' not found in any app.")
raise ImproperlyConfigured(
f"Constraint '{constraint_name}' not found in any app."
)
128 changes: 64 additions & 64 deletions core/migrations/0005_auto_20231203_0832.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,68 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunSQL("""
INSERT INTO core_walletaccount (
id,
name,
private_key,
network_type
)
SELECT
id,
name,
private_key,
network_type
FROM
faucet_walletaccount;
INSERT INTO core_chain (
id,
chain_name,
symbol,
chain_id,
rpc_url,
decimals,
explorer_url,
logo_url,
native_currency_name,
poa,
rpc_url_private,
wallet_id,
modal_url,
max_gas_price,
gas_multiplier,
chain_type,
is_testnet,
is_active,
enough_fee_multiplier,
explorer_api_key,
explorer_api_url
)
SELECT
id,
chain_name,
symbol,
chain_id,
rpc_url,
decimals,
explorer_url,
logo_url,
native_currency_name,
poa,
rpc_url_private,
wallet_id,
modal_url,
max_gas_price,
gas_multiplier,
chain_type,
is_testnet,
is_active,
enough_fee_multiplier,
explorer_api_key,
explorer_api_url
FROM
faucet_chain;
SELECT setval(pg_get_serial_sequence('"core_walletaccount"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "core_walletaccount";
SELECT setval(pg_get_serial_sequence('"core_chain"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "core_chain";
""", reverse_sql="")
# migrations.RunSQL("""
# INSERT INTO core_walletaccount (
# id,
# name,
# private_key,
# network_type
# )
# SELECT
# id,
# name,
# private_key,
# network_type
# FROM
# faucet_walletaccount;
# INSERT INTO core_chain (
# id,
# chain_name,
# symbol,
# chain_id,
# rpc_url,
# decimals,
# explorer_url,
# logo_url,
# native_currency_name,
# poa,
# rpc_url_private,
# wallet_id,
# modal_url,
# max_gas_price,
# gas_multiplier,
# chain_type,
# is_testnet,
# is_active,
# enough_fee_multiplier,
# explorer_api_key,
# explorer_api_url
# )
# SELECT
# id,
# chain_name,
# symbol,
# chain_id,
# rpc_url,
# decimals,
# explorer_url,
# logo_url,
# native_currency_name,
# poa,
# rpc_url_private,
# wallet_id,
# modal_url,
# max_gas_price,
# gas_multiplier,
# chain_type,
# is_testnet,
# is_active,
# enough_fee_multiplier,
# explorer_api_key,
# explorer_api_url
# FROM
# faucet_chain;
# SELECT setval(pg_get_serial_sequence('"core_walletaccount"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "core_walletaccount";
# SELECT setval(pg_get_serial_sequence('"core_chain"','id'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "core_chain";
# """, reverse_sql="")
]
7 changes: 5 additions & 2 deletions faucet/faucet_manager/claim_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from django.db import transaction
from django.utils import timezone

from authentication.models import NetworkTypes, UserProfile
from authentication.models import UserProfile
from core.models import NetworkTypes
from faucet.faucet_manager.credit_strategy import (
CreditStrategy,
CreditStrategyFactory,
Expand Down Expand Up @@ -36,7 +37,9 @@ def fund_manager(self):

def claim(self, amount, passive_address=None):
with transaction.atomic():
user_profile = UserProfile.objects.select_for_update().get(pk=self.credit_strategy.user_profile.pk)
user_profile = UserProfile.objects.select_for_update().get(
pk=self.credit_strategy.user_profile.pk
)
self.assert_pre_claim_conditions(amount, user_profile)
return self.create_pending_claim_receipt(
amount, passive_address
Expand Down
Loading

0 comments on commit cd1e771

Please sign in to comment.