mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-19 13:18:26 +02:00
Create separate module for received payment result (#1100)
* Move received payment class to separate module * Rename received payments stream class
This commit is contained in:
parent
cb73a6bfd2
commit
9ba2d606bd
2 changed files with 36 additions and 11 deletions
32
squeaknode/core/received_payment_stream.py
Normal file
32
squeaknode/core/received_payment_stream.py
Normal file
|
|
@ -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]
|
||||
|
|
@ -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(),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue