Skip to content

Commit

Permalink
Fix wrong Decimal type
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 21, 2019
1 parent ae0c224 commit 663f81c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/escrow/escrow_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class EscrowOffer:
sum_fee_up: typing.Optional[Decimal128] = None
#: Amount of held currency with agreed fee substracted.
sum_fee_down: typing.Optional[Decimal128] = None
#: Amount of insured currency.
insured: typing.Optional[Decimal128] = None
#: Unix time stamp of counteragent first reaction to sent offer.
react_time: typing.Optional[float] = None
#: Unix time stamp since which transaction should be checked.
Expand Down
6 changes: 4 additions & 2 deletions src/handlers/escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def wrapper(message: types.Message, state: FSMContext):

async def get_insurance(offer: EscrowOffer) -> Decimal:
"""Get insurance of escrow asset in ``offer`` taking limits into account."""
offer_sum = offer[f"sum_{offer.type}"]
offer_sum = offer[f"sum_{offer.type}"].to_decimal()
asset = offer[offer.type]
limits = await get_escrow_instance(asset).get_limits(asset)
if not limits:
Expand All @@ -138,7 +138,9 @@ async def get_insurance(offer: EscrowOffer) -> Decimal:
[{"$group": {"_id": 0, "insured_total": {"$sum": "$insured"}}}]
)
if await cursor.fetch_next:
insured_total = cursor.next_object()["insured_total"].to_decimal()
insured_total = cursor.next_object()["insured_total"]
if insured_total != 0:
insured_total = insured_total.to_decimal()
total_difference = limits.total - insured_total - insured
if total_difference < 0:
insured += total_difference
Expand Down

0 comments on commit 663f81c

Please sign in to comment.