pub struct Client { /* private fields */ }
Expand description
Nostr client
Implementations§
Source§impl Client
impl Client
Sourcepub fn new<T>(signer: T) -> Selfwhere
T: IntoNostrSigner,
pub fn new<T>(signer: T) -> Selfwhere
T: IntoNostrSigner,
Construct client with signer
To construct a client without signer use Client::default
.
§Example
use nostr_sdk::prelude::*;
let keys = Keys::generate();
let client = Client::new(keys);
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Construct client
§Example
use std::time::Duration;
use nostr_sdk::prelude::*;
let signer = Keys::generate();
let opts = ClientOptions::default().gossip(true);
let client: Client = Client::builder().signer(signer).opts(opts).build();
Sourcepub fn update_min_pow_difficulty(&self, _difficulty: u8)
👎Deprecated since 0.40.0: This no longer works, please use AdmitPolicy
instead.
pub fn update_min_pow_difficulty(&self, _difficulty: u8)
AdmitPolicy
instead.Update minimum POW difficulty for received events
Events with a POW lower than the current value will be ignored to prevent resources exhaustion.
Sourcepub fn automatic_authentication(&self, enable: bool)
pub fn automatic_authentication(&self, enable: bool)
Auto authenticate to relays (default: true)
Sourcepub async fn has_signer(&self) -> bool
pub async fn has_signer(&self) -> bool
Check if signer is configured
Sourcepub async fn signer(&self) -> Result<Arc<dyn NostrSigner>, Error>
pub async fn signer(&self) -> Result<Arc<dyn NostrSigner>, Error>
Sourcepub async fn set_signer<T>(&self, signer: T)where
T: IntoNostrSigner,
pub async fn set_signer<T>(&self, signer: T)where
T: IntoNostrSigner,
Set nostr signer
Sourcepub async fn unset_signer(&self)
pub async fn unset_signer(&self)
Unset nostr signer
Sourcepub fn database(&self) -> &Arc<dyn NostrDatabase>
pub fn database(&self) -> &Arc<dyn NostrDatabase>
Get database
Sourcepub async fn reset(&self)
pub async fn reset(&self)
Reset the client
This method resets the client to simplify the switch to another account.
This method will:
- unsubscribe from all subscriptions
- disconnect and force remove all relays
- unset the signer
This method will NOT:
- reset
ClientOptions
- remove the database
- clear the gossip graph
Sourcepub fn notifications(&self) -> Receiver<RelayPoolNotification>
pub fn notifications(&self) -> Receiver<RelayPoolNotification>
Get new notification listener
Sourcepub async fn relays(&self) -> HashMap<RelayUrl, Relay>
pub async fn relays(&self) -> HashMap<RelayUrl, Relay>
Get relays with RelayServiceFlags::READ
or RelayServiceFlags::WRITE
flags
Call RelayPool::all_relays
to get all relays
or RelayPool::relays_with_flag
to get relays with specific RelayServiceFlags
.
Sourcepub async fn add_relay<U>(&self, url: U) -> Result<bool, Error>
pub async fn add_relay<U>(&self, url: U) -> Result<bool, Error>
Add relay
Relays added with this method will have both RelayServiceFlags::READ
and RelayServiceFlags::WRITE
flags enabled.
If the relay already exists, the flags will be updated and false
returned.
If are set pool subscriptions, the new added relay will inherit them. Use Client::subscribe_to
method instead of Client::subscribe
,
to avoid to set pool subscriptions.
This method use previously set or default ClientOptions
to configure the Relay
(ex. set proxy, set min POW, set relay limits, …).
To use custom RelayOptions
use RelayPool::add_relay
.
Connection is NOT automatically started with relay, remember to call Client::connect
!
Sourcepub async fn add_discovery_relay<U>(&self, url: U) -> Result<bool, Error>
pub async fn add_discovery_relay<U>(&self, url: U) -> Result<bool, Error>
Add discovery relay
If relay already exists, this method automatically add the RelayServiceFlags::DISCOVERY
flag to it and return false
.
Sourcepub async fn add_read_relay<U>(&self, url: U) -> Result<bool, Error>
pub async fn add_read_relay<U>(&self, url: U) -> Result<bool, Error>
Add read relay
If relay already exists, this method add the RelayServiceFlags::READ
flag to it and return false
.
If are set pool subscriptions, the new added relay will inherit them. Use subscribe_to
method instead of subscribe
,
to avoid to set pool subscriptions.
Sourcepub async fn add_write_relay<U>(&self, url: U) -> Result<bool, Error>
pub async fn add_write_relay<U>(&self, url: U) -> Result<bool, Error>
Add write relay
If relay already exists, this method add the RelayServiceFlags::WRITE
flag to it and return false
.
Sourcepub async fn remove_relay<U>(&self, url: U) -> Result<(), Error>
pub async fn remove_relay<U>(&self, url: U) -> Result<(), Error>
Remove and disconnect relay
If the relay has RelayServiceFlags::GOSSIP
, it will not be removed from the pool and its
flags will be updated (remove RelayServiceFlags::READ
,
RelayServiceFlags::WRITE
and RelayServiceFlags::DISCOVERY
flags).
To force remove the relay, use Client::force_remove_relay
.
Sourcepub async fn force_remove_relay<U>(&self, url: U) -> Result<(), Error>
pub async fn force_remove_relay<U>(&self, url: U) -> Result<(), Error>
Force remove and disconnect relay
Note: this method will remove the relay, also if it’s in use for the gossip model or other service!
Sourcepub async fn remove_all_relays(&self)
pub async fn remove_all_relays(&self)
Disconnect and remove all relays
Some relays used by some services could not be disconnected with this method
(like the ones used for gossip).
Use Client::force_remove_all_relays
to remove every relay.
Sourcepub async fn force_remove_all_relays(&self)
pub async fn force_remove_all_relays(&self)
Disconnect and force remove all relays
Sourcepub async fn connect_relay<U>(&self, url: U) -> Result<(), Error>
pub async fn connect_relay<U>(&self, url: U) -> Result<(), Error>
Connect to a previously added relay
Check RelayPool::connect_relay
docs to learn more.
Sourcepub async fn try_connect_relay<U>(
&self,
url: U,
timeout: Duration,
) -> Result<(), Error>
pub async fn try_connect_relay<U>( &self, url: U, timeout: Duration, ) -> Result<(), Error>
Try to connect to a previously added relay
For further details, see the documentation of RelayPool::try_connect_relay
.
Sourcepub async fn disconnect_relay<U>(&self, url: U) -> Result<(), Error>
pub async fn disconnect_relay<U>(&self, url: U) -> Result<(), Error>
Disconnect relay
Sourcepub async fn connect(&self)
pub async fn connect(&self)
Connect to all added relays
Attempts to initiate a connection for every relay currently in
RelayStatus::Initialized
or RelayStatus::Terminated
.
A background connection task is spawned for each such relay, which then tries
to establish the connection.
Any relay not in one of these two statuses is skipped.
For further details, see the documentation of Relay::connect
.
Sourcepub async fn wait_for_connection(&self, timeout: Duration)
pub async fn wait_for_connection(&self, timeout: Duration)
Waits for relays connections
Wait for relays connections at most for the specified timeout
.
The code continues when the relays are connected or the timeout
is reached.
Sourcepub async fn try_connect(&self, timeout: Duration) -> Output<()>
pub async fn try_connect(&self, timeout: Duration) -> Output<()>
Try to establish a connection with the relays.
Attempts to establish a connection for every relay currently in
RelayStatus::Initialized
or RelayStatus::Terminated
without spawning the connection task if it fails.
This means that if the connection fails, no automatic retries are scheduled.
Use Client::connect
if you want to immediately spawn a connection task,
regardless of whether the initial connection succeeds.
For further details, see the documentation of Relay::try_connect
.
Sourcepub async fn connect_with_timeout(&self, timeout: Duration)
👎Deprecated since 0.39.0: Use connect
+ wait_for_connection
instead.
pub async fn connect_with_timeout(&self, timeout: Duration)
connect
+ wait_for_connection
instead.Connect to all added relays
Try to connect to the relays and wait for them to be connected at most for the specified timeout
.
The code continues if the timeout
is reached or if all relays connect.
Sourcepub async fn disconnect(&self)
pub async fn disconnect(&self)
Disconnect from all relays
Sourcepub async fn subscriptions(
&self,
) -> HashMap<SubscriptionId, HashMap<RelayUrl, Filter>>
pub async fn subscriptions( &self, ) -> HashMap<SubscriptionId, HashMap<RelayUrl, Filter>>
Get subscriptions
Sourcepub async fn subscription(
&self,
id: &SubscriptionId,
) -> HashMap<RelayUrl, Filter>
pub async fn subscription( &self, id: &SubscriptionId, ) -> HashMap<RelayUrl, Filter>
Get subscription
Sourcepub async fn subscribe(
&self,
filter: Filter,
opts: Option<SubscribeAutoCloseOptions>,
) -> Result<Output<SubscriptionId>, Error>
pub async fn subscribe( &self, filter: Filter, opts: Option<SubscribeAutoCloseOptions>, ) -> Result<Output<SubscriptionId>, Error>
Subscribe to filters
This method create a new subscription. None of the previous subscriptions will be edited/closed when you call this!
So remember to unsubscribe when you no longer need it. You can get all your active (non-auto-closing) subscriptions
by calling client.subscriptions().await
.
If gossip
is enabled (see ClientOptions::gossip
) the events will be requested also to
NIP65 relays (automatically discovered) of public keys included in filters (if any).
§Auto-closing subscription
It’s possible to automatically close a subscription by configuring the SubscribeAutoCloseOptions
.
Note: auto-closing subscriptions aren’t saved in subscriptions map!
§Example
// Compose filter
let subscription = Filter::new()
.pubkeys(vec![keys.public_key()])
.since(Timestamp::now());
// Subscribe
let output = client.subscribe(subscription, None).await?;
println!("Subscription ID: {}", output.val);
// Auto-closing subscription
let id = SubscriptionId::generate();
let subscription = Filter::new().kind(Kind::TextNote).limit(10);
let opts = SubscribeAutoCloseOptions::default().exit_policy(ReqExitPolicy::ExitOnEOSE);
let output = client.subscribe(subscription, Some(opts)).await?;
println!("Subscription ID: {} [auto-closing]", output.val);
Sourcepub async fn subscribe_with_id(
&self,
id: SubscriptionId,
filter: Filter,
opts: Option<SubscribeAutoCloseOptions>,
) -> Result<Output<()>, Error>
pub async fn subscribe_with_id( &self, id: SubscriptionId, filter: Filter, opts: Option<SubscribeAutoCloseOptions>, ) -> Result<Output<()>, Error>
Subscribe to filters with custom SubscriptionId
If gossip
is enabled (see ClientOptions::gossip
) the events will be requested also to
NIP65 relays (automatically discovered) of public keys included in filters (if any).
§Auto-closing subscription
It’s possible to automatically close a subscription by configuring the SubscribeAutoCloseOptions.
Note: auto-closing subscriptions aren’t saved in subscriptions map!
Sourcepub async fn subscribe_to<I, U>(
&self,
urls: I,
filter: Filter,
opts: Option<SubscribeAutoCloseOptions>,
) -> Result<Output<SubscriptionId>, Error>
pub async fn subscribe_to<I, U>( &self, urls: I, filter: Filter, opts: Option<SubscribeAutoCloseOptions>, ) -> Result<Output<SubscriptionId>, Error>
Subscribe to filters to specific relays
This method create a new subscription. None of the previous subscriptions will be edited/closed when you call this! So remember to unsubscribe when you no longer need it.
§Auto-closing subscription
It’s possible to automatically close a subscription by configuring the SubscribeAutoCloseOptions.
Sourcepub async fn subscribe_with_id_to<I, U>(
&self,
urls: I,
id: SubscriptionId,
filter: Filter,
opts: Option<SubscribeAutoCloseOptions>,
) -> Result<Output<()>, Error>
pub async fn subscribe_with_id_to<I, U>( &self, urls: I, id: SubscriptionId, filter: Filter, opts: Option<SubscribeAutoCloseOptions>, ) -> Result<Output<()>, Error>
Subscribe to filter with custom SubscriptionId to specific relays
§Auto-closing subscription
It’s possible to automatically close a subscription by configuring the SubscribeAutoCloseOptions.
Sourcepub async fn subscribe_targeted<I, U>(
&self,
id: SubscriptionId,
targets: I,
opts: SubscribeOptions,
) -> Result<Output<()>, Error>
pub async fn subscribe_targeted<I, U>( &self, id: SubscriptionId, targets: I, opts: SubscribeOptions, ) -> Result<Output<()>, Error>
Targeted subscription
Subscribe to specific relays with specific filters
Sourcepub async fn unsubscribe(&self, id: &SubscriptionId)
pub async fn unsubscribe(&self, id: &SubscriptionId)
Unsubscribe
Sourcepub async fn unsubscribe_all(&self)
pub async fn unsubscribe_all(&self)
Unsubscribe from all subscriptions
Sourcepub async fn sync(
&self,
filter: Filter,
opts: &SyncOptions,
) -> Result<Output<Reconciliation>, Error>
pub async fn sync( &self, filter: Filter, opts: &SyncOptions, ) -> Result<Output<Reconciliation>, Error>
Sync events with relays (negentropy reconciliation)
If gossip
is enabled (see ClientOptions::gossip
) the events will be reconciled also from
NIP65 relays (automatically discovered) of public keys included in filters (if any).
Sourcepub async fn sync_with<I, U>(
&self,
urls: I,
filter: Filter,
opts: &SyncOptions,
) -> Result<Output<Reconciliation>, Error>
pub async fn sync_with<I, U>( &self, urls: I, filter: Filter, opts: &SyncOptions, ) -> Result<Output<Reconciliation>, Error>
Sync events with specific relays (negentropy reconciliation)
Sourcepub async fn fetch_events(
&self,
filter: Filter,
timeout: Duration,
) -> Result<Events, Error>
pub async fn fetch_events( &self, filter: Filter, timeout: Duration, ) -> Result<Events, Error>
Fetch events from relays
§Overview
This is an auto-closing subscription and will be closed automatically on EOSE
.
To use another exit policy, check RelayPool::fetch_events
.
For long-lived subscriptions, check Client::subscribe
.
§Gossip
If gossip
is enabled (see ClientOptions::gossip
) the events will be requested also to
NIP65 relays (automatically discovered) of public keys included in filters (if any).
§Example
let subscription = Filter::new()
.pubkeys(vec![keys.public_key()])
.since(Timestamp::now());
let _events = client
.fetch_events(subscription, Duration::from_secs(10))
.await
.unwrap();
Sourcepub async fn fetch_events_from<I, U>(
&self,
urls: I,
filter: Filter,
timeout: Duration,
) -> Result<Events, Error>
pub async fn fetch_events_from<I, U>( &self, urls: I, filter: Filter, timeout: Duration, ) -> Result<Events, Error>
Fetch events from specific relays
§Overview
This is an auto-closing subscription and will be closed automatically on EOSE
.
To use another exit policy, check RelayPool::fetch_events_from
.
For long-lived subscriptions, check Client::subscribe_to
.
Sourcepub async fn fetch_combined_events(
&self,
filter: Filter,
timeout: Duration,
) -> Result<Events, Error>
pub async fn fetch_combined_events( &self, filter: Filter, timeout: Duration, ) -> Result<Events, Error>
Get events both from database and relays
§Overview
This is an auto-closing subscription and will be closed automatically on EOSE
.
For long-lived subscriptions, check Client::subscribe
.
§Gossip
If gossip
is enabled (see ClientOptions::gossip
) the events will be requested also to
NIP65 relays (automatically discovered) of public keys included in filters (if any).
§Notes and alternative example
This method will be deprecated in the future!
This is a temporary solution for who still want to query events both from database and relays and merge the result.
The optimal solution is to execute a Client::sync
to reconcile missing events, Client::subscribe
to get all
new future events, NostrDatabase::query
to query stored events and Client::handle_notifications
to listen-for/handle new events (i.e. to know when update the UI).
This will allow very fast queries, low bandwidth usage (depending on how many events the client have to reconcile) and a lower load on the relays.
You can obtain the same result with:
// Query database
let stored_events: Events = client.database().query(filter.clone()).await?;
// Query relays
let fetched_events: Events = client.fetch_events(filter, Duration::from_secs(10)).await?;
// Merge result
let events: Events = stored_events.merge(fetched_events);
// Iter and print result
for event in events.into_iter() {
println!("{}", event.as_json());
}
Sourcepub async fn stream_events(
&self,
filter: Filter,
timeout: Duration,
) -> Result<ReceiverStream<Event>, Error>
pub async fn stream_events( &self, filter: Filter, timeout: Duration, ) -> Result<ReceiverStream<Event>, Error>
Stream events from relays
§Overview
This is an auto-closing subscription and will be closed automatically on EOSE
.
To use another exit policy, check RelayPool::stream_events
.
For long-lived subscriptions, check Client::subscribe
.
§Gossip
If gossip
is enabled (see ClientOptions::gossip
) the events will be streamed also from
NIP65 relays (automatically discovered) of public keys included in filters (if any).
Sourcepub async fn stream_events_from<I, U>(
&self,
urls: I,
filter: Filter,
timeout: Duration,
) -> Result<ReceiverStream<Event>, Error>
pub async fn stream_events_from<I, U>( &self, urls: I, filter: Filter, timeout: Duration, ) -> Result<ReceiverStream<Event>, Error>
Stream events from specific relays
§Overview
This is an auto-closing subscription and will be closed automatically on EOSE
.
To use another exit policy, check RelayPool::stream_events_from
.
For long-lived subscriptions, check Client::subscribe_to
.
Sourcepub async fn stream_events_targeted(
&self,
targets: HashMap<RelayUrl, Filter>,
timeout: Duration,
) -> Result<ReceiverStream<Event>, Error>
pub async fn stream_events_targeted( &self, targets: HashMap<RelayUrl, Filter>, timeout: Duration, ) -> Result<ReceiverStream<Event>, Error>
Stream events from specific relays with specific filters
§Overview
This is an auto-closing subscription and will be closed automatically on EOSE
.
To use another exit policy, check RelayPool::stream_events_targeted
.
For long-lived subscriptions, check Client::subscribe_targeted
.
Sourcepub async fn send_msg_to<I, U>(
&self,
urls: I,
msg: ClientMessage<'_>,
) -> Result<Output<()>, Error>
pub async fn send_msg_to<I, U>( &self, urls: I, msg: ClientMessage<'_>, ) -> Result<Output<()>, Error>
Send the client message to a specific relays
Sourcepub async fn batch_msg_to<I, U>(
&self,
urls: I,
msgs: Vec<ClientMessage<'_>>,
) -> Result<Output<()>, Error>
pub async fn batch_msg_to<I, U>( &self, urls: I, msgs: Vec<ClientMessage<'_>>, ) -> Result<Output<()>, Error>
Batch send client messages to specific relays
Sourcepub async fn send_event(&self, event: &Event) -> Result<Output<EventId>, Error>
pub async fn send_event(&self, event: &Event) -> Result<Output<EventId>, Error>
Send the event to relays
§Overview
Send the Event
to all relays with RelayServiceFlags::WRITE
flag.
§Gossip
If gossip
is enabled (see ClientOptions::gossip
):
Sourcepub async fn send_event_to<I, U>(
&self,
urls: I,
event: &Event,
) -> Result<Output<EventId>, Error>
pub async fn send_event_to<I, U>( &self, urls: I, event: &Event, ) -> Result<Output<EventId>, Error>
Send event to specific relays
§Gossip
If gossip
is enabled (see ClientOptions::gossip
) and the Event
is a NIP17/NIP65 relay list,
the gossip data will be updated.
Sourcepub async fn sign_event_builder(
&self,
builder: EventBuilder,
) -> Result<Event, Error>
pub async fn sign_event_builder( &self, builder: EventBuilder, ) -> Result<Event, Error>
Build, sign and return Event
This method requires a NostrSigner
.
Sourcepub async fn send_event_builder(
&self,
builder: EventBuilder,
) -> Result<Output<EventId>, Error>
pub async fn send_event_builder( &self, builder: EventBuilder, ) -> Result<Output<EventId>, Error>
Take an EventBuilder
, sign it by using the NostrSigner
and broadcast to relays.
This method requires a NostrSigner
.
Check Client::send_event
from more details.
Sourcepub async fn send_event_builder_to<I, U>(
&self,
urls: I,
builder: EventBuilder,
) -> Result<Output<EventId>, Error>
pub async fn send_event_builder_to<I, U>( &self, urls: I, builder: EventBuilder, ) -> Result<Output<EventId>, Error>
Take an EventBuilder
, sign it by using the NostrSigner
and broadcast to specific relays.
This method requires a NostrSigner
.
Check Client::send_event_to
from more details.
Sourcepub async fn fetch_metadata(
&self,
public_key: PublicKey,
timeout: Duration,
) -> Result<Option<Metadata>, Error>
pub async fn fetch_metadata( &self, public_key: PublicKey, timeout: Duration, ) -> Result<Option<Metadata>, Error>
Fetch the newest public key metadata from relays.
Returns None
if the Metadata
of the PublicKey
has not been found.
Check Client::fetch_events
for more details.
If you only want to consult stored data,
consider client.database().profile(PUBKEY)
.
Sourcepub async fn set_metadata(
&self,
metadata: &Metadata,
) -> Result<Output<EventId>, Error>
pub async fn set_metadata( &self, metadata: &Metadata, ) -> Result<Output<EventId>, Error>
Update metadata
This method requires a NostrSigner
.
https://github.com/nostr-protocol/nips/blob/master/01.md
§Example
let metadata = Metadata::new()
.name("username")
.display_name("My Username")
.about("Description")
.picture(Url::parse("https://example.com/avatar.png").unwrap())
.nip05("username@example.com");
client.set_metadata(&metadata).await.unwrap();
Sourcepub async fn get_contact_list(
&self,
timeout: Duration,
) -> Result<Vec<Contact>, Error>
pub async fn get_contact_list( &self, timeout: Duration, ) -> Result<Vec<Contact>, Error>
Get the contact list from relays.
This method requires a NostrSigner
.
Sourcepub async fn get_contact_list_public_keys(
&self,
timeout: Duration,
) -> Result<Vec<PublicKey>, Error>
pub async fn get_contact_list_public_keys( &self, timeout: Duration, ) -> Result<Vec<PublicKey>, Error>
Get contact list public keys from relays.
This method requires a NostrSigner
.
Sourcepub async fn get_contact_list_metadata(
&self,
timeout: Duration,
) -> Result<HashMap<PublicKey, Metadata>, Error>
pub async fn get_contact_list_metadata( &self, timeout: Duration, ) -> Result<HashMap<PublicKey, Metadata>, Error>
Get contact list Metadata
from relays.
This method requires a NostrSigner
.
Sourcepub async fn send_private_msg<S, I>(
&self,
receiver: PublicKey,
message: S,
rumor_extra_tags: I,
) -> Result<Output<EventId>, Error>
Available on crate feature nip59
only.
pub async fn send_private_msg<S, I>( &self, receiver: PublicKey, message: S, rumor_extra_tags: I, ) -> Result<Output<EventId>, Error>
nip59
only.Send a private direct message
If gossip
is enabled (see ClientOptions::gossip
) the message will be sent to the NIP17 relays (automatically discovered).
If gossip is not enabled will be sent to all relays with RelayServiceFlags::WRITE
flag.
This method requires a NostrSigner
.
§Errors
Returns Error::PrivateMsgRelaysNotFound
if the receiver hasn’t set the NIP17 list,
meaning that is not ready to receive private messages.
Sourcepub async fn send_private_msg_to<I, S, U, IT>(
&self,
urls: I,
receiver: PublicKey,
message: S,
rumor_extra_tags: IT,
) -> Result<Output<EventId>, Error>where
I: IntoIterator<Item = U>,
S: Into<String>,
U: TryIntoUrl,
IT: IntoIterator<Item = Tag>,
Error: From<<U as TryIntoUrl>::Err>,
Available on crate feature nip59
only.
pub async fn send_private_msg_to<I, S, U, IT>(
&self,
urls: I,
receiver: PublicKey,
message: S,
rumor_extra_tags: IT,
) -> Result<Output<EventId>, Error>where
I: IntoIterator<Item = U>,
S: Into<String>,
U: TryIntoUrl,
IT: IntoIterator<Item = Tag>,
Error: From<<U as TryIntoUrl>::Err>,
nip59
only.Send a private direct message to specific relays
This method requires a NostrSigner
.
Sourcepub async fn gift_wrap<I>(
&self,
receiver: &PublicKey,
rumor: UnsignedEvent,
extra_tags: I,
) -> Result<Output<EventId>, Error>where
I: IntoIterator<Item = Tag>,
Available on crate feature nip59
only.
pub async fn gift_wrap<I>(
&self,
receiver: &PublicKey,
rumor: UnsignedEvent,
extra_tags: I,
) -> Result<Output<EventId>, Error>where
I: IntoIterator<Item = Tag>,
nip59
only.Construct Gift Wrap and send to relays
This method requires a NostrSigner
.
Check Client::send_event
to know how sending events works.
Sourcepub async fn gift_wrap_to<I, U, IT>(
&self,
urls: I,
receiver: &PublicKey,
rumor: UnsignedEvent,
extra_tags: IT,
) -> Result<Output<EventId>, Error>where
I: IntoIterator<Item = U>,
U: TryIntoUrl,
IT: IntoIterator<Item = Tag>,
Error: From<<U as TryIntoUrl>::Err>,
Available on crate feature nip59
only.
pub async fn gift_wrap_to<I, U, IT>(
&self,
urls: I,
receiver: &PublicKey,
rumor: UnsignedEvent,
extra_tags: IT,
) -> Result<Output<EventId>, Error>where
I: IntoIterator<Item = U>,
U: TryIntoUrl,
IT: IntoIterator<Item = Tag>,
Error: From<<U as TryIntoUrl>::Err>,
nip59
only.Construct Gift Wrap and send to specific relays
This method requires a NostrSigner
.
Sourcepub async fn unwrap_gift_wrap(
&self,
gift_wrap: &Event,
) -> Result<UnwrappedGift, Error>
Available on crate feature nip59
only.
pub async fn unwrap_gift_wrap( &self, gift_wrap: &Event, ) -> Result<UnwrappedGift, Error>
nip59
only.Unwrap Gift Wrap event
This method requires a NostrSigner
.
Check UnwrappedGift::from_gift_wrap
to learn more.
Sourcepub async fn handle_notifications<F, Fut>(&self, func: F) -> Result<(), Error>
pub async fn handle_notifications<F, Fut>(&self, func: F) -> Result<(), Error>
Handle notifications
The closure function expects a bool
as output: return true
to exit from the notification loop.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more