simplify validation, move to fee.update

This commit is contained in:
Victor Shyba 2019-06-18 05:21:58 -03:00 committed by Lex Berezhny
parent 5876d5c295
commit 1e2b040f75
3 changed files with 10 additions and 14 deletions

View file

@ -2609,16 +2609,8 @@ class Daemon(metaclass=JSONRPCServerType):
elif old_txo.claim.is_signed and not clear_channel and not replace:
channel = old_txo.channel
fee_address = self.get_fee_address(kwargs, old_txo.claim.stream.fee.address or claim_address)
if fee_address:
kwargs['fee_address'] = fee_address
kwargs['fee_currency'] = kwargs.get('fee_currency', old_txo.claim.stream.fee.currency if not replace else None)
kwargs['fee_amount'] = kwargs.get('fee_amount', old_txo.claim.stream.fee.amount if not replace else None)
valid_currency = kwargs['fee_currency'] if kwargs['fee_currency'] != 'UNKNOWN_CURRENCY' else None
if kwargs.get('fee_amount') and not valid_currency:
raise Exception('In order to set a fee amount, please specify a fee currency')
if valid_currency and not kwargs.get('fee_amount'):
raise Exception('In order to set a fee currency, please specify a fee amount')
if {'fee_currency', 'fee_amount', 'fee_address'}.intersection(kwargs):
kwargs['fee_address'] = self.get_fee_address(kwargs, old_txo.claim.stream.fee.address or claim_address)
if replace:
claim = Claim()

View file

@ -204,12 +204,18 @@ class Fee(Metadata):
__slots__ = ()
def update(self, address: str = None, currency: str = None, amount=None):
amount = amount or self.amount
currency = currency or (self.currency if self.message.currency else None)
if address is not None:
self.address = address
if (self.message.currency or currency is not None) and amount is not None:
if currency and amount:
currency = currency.lower() if currency is not None else self.currency.lower()
assert currency in ('lbc', 'btc', 'usd'), f'Unknown currency type: {currency}'
setattr(self, currency, Decimal(amount))
setattr(self, currency, Decimal(amount or self.amount))
elif amount and not currency:
raise Exception('In order to set a fee amount, please specify a fee currency')
elif currency and not amount:
raise Exception('In order to set a fee currency, please specify a fee amount')
@property
def currency(self) -> str:

View file

@ -206,8 +206,6 @@ class Stream(BaseClaim):
def update(self, file_path=None, height=None, width=None, duration=None, **kwargs):
if kwargs.pop('clear_fee', False):
# clear_fee is set, ignore defaults
kwargs.pop('fee_address', None), kwargs.pop('fee_currency', None), kwargs.pop('fee_amount', None)
self.message.ClearField('fee')
else:
self.fee.update(