nwc 0.45.0-alpha.1

Nostr Wallet Connect client
Documentation
use std::future::IntoFuture;
use std::time::Duration;

use nostr::prelude::*;

use crate::NostrWalletConnect;
use crate::error::Error;

/// List transactions
#[must_use = "Does nothing unless you await!"]
pub struct ListTransactions<'client> {
    client: &'client NostrWalletConnect,
    request: ListTransactionsRequest,
    timeout: Option<Duration>,
}

impl<'client> ListTransactions<'client> {
    pub(crate) fn new(
        client: &'client NostrWalletConnect,
        request: ListTransactionsRequest,
    ) -> Self {
        Self {
            client,
            request,
            timeout: None,
        }
    }

    /// Set timeout
    #[inline]
    pub fn timeout(mut self, timeout: Duration) -> Self {
        self.timeout = Some(timeout);
        self
    }
}

impl<'client> IntoFuture for ListTransactions<'client> {
    type Output = Result<Vec<LookupInvoiceResponse>, Error>;
    type IntoFuture = BoxedFuture<'client, Self::Output>;

    fn into_future(self) -> Self::IntoFuture {
        Box::pin(async move {
            let timeout: Duration = self.timeout.unwrap_or(self.client.timeout);
            let req = Request::list_transactions(self.request);
            let res: Response = self.client.send_request(req, timeout).await?;
            Ok(res.to_list_transactions()?)
        })
    }
}