minor cleanup

This commit is contained in:
Lex Berezhny 2020-02-21 10:05:46 -05:00
parent d2560d260c
commit b1318a9958
4 changed files with 36 additions and 41 deletions

View file

@ -57,6 +57,9 @@ Code | Name | Message
420 | KeyFeeAboveMaxAllowed | {message} 420 | KeyFeeAboveMaxAllowed | {message}
421 | InvalidPassword | Password is invalid. 421 | InvalidPassword | Password is invalid.
422 | IncompatibleWalletServer | '{server}:{port}' has an incompatibly old version. 422 | IncompatibleWalletServer | '{server}:{port}' has an incompatibly old version.
431 | ServerPaymentInvalidAddress | Invalid address from wallet server: '{address}' - skipping payment round.
432 | ServerPaymentWalletLocked | Cannot spend funds with locked wallet, skipping payment round.
433 | ServerPaymentFeeAboveMaxAllowed | Server asked {daily_fee} LBC as daily fee, but maximum allowed is {max_fee} LBC. Skipping payment round.
**5xx** | Blob | **Blobs** **5xx** | Blob | **Blobs**
500 | BlobNotFound | Blob not found. 500 | BlobNotFound | Blob not found.
501 | BlobPermissionDenied | Permission denied to read blob. 501 | BlobPermissionDenied | Permission denied to read blob.
@ -78,7 +81,3 @@ Code | Name | Message
701 | InvalidExchangeRateResponse | Failed to get exchange rate from {source}: {reason} 701 | InvalidExchangeRateResponse | Failed to get exchange rate from {source}: {reason}
702 | CurrencyConversion | {message} 702 | CurrencyConversion | {message}
703 | InvalidCurrency | Invalid currency: {currency} is not a supported currency. 703 | InvalidCurrency | Invalid currency: {currency} is not a supported currency.
**8xx** | WalletServerPayment | **Wallet Server Payment**
801 | InvalidAddressForServerPayment | Invalid address from wallet server: '{address}' - skipping payment round.
802 | WalletLockedDuringServerPayment | Cannot spend funds with locked wallet, skipping payment round.
803 | ServerFeeHigherThanAllowedServerPayment | Server asked {daily_fee} LBC as daily fee, but maximum allowed is {max_fee} LBC. Skipping payment round.

View file

@ -242,6 +242,27 @@ class IncompatibleWalletServerError(WalletError):
super().__init__(f"'{server}:{port}' has an incompatibly old version.") super().__init__(f"'{server}:{port}' has an incompatibly old version.")
class ServerPaymentInvalidAddressError(WalletError):
def __init__(self, address):
self.address = address
super().__init__(f"Invalid address from wallet server: '{address}' - skipping payment round.")
class ServerPaymentWalletLockedError(WalletError):
def __init__(self):
super().__init__("Cannot spend funds with locked wallet, skipping payment round.")
class ServerPaymentFeeAboveMaxAllowedError(WalletError):
def __init__(self, daily_fee, max_fee):
self.daily_fee = daily_fee
self.max_fee = max_fee
super().__init__(f"Server asked {daily_fee} LBC as daily fee, but maximum allowed is {max_fee} LBC. Skipping payment round.")
class BlobError(BaseError): class BlobError(BaseError):
""" """
**Blobs** **Blobs**
@ -377,31 +398,3 @@ class InvalidCurrencyError(CurrencyExchangeError):
def __init__(self, currency): def __init__(self, currency):
self.currency = currency self.currency = currency
super().__init__(f"Invalid currency: {currency} is not a supported currency.") super().__init__(f"Invalid currency: {currency} is not a supported currency.")
class WalletServerPaymentError(BaseError):
"""
**Wallet Server Payment**
"""
class InvalidAddressForServerPaymentError(WalletServerPaymentError):
def __init__(self, address):
self.address = address
super().__init__(f"Invalid address from wallet server: '{address}' - skipping payment round.")
class WalletLockedDuringServerPaymentError(WalletServerPaymentError):
def __init__(self):
super().__init__("Cannot spend funds with locked wallet, skipping payment round.")
class ServerFeeHigherThanAllowedServerPaymentError(WalletServerPaymentError):
def __init__(self, daily_fee, max_fee):
self.daily_fee = daily_fee
self.max_fee = max_fee
super().__init__(f"Server asked {daily_fee} LBC as daily fee,"
f" but maximum allowed is {max_fee} LBC. Skipping payment round.")

