mirror of
https://github.com/more-tech4-magnum-opus/backend.git
synced 2024-11-21 19:16:33 +03:00
fixed pr, optimised code
This commit is contained in:
parent
7ba849cd29
commit
ae7cfe5166
|
@ -104,7 +104,7 @@ urlpatterns = [
|
|||
),
|
||||
),
|
||||
path(
|
||||
"create_season/",
|
||||
"season/",
|
||||
include([path("", CreateSeasonApi.as_view(), name="create new season")]),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -13,4 +13,6 @@ channels==3.0.5
|
|||
channels-redis==4.0.0
|
||||
|
||||
celery==5.2.7
|
||||
django-celery-beat==2.3.0
|
||||
django-celery-beat==2.3.0
|
||||
|
||||
faker==15.0.0
|
|
@ -3,8 +3,7 @@ from rest_framework.generics import get_object_or_404
|
|||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from common.permissions import IsAdmin
|
||||
from users.api.serializers import UserSerializer, CreateSeasonSerializer
|
||||
from users.models import User
|
||||
from users.api.serializers import CreateSeasonSerializer
|
||||
from users.api.serializers import (
|
||||
UserSerializer,
|
||||
DepartmentSerializer,
|
||||
|
|
|
@ -2,6 +2,8 @@ from django.contrib.auth.models import AbstractUser
|
|||
from django.core.validators import MinValueValidator
|
||||
from django.db import models
|
||||
|
||||
from faker import Faker
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
class WorkerType(models.TextChoices):
|
||||
|
@ -20,8 +22,7 @@ class User(AbstractUser):
|
|||
type = models.CharField(
|
||||
max_length=6, choices=WorkerType.choices, default=WorkerType.WORKER
|
||||
)
|
||||
salary = models.IntegerField(default=0)
|
||||
clan = models.ForeignKey(Clan, on_delete=models.SET_NULL, null=True)
|
||||
clan = models.ForeignKey("users.Clan", on_delete=models.SET_NULL, null=True)
|
||||
command = models.ForeignKey(
|
||||
"users.Command", related_name="workers", on_delete=models.CASCADE
|
||||
)
|
||||
|
@ -75,3 +76,12 @@ class Command(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class Clan(models.Model):
|
||||
name = models.CharField(max_length=100, null=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
name = Faker().name()
|
||||
self.name = name + "'s clan"
|
||||
super(Clan, self).save(*args, **kwargs)
|
||||
|
|
|
@ -4,12 +4,9 @@ import json
|
|||
from time import sleep
|
||||
from typing import List
|
||||
|
||||
URL = 'https://hackathon.lsp.team/hk'
|
||||
URL = "https://hackathon.lsp.team/hk"
|
||||
|
||||
base_headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
base_headers = {"Content-Type": "application/json", "Accept": "application/json"}
|
||||
|
||||
|
||||
class Wallet(BaseModel):
|
||||
|
@ -40,91 +37,98 @@ class TransactionHistory(BaseModel):
|
|||
|
||||
|
||||
def create_wallet() -> Wallet:
|
||||
response = r.post(URL+'/v1/wallets/new')
|
||||
response = r.post(URL + "/v1/wallets/new")
|
||||
data = response.json()
|
||||
return Wallet(publicKey=data['publicKey'], privateKey=data['privateKey'])
|
||||
return Wallet(publicKey=data["publicKey"], privateKey=data["privateKey"])
|
||||
|
||||
|
||||
def check_transaction(trans_hash: str) -> str:
|
||||
res = r.get(URL + '/v1/transfers/status/'+trans_hash, data=json.dumps({
|
||||
'transactionHash': trans_hash
|
||||
}),
|
||||
headers=base_headers
|
||||
res = r.get(
|
||||
URL + "/v1/transfers/status/" + trans_hash,
|
||||
data=json.dumps({"transactionHash": trans_hash}),
|
||||
headers=base_headers,
|
||||
)
|
||||
return res.json()['status']
|
||||
return res.json()["status"]
|
||||
|
||||
|
||||
def transfer_rubbles(my_wallet_private_key, transfer_publick_key: str, amount: float) -> TransHash:
|
||||
response = r.post(URL+'/v1/transfers/ruble', data=json.dumps({
|
||||
"fromPrivateKey": my_wallet_private_key,
|
||||
"toPublicKey": transfer_publick_key,
|
||||
"amount": amount
|
||||
}),
|
||||
headers={
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
def transfer_rubbles(
|
||||
my_wallet_private_key, transfer_publick_key: str, amount: float
|
||||
) -> TransHash:
|
||||
response = r.post(
|
||||
URL + "/v1/transfers/ruble",
|
||||
data=json.dumps(
|
||||
{
|
||||
"fromPrivateKey": my_wallet_private_key,
|
||||
"toPublicKey": transfer_publick_key,
|
||||
"amount": amount,
|
||||
}
|
||||
),
|
||||
headers={"Content-Type": "application/json", "Accept": "application/json"},
|
||||
)
|
||||
return TransHash(transaction_hash=response.json()['transaction'])
|
||||
return TransHash(transaction_hash=response.json()["transaction"])
|
||||
|
||||
|
||||
def create_nft(wallet_public_key: str, string_url: str) -> TransHash:
|
||||
response = r.post(URL + '/v1/nft/generate', data=json.dumps(
|
||||
{
|
||||
"toPublicKey": wallet_public_key,
|
||||
"uri": string_url,
|
||||
"nftCount": 1
|
||||
}
|
||||
response = r.post(
|
||||
URL + "/v1/nft/generate",
|
||||
data=json.dumps(
|
||||
{"toPublicKey": wallet_public_key, "uri": string_url, "nftCount": 1}
|
||||
),
|
||||
headers=base_headers
|
||||
headers=base_headers,
|
||||
)
|
||||
return TransHash(transaction_hash=response.json()['transaction_hash'])
|
||||
return TransHash(transaction_hash=response.json()["transaction_hash"])
|
||||
|
||||
|
||||
def get_nfts(wallet_public_key: str) -> List[NftInfo]:
|
||||
res = r.get(URL+f'/v1/wallets/{wallet_public_key}/nft/balance')
|
||||
res = r.get(URL + f"/v1/wallets/{wallet_public_key}/nft/balance")
|
||||
print(res.json())
|
||||
return list(
|
||||
map(
|
||||
lambda res: NftInfo(
|
||||
uri=res['uri'],
|
||||
tokens=res['tokens']
|
||||
),
|
||||
res.json()['balance']
|
||||
),
|
||||
)
|
||||
lambda res: NftInfo(uri=res["uri"], tokens=res["tokens"]),
|
||||
res.json()["balance"],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def get_history(wallet_public_key: str) -> List[TransactionHistory]:
|
||||
res = r.post(URL+f'/v1/wallets/{wallet_public_key}/history', data=json.dumps({
|
||||
"page": 0,
|
||||
"offset": 100,
|
||||
"sort": "asc"
|
||||
|
||||
}), headers=base_headers)
|
||||
res = r.post(
|
||||
URL + f"/v1/wallets/{wallet_public_key}/history",
|
||||
data=json.dumps({"page": 0, "offset": 100, "sort": "asc"}),
|
||||
headers=base_headers,
|
||||
)
|
||||
return list(
|
||||
map(
|
||||
lambda res: TransactionHistory(
|
||||
hash=res['hash'],
|
||||
timestamp=res['timeStamp'],
|
||||
token_name=res['tokenName'],
|
||||
from_wallet=res['from'],
|
||||
to_wallet=res['to']
|
||||
),
|
||||
res.json()['history']
|
||||
hash=res["hash"],
|
||||
timestamp=res["timeStamp"],
|
||||
token_name=res["tokenName"],
|
||||
from_wallet=res["from"],
|
||||
to_wallet=res["to"],
|
||||
),
|
||||
)
|
||||
res.json()["history"],
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def transfer_nft(my_private_wallet_key: str, transfer_publick_key: str, token_id: int) -> TransHash:
|
||||
res = r.post(URL+'/v1/transfers/nft', data=json.dumps(
|
||||
{
|
||||
"fromPrivateKey": my_private_wallet_key,
|
||||
"toPublicKey": transfer_publick_key,
|
||||
"tokenId": token_id
|
||||
}
|
||||
), headers=base_headers)
|
||||
return TransHash(transaction_hash=res.json()['transaction_hash'])
|
||||
def transfer_nft(
|
||||
my_private_wallet_key: str, transfer_publick_key: str, token_id: int
|
||||
) -> TransHash:
|
||||
res = r.post(
|
||||
URL + "/v1/transfers/nft",
|
||||
data=json.dumps(
|
||||
{
|
||||
"fromPrivateKey": my_private_wallet_key,
|
||||
"toPublicKey": transfer_publick_key,
|
||||
"tokenId": token_id,
|
||||
}
|
||||
),
|
||||
headers=base_headers,
|
||||
)
|
||||
return TransHash(transaction_hash=res.json()["transaction_hash"])
|
||||
|
||||
def get_balance(my_public_wallet_key: str) -> WalletBalance:
|
||||
res = r.get(URL+f'/v1/wallets/{my_public_wallet_key}/balance')
|
||||
return WalletBalance(matic=res.json()['maticAmount'], coins=res.json()['coinsAmount'])
|
||||
|
||||
def get_balance(my_public_wallet_key: str) -> WalletBalance:
|
||||
res = r.get(URL + f"/v1/wallets/{my_public_wallet_key}/balance")
|
||||
return WalletBalance(
|
||||
matic=res.json()["maticAmount"], coins=res.json()["coinsAmount"]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user