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")
|
||||
}
|
||||
|
||||
/// 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.
|
||||
pub fn ensure_relays(&self) -> N34Result<()> {
|
||||
if self.relays.is_empty() {
|
||||
|
||||
@@ -25,7 +25,7 @@ use futures::future;
|
||||
use nostr::{
|
||||
event::{Event, EventId, Kind, Tag, TagStandard, Tags, UnsignedEvent},
|
||||
filter::Filter,
|
||||
key::{Keys, PublicKey},
|
||||
key::PublicKey,
|
||||
nips::{nip01::Coordinate, nip22, nip34::GitRepositoryAnnouncement},
|
||||
parser::NostrParser,
|
||||
types::RelayUrl,
|
||||
@@ -103,17 +103,13 @@ impl NostrClient {
|
||||
/// Initializes a new [`NostrClient`] instance and connects to the specified
|
||||
/// relays.
|
||||
pub async fn init(options: &CliOptions, relays: &[RelayUrl]) -> Self {
|
||||
let client = Self::new(
|
||||
Client::builder()
|
||||
.signer(Keys::new(
|
||||
options
|
||||
.secret_key
|
||||
.as_ref()
|
||||
.expect("This the only method for now")
|
||||
.clone(),
|
||||
))
|
||||
.build(),
|
||||
);
|
||||
let mut client_builder = Client::builder();
|
||||
|
||||
if let Some(signer) = options.signer() {
|
||||
client_builder = client_builder.signer(signer);
|
||||
}
|
||||
|
||||
let client = Self::new(client_builder.build());
|
||||
|
||||
client.add_relays(relays).await;
|
||||
client
|
||||
|
||||
Reference in New Issue
Block a user