chore: Add the signer to the client if found
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
@@ -117,6 +117,14 @@ impl CliOptions {
|
|||||||
unreachable!("There is no other method until now")
|
unreachable!("There is no other method until now")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the signer
|
||||||
|
pub fn signer(&self) -> Option<impl nostr::signer::IntoNostrSigner> {
|
||||||
|
if let Some(sk) = &self.secret_key {
|
||||||
|
return Some(Keys::new(sk.clone()));
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns an error if there are no relays.
|
/// Returns an error if there are no relays.
|
||||||
pub fn ensure_relays(&self) -> N34Result<()> {
|
pub fn ensure_relays(&self) -> N34Result<()> {
|
||||||
if self.relays.is_empty() {
|
if self.relays.is_empty() {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use futures::future;
|
|||||||
use nostr::{
|
use nostr::{
|
||||||
event::{Event, EventId, Kind, Tag, TagStandard, Tags, UnsignedEvent},
|
event::{Event, EventId, Kind, Tag, TagStandard, Tags, UnsignedEvent},
|
||||||
filter::Filter,
|
filter::Filter,
|
||||||
key::{Keys, PublicKey},
|
key::PublicKey,
|
||||||
nips::{nip01::Coordinate, nip22, nip34::GitRepositoryAnnouncement},
|
nips::{nip01::Coordinate, nip22, nip34::GitRepositoryAnnouncement},
|
||||||
parser::NostrParser,
|
parser::NostrParser,
|
||||||
types::RelayUrl,
|
types::RelayUrl,
|
||||||
@@ -103,17 +103,13 @@ impl NostrClient {
|
|||||||
/// Initializes a new [`NostrClient`] instance and connects to the specified
|
/// Initializes a new [`NostrClient`] instance and connects to the specified
|
||||||
/// relays.
|
/// relays.
|
||||||
pub async fn init(options: &CliOptions, relays: &[RelayUrl]) -> Self {
|
pub async fn init(options: &CliOptions, relays: &[RelayUrl]) -> Self {
|
||||||
let client = Self::new(
|
let mut client_builder = Client::builder();
|
||||||
Client::builder()
|
|
||||||
.signer(Keys::new(
|
if let Some(signer) = options.signer() {
|
||||||
options
|
client_builder = client_builder.signer(signer);
|
||||||
.secret_key
|
}
|
||||||
.as_ref()
|
|
||||||
.expect("This the only method for now")
|
let client = Self::new(client_builder.build());
|
||||||
.clone(),
|
|
||||||
))
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
client.add_relays(relays).await;
|
client.add_relays(relays).await;
|
||||||
client
|
client
|
||||||
|
|||||||
Reference in New Issue
Block a user