mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-16 13:01:04 +02:00
Remove received payments verifier (#591)
* Got received payments working without verifier class * Process received payments works with better exception handling * Delete sent offers verifier
This commit is contained in:
parent
f63c511149
commit
080ee1eac8
3 changed files with 38 additions and 71 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
import time
|
||||
from typing import List
|
||||
|
||||
from squeak.core import CheckSqueak
|
||||
|
|
@ -8,13 +9,13 @@ from squeak.core.signing import CSqueakAddress
|
|||
|
||||
from proto import squeak_server_pb2
|
||||
from squeaknode.core.offer import Offer
|
||||
from squeaknode.core.sent_offer import SentOffer
|
||||
from squeaknode.core.squeak_address_validator import SqueakAddressValidator
|
||||
from squeaknode.core.squeak_peer import SqueakPeer
|
||||
from squeaknode.core.squeak_profile import SqueakProfile
|
||||
from squeaknode.node.received_payments_subscription_client import (
|
||||
OpenReceivedPaymentsSubscriptionClient,
|
||||
)
|
||||
from squeaknode.node.sent_offers_verifier import SentOffersVerifier
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -32,10 +33,6 @@ class SqueakController:
|
|||
self.squeak_core = squeak_core
|
||||
self.squeak_store = squeak_store
|
||||
self.squeak_whitelist = squeak_whitelist
|
||||
self.sent_offers_verifier = SentOffersVerifier(
|
||||
self.squeak_db,
|
||||
self.squeak_core,
|
||||
)
|
||||
self.config = config
|
||||
|
||||
def save_uploaded_squeak(self, squeak: CSqueak):
|
||||
|
|
@ -250,8 +247,25 @@ class SqueakController:
|
|||
num_expired_sent_offers)
|
||||
)
|
||||
|
||||
def process_subscribed_invoices(self):
|
||||
self.sent_offers_verifier.process_subscribed_invoices()
|
||||
def process_subscribed_invoices(self, retry_s: int = 10):
|
||||
def get_sent_offer_for_payment_hash(payment_hash: bytes) -> SentOffer:
|
||||
return self.squeak_db.get_sent_offer_by_payment_hash(
|
||||
payment_hash
|
||||
)
|
||||
while True:
|
||||
try:
|
||||
latest_settle_index = self.squeak_db.get_latest_settle_index() or 0
|
||||
for received_payment in self.squeak_core.get_received_payments(
|
||||
get_sent_offer_for_payment_hash,
|
||||
latest_settle_index,
|
||||
):
|
||||
self.squeak_db.insert_received_payment(received_payment)
|
||||
except Exception:
|
||||
logger.info(
|
||||
"Unable to subscribe invoices from lnd. Retrying in "
|
||||
"{} seconds.".format(retry_s),
|
||||
)
|
||||
time.sleep(retry_s)
|
||||
|
||||
def subscribe_received_payments(self, initial_index: int):
|
||||
with OpenReceivedPaymentsSubscriptionClient(
|
||||
|
|
|
|||
|
|
@ -160,34 +160,24 @@ class SqueakCore:
|
|||
node_pubkey=offer.destination,
|
||||
)
|
||||
|
||||
def get_received_payments(self, get_sent_offer_fn, latest_settle_index, retry_s) -> Iterator[ReceivedPayment]:
|
||||
try:
|
||||
for invoice in self.lightning_client.subscribe_invoices(
|
||||
def get_received_payments(self, get_sent_offer_fn, latest_settle_index) -> Iterator[ReceivedPayment]:
|
||||
for invoice in self.lightning_client.subscribe_invoices(
|
||||
settle_index=latest_settle_index,
|
||||
):
|
||||
if invoice.settled:
|
||||
payment_hash = invoice.r_hash
|
||||
settle_index = invoice.settle_index
|
||||
# sent_offer = self.squeak_db.get_sent_offer_by_payment_hash(
|
||||
# payment_hash)
|
||||
sent_offer = get_sent_offer_fn(payment_hash)
|
||||
received_payment = ReceivedPayment(
|
||||
received_payment_id=None,
|
||||
created=None,
|
||||
squeak_hash=sent_offer.squeak_hash,
|
||||
payment_hash=sent_offer.payment_hash,
|
||||
price_msat=sent_offer.price_msat,
|
||||
settle_index=settle_index,
|
||||
client_addr=sent_offer.client_addr,
|
||||
)
|
||||
# self.squeak_db.insert_received_payment(received_payment)
|
||||
yield received_payment
|
||||
except Exception:
|
||||
logger.info(
|
||||
"Unable to subscribe invoices from lnd. Retrying in "
|
||||
"{} seconds.".format(retry_s),
|
||||
)
|
||||
time.sleep(retry_s)
|
||||
):
|
||||
if invoice.settled:
|
||||
payment_hash = invoice.r_hash
|
||||
settle_index = invoice.settle_index
|
||||
sent_offer = get_sent_offer_fn(payment_hash)
|
||||
received_payment = ReceivedPayment(
|
||||
received_payment_id=None,
|
||||
created=None,
|
||||
squeak_hash=sent_offer.squeak_hash,
|
||||
payment_hash=sent_offer.payment_hash,
|
||||
price_msat=sent_offer.price_msat,
|
||||
settle_index=settle_index,
|
||||
client_addr=sent_offer.client_addr,
|
||||
)
|
||||
yield received_payment
|
||||
|
||||
def get_offer(self, squeak: CSqueak, offer_msg: squeak_server_pb2.SqueakBuyOffer, peer: SqueakPeer) -> Offer:
|
||||
if peer.peer_id is None:
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
import logging
|
||||
|
||||
from squeaknode.core.sent_offer import SentOffer
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
LND_CONNECT_RETRY_S = 10
|
||||
|
||||
|
||||
class SentOffersVerifier:
|
||||
def __init__(self, squeak_db, squeak_core):
|
||||
self.squeak_db = squeak_db
|
||||
self.squeak_core = squeak_core
|
||||
|
||||
def process_subscribed_invoices(self):
|
||||
while True:
|
||||
self.try_processing()
|
||||
|
||||
def try_processing(self):
|
||||
latest_settle_index = self._get_latest_settle_index() or 0
|
||||
|
||||
def get_sent_offer_for_payment_hash(payment_hash: bytes) -> SentOffer:
|
||||
return self.squeak_db.get_sent_offer_by_payment_hash(
|
||||
payment_hash
|
||||
)
|
||||
|
||||
for received_payment in self.squeak_core.get_received_payments(
|
||||
get_sent_offer_for_payment_hash,
|
||||
latest_settle_index,
|
||||
LND_CONNECT_RETRY_S,
|
||||
):
|
||||
self.squeak_db.insert_received_payment(received_payment)
|
||||
|
||||
def _get_latest_settle_index(self):
|
||||
logger.info("Getting latest settle index from db...")
|
||||
return self.squeak_db.get_latest_settle_index()
|
||||
Loading…
Add table
Add a link
Reference in a new issue