1#![forbid(unsafe_code)]
8#![warn(missing_docs)]
9#![warn(rustdoc::bare_urls)]
10#![allow(unknown_lints)]
11#![allow(clippy::arc_with_non_send_sync)]
12
13use std::fmt;
14use std::sync::Arc;
15
16pub extern crate nostr;
17
18use async_trait::async_trait;
19use nostr::prelude::*;
20
21pub mod error;
22pub mod prelude;
23#[cfg(feature = "webln")]
24mod webln;
25
26pub use self::error::ZapperError;
27#[cfg(feature = "webln")]
28pub use self::webln::WebLNZapper;
29
30#[derive(Debug, Clone, PartialEq, Eq)]
32pub enum ZapperBackend {
33 WebLN,
35 NWC,
37 Custom(String),
39}
40
41pub type DynNostrZapper = dyn NostrZapper;
43
44pub trait IntoNostrZapper {
46 #[doc(hidden)]
47 fn into_nostr_zapper(self) -> Arc<DynNostrZapper>;
48}
49
50impl IntoNostrZapper for Arc<DynNostrZapper> {
51 fn into_nostr_zapper(self) -> Arc<DynNostrZapper> {
52 self
53 }
54}
55
56impl<T> IntoNostrZapper for T
57where
58 T: NostrZapper + Sized + 'static,
59{
60 fn into_nostr_zapper(self) -> Arc<DynNostrZapper> {
61 Arc::new(self)
62 }
63}
64
65impl<T> IntoNostrZapper for Arc<T>
66where
67 T: NostrZapper + 'static,
68{
69 fn into_nostr_zapper(self) -> Arc<DynNostrZapper> {
70 self
71 }
72}
73
74#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
76#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
77pub trait NostrZapper: fmt::Debug + Send + Sync {
78 fn backend(&self) -> ZapperBackend;
80
81 async fn pay(&self, invoice: String) -> Result<(), ZapperError>;
83}