chore: use the existing signer to get the pubkey instead of a new one
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
@@ -102,7 +102,7 @@ impl CommandRunner for NewArgs {
|
|||||||
)?)?;
|
)?)?;
|
||||||
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
||||||
let client = NostrClient::init(&options, &relays).await;
|
let client = NostrClient::init(&options, &relays).await;
|
||||||
let user_pubk = options.pubkey().await?;
|
let user_pubk = client.pubkey().await?;
|
||||||
let coordinates = naddrs.clone().into_coordinates();
|
let coordinates = naddrs.clone().into_coordinates();
|
||||||
client.add_relays(&naddrs.extract_relays()).await;
|
client.add_relays(&naddrs.extract_relays()).await;
|
||||||
let repos = client.fetch_repos(coordinates.as_slice()).await?;
|
let repos = client.fetch_repos(coordinates.as_slice()).await?;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use clap::{Args, Parser};
|
use clap::{Args, Parser};
|
||||||
use nostr::key::{Keys, PublicKey, SecretKey};
|
use nostr::key::{Keys, SecretKey};
|
||||||
use nostr::nips::nip46::NostrConnectURI;
|
use nostr::nips::nip46::NostrConnectURI;
|
||||||
use nostr::signer::{IntoNostrSigner, NostrSigner};
|
use nostr::signer::{IntoNostrSigner, NostrSigner};
|
||||||
use nostr_connect::client::NostrConnect;
|
use nostr_connect::client::NostrConnect;
|
||||||
@@ -124,19 +124,6 @@ pub enum Commands {
|
|||||||
|
|
||||||
|
|
||||||
impl CliOptions {
|
impl CliOptions {
|
||||||
/// Gets the public key of the user.
|
|
||||||
pub async fn pubkey(&self) -> N34Result<PublicKey> {
|
|
||||||
let Some(signer) = self.signer().await? else {
|
|
||||||
unreachable!(
|
|
||||||
"This method should only be called when a signer is required. If this panic \
|
|
||||||
occurs, it indicates a bug where the command failed to properly require a signer \
|
|
||||||
(which is the default behavior)"
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
signer.get_public_key().await.map_err(N34Error::SignerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the signer
|
/// Returns the signer
|
||||||
pub async fn signer(&self) -> N34Result<Option<Arc<dyn NostrSigner + 'static>>> {
|
pub async fn signer(&self) -> N34Result<Option<Arc<dyn NostrSigner + 'static>>> {
|
||||||
if self.nip07 {
|
if self.nip07 {
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ impl CommandRunner for SendArgs {
|
|||||||
|
|
||||||
let repo_coordinates = naddrs.clone().into_coordinates();
|
let repo_coordinates = naddrs.clone().into_coordinates();
|
||||||
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
||||||
let user_pubk = options.pubkey().await?;
|
|
||||||
let client = NostrClient::init(&options, &relays).await;
|
let client = NostrClient::init(&options, &relays).await;
|
||||||
|
let user_pubk = client.pubkey().await?;
|
||||||
|
|
||||||
client.add_relays(&naddrs.extract_relays()).await;
|
client.add_relays(&naddrs.extract_relays()).await;
|
||||||
if let Some(original_patch) = &self.original_patch {
|
if let Some(original_patch) = &self.original_patch {
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ impl CommandRunner for ReplyArgs {
|
|||||||
let nostr_address_path = utils::nostr_address_path()?;
|
let nostr_address_path = utils::nostr_address_path()?;
|
||||||
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
||||||
let client = NostrClient::init(&options, &relays).await;
|
let client = NostrClient::init(&options, &relays).await;
|
||||||
let user_pubk = options.pubkey().await?;
|
let user_pubk = client.pubkey().await?;
|
||||||
|
|
||||||
let repo_naddrs = if let Some(naddrs) = self.naddrs.flat_naddrs(&options.config.sets)? {
|
let repo_naddrs = if let Some(naddrs) = self.naddrs.flat_naddrs(&options.config.sets)? {
|
||||||
client.add_relays(&naddrs.extract_relays()).await;
|
client.add_relays(&naddrs.extract_relays()).await;
|
||||||
Some(naddrs)
|
Some(naddrs)
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ impl CommandRunner for AnnounceArgs {
|
|||||||
async fn run(mut self, options: CliOptions) -> N34Result<()> {
|
async fn run(mut self, options: CliOptions) -> N34Result<()> {
|
||||||
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
||||||
let client = NostrClient::init(&options, &relays).await;
|
let client = NostrClient::init(&options, &relays).await;
|
||||||
let user_pubk = options.pubkey().await?;
|
let user_pubk = client.pubkey().await?;
|
||||||
let relays_list = client.user_relays_list(user_pubk).await?;
|
let relays_list = client.user_relays_list(user_pubk).await?;
|
||||||
client
|
client
|
||||||
.add_relays(&utils::add_read_relays(relays_list.as_ref()))
|
.add_relays(&utils::add_read_relays(relays_list.as_ref()))
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ pub async fn issue_status_command(
|
|||||||
new_status: IssueStatus,
|
new_status: IssueStatus,
|
||||||
check_fn: impl FnOnce(&IssueStatus) -> N34Result<()>,
|
check_fn: impl FnOnce(&IssueStatus) -> N34Result<()>,
|
||||||
) -> N34Result<()> {
|
) -> N34Result<()> {
|
||||||
let user_pkey = options.pubkey().await?;
|
|
||||||
let naddrs = utils::naddrs_or_file(
|
let naddrs = utils::naddrs_or_file(
|
||||||
naddrs.flat_naddrs(&options.config.sets)?,
|
naddrs.flat_naddrs(&options.config.sets)?,
|
||||||
&utils::nostr_address_path()?,
|
&utils::nostr_address_path()?,
|
||||||
)?;
|
)?;
|
||||||
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
||||||
let client = NostrClient::init(&options, &relays).await;
|
let client = NostrClient::init(&options, &relays).await;
|
||||||
|
let user_pubk = client.pubkey().await?;
|
||||||
client
|
client
|
||||||
.add_relays(&[naddrs.extract_relays(), issue_id.relays].concat())
|
.add_relays(&[naddrs.extract_relays(), issue_id.relays].concat())
|
||||||
.await;
|
.await;
|
||||||
@@ -98,10 +98,10 @@ pub async fn issue_status_command(
|
|||||||
.map(|c| Tag::coordinate(c, relay_hint.clone())),
|
.map(|c| Tag::coordinate(c, relay_hint.clone())),
|
||||||
)
|
)
|
||||||
.dedup_tags()
|
.dedup_tags()
|
||||||
.build(user_pkey);
|
.build(user_pubk);
|
||||||
|
|
||||||
let event_id = status_event.id.expect("There is an id");
|
let event_id = status_event.id.expect("There is an id");
|
||||||
let user_relays_list = client.user_relays_list(user_pkey).await?;
|
let user_relays_list = client.user_relays_list(user_pubk).await?;
|
||||||
let write_relays = [
|
let write_relays = [
|
||||||
relays,
|
relays,
|
||||||
naddrs.extract_relays(),
|
naddrs.extract_relays(),
|
||||||
@@ -134,13 +134,13 @@ pub async fn patch_status_command(
|
|||||||
merge_or_applied_patches: Vec<EventId>,
|
merge_or_applied_patches: Vec<EventId>,
|
||||||
check_fn: impl FnOnce(&PatchStatus) -> N34Result<()>,
|
check_fn: impl FnOnce(&PatchStatus) -> N34Result<()>,
|
||||||
) -> N34Result<()> {
|
) -> N34Result<()> {
|
||||||
let user_pkey = options.pubkey().await?;
|
|
||||||
let naddrs = utils::naddrs_or_file(
|
let naddrs = utils::naddrs_or_file(
|
||||||
naddrs.flat_naddrs(&options.config.sets)?,
|
naddrs.flat_naddrs(&options.config.sets)?,
|
||||||
&utils::nostr_address_path()?,
|
&utils::nostr_address_path()?,
|
||||||
)?;
|
)?;
|
||||||
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
let relays = options.relays.clone().flat_relays(&options.config.sets)?;
|
||||||
let client = NostrClient::init(&options, &relays).await;
|
let client = NostrClient::init(&options, &relays).await;
|
||||||
|
let user_pubk = client.pubkey().await?;
|
||||||
client
|
client
|
||||||
.add_relays(&[naddrs.extract_relays(), patch_id.relays].concat())
|
.add_relays(&[naddrs.extract_relays(), patch_id.relays].concat())
|
||||||
.await;
|
.await;
|
||||||
@@ -227,10 +227,10 @@ pub async fn patch_status_command(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let status_event = status_builder.dedup_tags().build(user_pkey);
|
let status_event = status_builder.dedup_tags().build(user_pubk);
|
||||||
|
|
||||||
let event_id = status_event.id.expect("There is an id");
|
let event_id = status_event.id.expect("There is an id");
|
||||||
let user_relays_list = client.user_relays_list(user_pkey).await?;
|
let user_relays_list = client.user_relays_list(user_pubk).await?;
|
||||||
let write_relays = [
|
let write_relays = [
|
||||||
relays,
|
relays,
|
||||||
naddrs.extract_relays(),
|
naddrs.extract_relays(),
|
||||||
|
|||||||
@@ -124,6 +124,16 @@ impl NostrClient {
|
|||||||
client
|
client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// Returns the users public key
|
||||||
|
pub async fn pubkey(&self) -> N34Result<PublicKey> {
|
||||||
|
self.client
|
||||||
|
.signer()
|
||||||
|
.await?
|
||||||
|
.get_public_key()
|
||||||
|
.await
|
||||||
|
.map_err(N34Error::SignerError)
|
||||||
|
}
|
||||||
|
|
||||||
/// Add relays and connect to them
|
/// Add relays and connect to them
|
||||||
pub async fn add_relays(&self, relays: &[RelayUrl]) {
|
pub async fn add_relays(&self, relays: &[RelayUrl]) {
|
||||||
if relays.is_empty() {
|
if relays.is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user