View file

@ -1,8 +1,11 @@
import asyncio import asyncio
import logging import logging
from lbry.error import InvalidAddressForServerPaymentError, WalletLockedDuringServerPaymentError, \ from lbry.error import (
ServerFeeHigherThanAllowedServerPaymentError ServerPaymentFeeAboveMaxAllowedError,
ServerPaymentInvalidAddressError,
ServerPaymentWalletLockedError
)
from lbry.wallet.dewies import lbc_to_dewies from lbry.wallet.dewies import lbc_to_dewies
from lbry.wallet.stream import StreamController from lbry.wallet.stream import StreamController
from lbry.wallet.transaction import Output, Transaction from lbry.wallet.transaction import Output, Transaction
@ -33,17 +36,18 @@ class WalletServerPayer:
continue continue
if not self.ledger.is_valid_address(address): if not self.ledger.is_valid_address(address):
self._on_payment_controller.add_error(InvalidAddressForServerPaymentError(address)) self._on_payment_controller.add_error(ServerPaymentInvalidAddressError(address))
continue continue
if self.wallet.is_locked: if self.wallet.is_locked:
self._on_payment_controller.add_error(WalletLockedDuringServerPaymentError()) self._on_payment_controller.add_error(ServerPaymentWalletLockedError())
continue continue
amount = lbc_to_dewies(features['daily_fee']) # check that this is in lbc and not dewies amount = lbc_to_dewies(features['daily_fee']) # check that this is in lbc and not dewies
limit = lbc_to_dewies(self.max_fee) limit = lbc_to_dewies(self.max_fee)
if amount > limit: if amount > limit:
self._on_payment_controller.add_error( self._on_payment_controller.add_error(
ServerFeeHigherThanAllowedServerPaymentError(features['daily_fee'], self.max_fee) ServerPaymentFeeAboveMaxAllowedError(features['daily_fee'], self.max_fee)
) )
continue continue

View file

@ -2,7 +2,7 @@ import asyncio
import lbry import lbry
import lbry.wallet import lbry.wallet
from lbry.error import ServerFeeHigherThanAllowedServerPaymentError from lbry.error import ServerPaymentFeeAboveMaxAllowedError
from lbry.wallet.network import ClientSession from lbry.wallet.network import ClientSession
from lbry.testcase import IntegrationTestCase, CommandTestCase from lbry.testcase import IntegrationTestCase, CommandTestCase
from lbry.wallet.orchstr8.node import SPVNode from lbry.wallet.orchstr8.node import SPVNode
@ -67,14 +67,13 @@ class TestUsagePayment(CommandTestCase):
node = SPVNode(self.conductor.spv_module, node_number=2) node = SPVNode(self.conductor.spv_module, node_number=2)
await node.start(self.blockchain, extraconf={"PAYMENT_ADDRESS": address, "DAILY_FEE": "1.1"}) await node.start(self.blockchain, extraconf={"PAYMENT_ADDRESS": address, "DAILY_FEE": "1.1"})
self.daemon.jsonrpc_settings_set('lbryum_servers', [f"{node.hostname}:{node.port}"]) self.daemon.jsonrpc_settings_set('lbryum_servers', [f"{node.hostname}:{node.port}"])
on_error = wallet_pay_service.on_payment.where(lambda e: isinstance(e, ServerFeeHigherThanAllowedServerPaymentError))
await self.daemon.jsonrpc_wallet_reconnect() await self.daemon.jsonrpc_wallet_reconnect()
features = await self.ledger.network.get_server_features() features = await self.ledger.network.get_server_features()
self.assertEqual(features["payment_address"], address) self.assertEqual(features["payment_address"], address)
self.assertEqual(features["daily_fee"], "1.1") self.assertEqual(features["daily_fee"], "1.1")
with self.assertRaises(ServerFeeHigherThanAllowedServerPaymentError): with self.assertRaises(ServerPaymentFeeAboveMaxAllowedError):
await asyncio.wait_for(on_error, timeout=3) await asyncio.wait_for(wallet_pay_service.on_payment.first, timeout=3)
await node.stop(False) await node.stop(False)
await node.start(self.blockchain, extraconf={"PAYMENT_ADDRESS": address, "DAILY_FEE": "1.0"}) await node.start(self.blockchain, extraconf={"PAYMENT_ADDRESS": address, "DAILY_FEE": "1.0"})
self.addCleanup(node.stop) self.addCleanup(node.stop)