Skip to content

Commit

Permalink
FAV receives Decimal and returns int in plain_value
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Jan 26, 2024
1 parent 340ad8e commit 517ff07
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions common/lib9c/models/fungible_asset_value.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from decimal import Decimal
from typing import Dict, List, Optional, Any

import bencodex
Expand All @@ -8,7 +9,7 @@


class FungibleAssetValue:
def __init__(self, currency: Currency, amount: float):
def __init__(self, currency: Currency, amount: Decimal):
self.currency = currency
self.amount = amount

Expand All @@ -19,16 +20,16 @@ def __eq__(self, other: FungibleAssetValue):
def from_raw_data(
cls,
ticker: str, decimal_places: int, minters: Optional[List[str]] = None, total_supply_trackable: bool = False,
amount: float = 0
amount: Decimal = Decimal("0")
):
return cls(
Currency(ticker, decimal_places, minters, total_supply_trackable),
amount=amount
)

@property
def plain_value(self) -> List[Dict[str, Any] | float]:
return [self.currency.plain_value, self.amount * max(1, 10 ** self.currency.decimal_places)]
def plain_value(self) -> List[Dict[str, Any] | int]:
return [self.currency.plain_value, int(self.amount * max(1, 10 ** self.currency.decimal_places))]

@property
def serialized_plain_value(self) -> bytes:
Expand Down

0 comments on commit 517ff07

Please sign in to comment.