xync-schema 0.0.34.dev1__tar.gz → 0.0.34.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xync_schema-0.0.34.dev1/xync_schema.egg-info → xync_schema-0.0.34.dev2}/PKG-INFO +1 -1
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema/models.py +35 -12
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2/xync_schema.egg-info}/PKG-INFO +1 -1
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/.env.sample +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/.gitignore +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/.pre-commit-config.yaml +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/README.md +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/makefile +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/pyproject.toml +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/setup.cfg +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/tests/__init__.py +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/tests/test_db.py +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema/__init__.py +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema/enums.py +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema/xtype.py +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema.egg-info/SOURCES.txt +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema.egg-info/dependency_links.txt +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema.egg-info/requires.txt +0 -0
- {xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema.egg-info/top_level.txt +0 -0
|
@@ -301,7 +301,7 @@ class User(TgUser, TsTrait):
|
|
|
301
301
|
async def balance_sum(self) -> int:
|
|
302
302
|
return int(await self.free_assets()) + int(await self.fiats_sum())
|
|
303
303
|
|
|
304
|
-
async def balance_xp(self, cur_id: int = None) -> dict[int, int] |
|
|
304
|
+
async def balance_xp(self, cur_id: int = None) -> dict[int, int] | float:
|
|
305
305
|
if cur_id:
|
|
306
306
|
dbt = (
|
|
307
307
|
await Transaction.filter(receiver=self, cur_id=cur_id) # , status=TransactionStatus.valid
|
|
@@ -315,20 +315,23 @@ class User(TgUser, TsTrait):
|
|
|
315
315
|
.annotate(credit=Sum("amount"))
|
|
316
316
|
.values_list("credit", flat=True)
|
|
317
317
|
) or [0]
|
|
318
|
-
|
|
318
|
+
scale = (await Cur[cur_id]).scale
|
|
319
|
+
return (dbt[0] - crd[0]) * 10 ** (-scale)
|
|
319
320
|
dbt = {
|
|
320
|
-
c: v
|
|
321
|
-
for c, v in await Transaction.filter(receiver=self, status=TransactionStatus.valid)
|
|
322
|
-
.
|
|
321
|
+
c: v * 10 ** (-s)
|
|
322
|
+
for c, v, s in await Transaction.filter(receiver=self, status=TransactionStatus.valid)
|
|
323
|
+
.prefetch_related("cur")
|
|
324
|
+
.group_by("cur_id", "cur__scale")
|
|
323
325
|
.annotate(debit=Sum("amount"))
|
|
324
|
-
.values_list("cur_id", "debit")
|
|
326
|
+
.values_list("cur_id", "debit", "cur__scale")
|
|
325
327
|
}
|
|
326
328
|
crd = {
|
|
327
|
-
c: v
|
|
328
|
-
for c, v in await Transaction.filter(sender=self, status=TransactionStatus.valid)
|
|
329
|
-
.
|
|
329
|
+
c: v * 10 ** (-s)
|
|
330
|
+
for c, v, s in await Transaction.filter(sender=self, status=TransactionStatus.valid)
|
|
331
|
+
.prefetch_related("cur")
|
|
332
|
+
.group_by("cur_id", "cur__scale")
|
|
330
333
|
.annotate(credit=Sum("amount"))
|
|
331
|
-
.values_list("cur_id", "credit")
|
|
334
|
+
.values_list("cur_id", "credit", "cur__scale")
|
|
332
335
|
}
|
|
333
336
|
return {c: dbt.get(c, 0) - crd.get(c, 0) for c in dbt.keys() | crd.keys()}
|
|
334
337
|
|
|
@@ -1008,10 +1011,30 @@ class Transaction(Model):
|
|
|
1008
1011
|
assert self.proof is None, "It is method for requests only"
|
|
1009
1012
|
return self.sender_id is None or self.sender_id == sender_id
|
|
1010
1013
|
|
|
1014
|
+
@property
|
|
1011
1015
|
def pack(self) -> bytes:
|
|
1012
|
-
|
|
1016
|
+
if self.status == TransactionStatus.request:
|
|
1017
|
+
"""Упаковка запроса в 4+4+4+8+2+4=22 байт"""
|
|
1018
|
+
fmt = ">LLBL"
|
|
1019
|
+
vals = self.id, self.receiver_id, self.cur_id, self.amount
|
|
1020
|
+
if self.sender_id:
|
|
1021
|
+
fmt += "L"
|
|
1022
|
+
vals += (self.sender_id,)
|
|
1023
|
+
if self.ts:
|
|
1024
|
+
fmt += "L"
|
|
1025
|
+
vals += (int((datetime.now() + timedelta(minutes=self.ts)).timestamp()),)
|
|
1026
|
+
return struct.pack(fmt, *vals)
|
|
1027
|
+
"""Упаковка перевода в 4+4+8+2+4+(64/128)=86/150 байт"""
|
|
1028
|
+
proof = self.proof or b""
|
|
1013
1029
|
return struct.pack(
|
|
1014
|
-
">
|
|
1030
|
+
f">LLLQHL{len(proof)}s",
|
|
1031
|
+
self.id,
|
|
1032
|
+
self.sender_id,
|
|
1033
|
+
self.receiver_id,
|
|
1034
|
+
self.amount,
|
|
1035
|
+
self.cur_id,
|
|
1036
|
+
int(self.ts.timestamp()),
|
|
1037
|
+
proof,
|
|
1015
1038
|
)
|
|
1016
1039
|
|
|
1017
1040
|
async def sender_sign(self):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xync_schema-0.0.34.dev1 → xync_schema-0.0.34.dev2}/xync_schema.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|