diff --git a/lbrynet/schema/claim.py b/lbrynet/schema/claim.py index 91f211b9a..74c18fdb0 100644 --- a/lbrynet/schema/claim.py +++ b/lbrynet/schema/claim.py @@ -330,10 +330,6 @@ class Fee: def currency(self) -> str: return FeeMessage.Currency.Name(self._fee.currency) - @currency.setter - def currency(self, currency: str): - self._fee.currency = FeeMessage.Currency.Value(currency) - @property def address(self) -> str: return b58encode(self._fee.address).decode() @@ -357,6 +353,18 @@ class Fee: if self.currency == 'USD': return self.usd + DEWIES = Decimal(COIN) + + @property + def lbc(self) -> Decimal: + if self._fee.currency != FeeMessage.LBC: + raise ValueError('LBC can only be returned for LBC fees.') + return Decimal(self._fee.amount / self.DEWIES) + + @lbc.setter + def lbc(self, amount: Decimal): + self.dewies = int(amount * self.DEWIES) + @property def dewies(self) -> int: if self._fee.currency != FeeMessage.LBC: @@ -368,29 +376,27 @@ class Fee: self._fee.amount = amount self._fee.currency = FeeMessage.LBC - DEWEYS = Decimal(COIN) - - @property - def lbc(self) -> Decimal: - if self._fee.currency != FeeMessage.LBC: - raise ValueError('LBC can only be returned for LBC fees.') - return Decimal(self._fee.amount / self.DEWEYS) - - @lbc.setter - def lbc(self, amount: Decimal): - self.dewies = int(amount * self.DEWEYS) - - USD = Decimal(100.0) + PENNIES = Decimal(100.0) @property def usd(self) -> Decimal: if self._fee.currency != FeeMessage.USD: raise ValueError('USD can only be returned for USD fees.') - return Decimal(self._fee.amount / self.USD) + return Decimal(self._fee.amount / self.PENNIES) @usd.setter def usd(self, amount: Decimal): - self._fee.amount = int(amount * self.USD) + self.pennies = int(amount * self.PENNIES) + + @property + def pennies(self) -> int: + if self._fee.currency != FeeMessage.USD: + raise ValueError('Pennies can only be returned for USD fees.') + return self._fee.amount + + @pennies.setter + def pennies(self, amount: int): + self._fee.amount = amount self._fee.currency = FeeMessage.USD diff --git a/tests/unit/schema/test_models.py b/tests/unit/schema/test_models.py index 9d6d96c72..e8fc3c137 100644 --- a/tests/unit/schema/test_models.py +++ b/tests/unit/schema/test_models.py @@ -40,11 +40,22 @@ class TestFee(TestCase): self.assertEqual(stream.fee.lbc, Decimal('1.01')) self.assertEqual(stream.fee.dewies, 101000000) self.assertEqual(stream.fee.currency, 'LBC') + stream.fee.dewies = 203000000 + self.assertEqual(stream.fee.lbc, Decimal('2.03')) + self.assertEqual(stream.fee.dewies, 203000000) + self.assertEqual(stream.fee.currency, 'LBC') with self.assertRaisesRegex(ValueError, 'USD can only be returned for USD fees.'): print(stream.fee.usd) + with self.assertRaisesRegex(ValueError, 'Pennies can only be returned for USD fees.'): + print(stream.fee.pennies) stream.fee.usd = Decimal('1.01') self.assertEqual(stream.fee.usd, Decimal('1.01')) + self.assertEqual(stream.fee.pennies, 101) + self.assertEqual(stream.fee.currency, 'USD') + stream.fee.pennies = 203 + self.assertEqual(stream.fee.usd, Decimal('2.03')) + self.assertEqual(stream.fee.pennies, 203) self.assertEqual(stream.fee.currency, 'USD') with self.assertRaisesRegex(ValueError, 'LBC can only be returned for LBC fees.'): print(stream.fee.lbc)