From 9ba2d606bd3de632081cd9422d563a9cd96be3e2 Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Sat, 28 Aug 2021 21:57:27 -0700 Subject: [PATCH] Create separate module for received payment result (#1100) * Move received payment class to separate module * Rename received payments stream class --- squeaknode/core/received_payment_stream.py | 32 ++++++++++++++++++++++ squeaknode/core/squeak_core.py | 15 +++------- 2 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 squeaknode/core/received_payment_stream.py diff --git a/squeaknode/core/received_payment_stream.py b/squeaknode/core/received_payment_stream.py new file mode 100644 index 00000000..4552e679 --- /dev/null +++ b/squeaknode/core/received_payment_stream.py @@ -0,0 +1,32 @@ +# MIT License +# +# Copyright (c) 2020 Jonathan Zernik +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +from typing import Callable +from typing import Iterator +from typing import NamedTuple + +from squeaknode.core.received_payment import ReceivedPayment + + +class ReceivedPaymentsStream(NamedTuple): + """Represents the result of a received payment subscription.""" + cancel_fn: Callable[[], None] + result_stream: Iterator[ReceivedPayment] diff --git a/squeaknode/core/squeak_core.py b/squeaknode/core/squeak_core.py index b9fdff9a..63760115 100644 --- a/squeaknode/core/squeak_core.py +++ b/squeaknode/core/squeak_core.py @@ -22,8 +22,6 @@ import logging import time from typing import Callable -from typing import Iterator -from typing import NamedTuple from typing import Optional import grpc @@ -42,6 +40,7 @@ from squeaknode.core.offer import Offer from squeaknode.core.peer_address import PeerAddress from squeaknode.core.received_offer import ReceivedOffer from squeaknode.core.received_payment import ReceivedPayment +from squeaknode.core.received_payment_stream import ReceivedPaymentsStream from squeaknode.core.sent_offer import SentOffer from squeaknode.core.sent_payment import SentPayment from squeaknode.core.squeak_profile import SqueakProfile @@ -55,12 +54,6 @@ from squeaknode.lightning.lnd_lightning_client import LNDLightningClient logger = logging.getLogger(__name__) -class ReceivedPaymentsResult(NamedTuple): - """Represents the result of a received payment subscription.""" - cancel_fn: Callable[[], None] - result_stream: Iterator[ReceivedPayment] - - class SqueakCore: def __init__( self, @@ -311,7 +304,7 @@ class SqueakCore: self, latest_settle_index: int, get_sent_offer_fn: Callable[[bytes], SentOffer], - ) -> ReceivedPaymentsResult: + ) -> ReceivedPaymentsStream: """Get an iterator of received payments. Args: @@ -320,7 +313,7 @@ class SqueakCore: the corresponding SentOffer. Returns: - ReceivedPaymentsResult: An object containing an iterator of received + ReceivedPaymentsStream: An object containing an iterator of received payments and a callback function to cancel the iteration. """ # Get the stream of settled invoices. @@ -352,7 +345,7 @@ class SqueakCore: if e.code() != grpc.StatusCode.CANCELLED: raise InvoiceSubscriptionError() - return ReceivedPaymentsResult( + return ReceivedPaymentsStream( cancel_fn=cancel_subscription, result_stream=get_payment_stream(), )