mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 23:55:01 +01:00
refactor(payment): replace wait_any_incoming_payment with event-based system (#1019)
Rename wait_any_incoming_payment to wait_payment_event and change return type from WaitPaymentResponse stream to Event stream. This introduces a new Event enum that wraps payment responses, making the system more extensible for future event types. - Add Event enum with PaymentReceived variant - Update MintPayment trait method signature - Refactor all payment backend implementations (LND, CLN, LNBits, fake wallet) - Update mint and payment processor to handle new event stream forma
This commit is contained in:
@@ -263,9 +263,9 @@ impl MintPayment for PaymentProcessorClient {
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn wait_any_incoming_payment(
|
||||
async fn wait_payment_event(
|
||||
&self,
|
||||
) -> Result<Pin<Box<dyn Stream<Item = WaitPaymentResponse> + Send>>, Self::Err> {
|
||||
) -> Result<Pin<Box<dyn Stream<Item = cdk_common::payment::Event> + Send>>, Self::Err> {
|
||||
self.wait_incoming_payment_stream_is_active
|
||||
.store(true, Ordering::SeqCst);
|
||||
tracing::debug!("Client waiting for payment");
|
||||
@@ -288,7 +288,9 @@ impl MintPayment for PaymentProcessorClient {
|
||||
.filter_map(|item| async {
|
||||
match item {
|
||||
Ok(value) => match value.try_into() {
|
||||
Ok(payment_response) => Some(payment_response),
|
||||
Ok(payment_response) => Some(cdk_common::payment::Event::PaymentReceived(
|
||||
payment_response,
|
||||
)),
|
||||
Err(e) => {
|
||||
tracing::error!("Error converting payment response: {}", e);
|
||||
None
|
||||
|
||||
@@ -401,19 +401,23 @@ impl CdkPaymentProcessor for PaymentProcessorServer {
|
||||
ln.cancel_wait_invoice();
|
||||
break;
|
||||
}
|
||||
result = ln.wait_any_incoming_payment() => {
|
||||
result = ln.wait_payment_event() => {
|
||||
match result {
|
||||
Ok(mut stream) => {
|
||||
while let Some(payment_response) = stream.next().await {
|
||||
match tx.send(Result::<_, Status>::Ok(payment_response.into()))
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
// Response was queued to be sent to client
|
||||
}
|
||||
Err(item) => {
|
||||
tracing::error!("Error adding incoming payment to stream: {}", item);
|
||||
break;
|
||||
while let Some(event) = stream.next().await {
|
||||
match event {
|
||||
cdk_common::payment::Event::PaymentReceived(payment_response) => {
|
||||
match tx.send(Result::<_, Status>::Ok(payment_response.into()))
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
// Response was queued to be sent to client
|
||||
}
|
||||
Err(item) => {
|
||||
tracing::error!("Error adding incoming payment to stream: {}", item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user