Skip to content

Commit

Permalink
fix: text-note cli command but invalid sig
Browse files Browse the repository at this point in the history
  • Loading branch information
EthnTuttle committed Nov 1, 2023
1 parent 91d51c3 commit 921dc18
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 85 deletions.
71 changes: 34 additions & 37 deletions fedimint-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi;
use std::str::FromStr;
use std::time::{Duration, UNIX_EPOCH};

use anyhow::{anyhow, bail, Context};
use anyhow::{anyhow, bail, Context, Ok};
use bitcoin::{secp256k1, Network};
use bitcoin_hashes::hex;
use bitcoin_hashes::hex::ToHex;
Expand All @@ -24,7 +24,7 @@ use fedimint_ln_common::contracts::ContractId;
use fedimint_mint_client::{MintClientExt, MintClientModule, OOBNotes};
use fedimint_wallet_client::{WalletClientExt, WalletClientModule, WithdrawState};
use futures::StreamExt;
use resolvr_client::ResolvrClientExt;
use nostr_sdk::Event;
use serde::{Deserialize, Serialize};
use serde_json::json;
use time::format_description::well_known::iso8601;
Expand Down Expand Up @@ -482,7 +482,7 @@ pub async fn handle_command(
}
ClientCmd::Nostr { nostr_command } => {
match &nostr_command {
NostrCommands::UpdateMetadata(sub_command_args) => {
NostrCommands::UpdateMetadata(_sub_command_args) => {
todo!()
// nostr_subcommands::update_metadata::update_metadata(
// args.private_key,
Expand All @@ -492,15 +492,12 @@ pub async fn handle_command(
// )
}
NostrCommands::TextNote(sub_command_args) => {
todo!()
// nostr_subcommands::text_note::broadcast_textnote(
// args.private_key,
// args.relays,
// args.difficulty_target,
// sub_command_args,
// )
let id =
nostr_subcommands::text_note::broadcast_textnote(client, sub_command_args)
.await?;
Ok(serde_json::Value::String(id.to_string()))
}
NostrCommands::RecommendRelay(sub_command_args) => {
NostrCommands::RecommendRelay(_sub_command_args) => {
todo!()
// nostr_subcommands::recommend_relay::recommend_relay(
// args.private_key,
Expand All @@ -509,7 +506,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::PublishContactListCsv(sub_command_args) => {
NostrCommands::PublishContactListCsv(_sub_command_args) => {
todo!()
// nostr_subcommands::publish_contactlist_csv::publish_contact_list_from_csv_file(
// args.private_key,
Expand All @@ -518,7 +515,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::SendDirectMessage(sub_command_args) => {
NostrCommands::SendDirectMessage(_sub_command_args) => {
todo!()
// nostr_subcommands::dm::send(
// args.private_key,
Expand All @@ -527,7 +524,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::DeleteEvent(sub_command_args) => {
NostrCommands::DeleteEvent(_sub_command_args) => {
todo!()
// nostr_subcommands::delete_event::delete(
// args.private_key,
Expand All @@ -536,7 +533,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::React(sub_command_args) => {
NostrCommands::React(_sub_command_args) => {
todo!()
// nostr_subcommands::react::react_to_event(
// args.private_key,
Expand All @@ -545,28 +542,28 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::ListEvents(sub_command_args) => {
NostrCommands::ListEvents(_sub_command_args) => {
todo!()
// nostr_subcommands::list_events::list_events(args.relays,
// sub_command_args)
}
NostrCommands::GenerateKeypair(sub_command_args) => {
NostrCommands::GenerateKeypair(_sub_command_args) => {
todo!()
// nostr_subcommands::generate_keypair::get_new_keypair(sub_command_args)
// nostr_subcommands::generate_keypair::get_new_keypair(_sub_command_args)
}
NostrCommands::ConvertKey(sub_command_args) => {
NostrCommands::ConvertKey(_sub_command_args) => {
todo!()
// nostr_subcommands::convert_key::convert_key(sub_command_args)
// nostr_subcommands::convert_key::convert_key(_sub_command_args)
}
NostrCommands::Nprofile(sub_command_args) => {
NostrCommands::Nprofile(_sub_command_args) => {
todo!()
// nostr_subcommands::nprofile::nprofile(sub_command_args)
// nostr_subcommands::nprofile::nprofile(_sub_command_args)
}
NostrCommands::Vanity(sub_command_args) => {
NostrCommands::Vanity(_sub_command_args) => {
todo!()
// nostr_subcommands::vanity::vanity(sub_command_args)
// nostr_subcommands::vanity::vanity(_sub_command_args)
}
NostrCommands::CreatePublicChannel(sub_command_args) => {
NostrCommands::CreatePublicChannel(_sub_command_args) => {
todo!()
// nostr_subcommands::create_public_channel::create_public_channel(
// args.private_key,
Expand All @@ -575,7 +572,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::SetChannelMetadata(sub_command_args) => {
NostrCommands::SetChannelMetadata(_sub_command_args) => {
todo!()
// nostr_subcommands::set_channel_metadata::set_channel_metadata(
// args.private_key,
Expand All @@ -584,7 +581,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::SendChannelMessage(sub_command_args) => {
NostrCommands::SendChannelMessage(_sub_command_args) => {
todo!()
// nostr_subcommands::send_channel_message::send_channel_message(
// args.private_key,
Expand All @@ -593,7 +590,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::HidePublicChannelMessage(sub_command_args) => {
NostrCommands::HidePublicChannelMessage(_sub_command_args) => {
todo!()
// nostr_subcommands::hide_public_channel_message::hide_public_channel_message(
// args.private_key,
Expand All @@ -602,7 +599,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::MutePublicKey(sub_command_args) => {
NostrCommands::MutePublicKey(_sub_command_args) => {
todo!()
// nostr_subcommands::mute_publickey::mute_publickey(
// args.private_key,
Expand All @@ -611,19 +608,19 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::BroadcastEvents(sub_command_args) => {
NostrCommands::BroadcastEvents(_sub_command_args) => {
todo!()
// nostr_subcommands::broadcast_events::broadcast_events(args.relays, sub_command_args)
}
NostrCommands::CreateZapRequest(sub_command_args) => {
NostrCommands::CreateZapRequest(_sub_command_args) => {
todo!()
// nostr_subcommands::zap_request::create_zap_request(
// args.private_key,
// args.difficulty_target,
// sub_command_args,
// )
}
NostrCommands::CreateZapReceipt(sub_command_args) => {
NostrCommands::CreateZapReceipt(_sub_command_args) => {
todo!()
// nostr_subcommands::zap_receipt::send_zap_receipt(
// args.private_key,
Expand All @@ -632,7 +629,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::CreateBadge(sub_command_args) => {
NostrCommands::CreateBadge(_sub_command_args) => {
todo!()
// nostr_subcommands::create_badge::create_badge(
// args.private_key,
Expand All @@ -641,7 +638,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::AwardBadge(sub_command_args) => {
NostrCommands::AwardBadge(_sub_command_args) => {
todo!()
// nostr_subcommands::award_badge::award_badge(
// args.private_key,
Expand All @@ -650,7 +647,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::ProfileBadges(sub_command_args) => {
NostrCommands::ProfileBadges(_sub_command_args) => {
todo!()
// nostr_subcommands::profile_badges::set_profile_badges(
// args.private_key,
Expand All @@ -659,7 +656,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::CustomEvent(sub_command_args) => {
NostrCommands::CustomEvent(_sub_command_args) => {
todo!()
// nostr_subcommands::custom_event::create_custom_event(
// args.private_key,
Expand All @@ -668,7 +665,7 @@ pub async fn handle_command(
// sub_command_args,
// )
}
NostrCommands::SetUserStatus(sub_command_args) => {
NostrCommands::SetUserStatus(_sub_command_args) => {
todo!()
// nostr_subcommands::user_status::set_user_status(
// args.private_key,
Expand Down
92 changes: 46 additions & 46 deletions fedimint-cli/src/nostr_subcommands/text_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ use std::str::FromStr;
use std::time::Duration;

use clap::Args;
use nostr_sdk::prelude::*;
use fedimint_client::Client;
use nostr_sdk::secp256k1::XOnlyPublicKey;
use nostr_sdk::{Event, EventId, Tag, Timestamp, ToBech32};
use resolvr_client::ResolvrClientExt;

use crate::utils::{create_client, handle_keys, parse_key};
use crate::utils::parse_key;

#[derive(Args, Clone, Debug)]
pub struct TextNoteSubCommand {
Expand All @@ -29,55 +32,52 @@ pub struct TextNoteSubCommand {
hex: bool,
}

pub fn broadcast_textnote(
private_key: Option<String>,
relays: Vec<String>,
difficulty_target: u8,
pub async fn broadcast_textnote(
client: Client,
sub_command_args: &TextNoteSubCommand,
) -> Result<()> {
todo!()
// if relays.is_empty() {
// panic!("No relays specified, at least one relay is required!")
// }
) -> anyhow::Result<EventId> {
// Set up tags
let mut tags: Vec<Tag> = vec![];

// let keys = handle_keys(private_key, sub_command_args.hex, true)?;
// let client = create_client(&keys, relays, difficulty_target)?;
// Subject tag (NIP-14)
if let Some(subject) = &sub_command_args.subject {
let subject_tag = Tag::Subject(subject.clone());
tags.push(subject_tag);
}

// // Set up tags
// let mut tags: Vec<Tag> = vec![];
// Any p-tag
for ptag in sub_command_args.ptag.iter() {
// Parse pubkey to ensure we're sending hex keys
let pubkey_hex = parse_key(ptag.clone()).unwrap();
let pubkey = XOnlyPublicKey::from_str(&pubkey_hex)?;
tags.push(Tag::PubKey(pubkey, None));
}
// Any e-tag
for etag in sub_command_args.etag.iter() {
let event_id = EventId::from_hex(etag)?;
tags.push(Tag::Event(event_id, None, None));
}
// Set expiration tag
if let Some(expiration) = sub_command_args.expiration {
let timestamp = Timestamp::now().add(Duration::from_secs(expiration));
tags.push(Tag::Expiration(timestamp));
}

// // Subject tag (NIP-14)
// if let Some(subject) = &sub_command_args.subject {
// let subject_tag = Tag::Subject(subject.clone());
// tags.push(subject_tag);
// }
// sign nostrmint with front

// // Any p-tag
// for ptag in sub_command_args.ptag.iter() {
// // Parse pubkey to ensure we're sending hex keys
// let pubkey_hex = parse_key(ptag.clone())?;
// let pubkey = XOnlyPublicKey::from_str(&pubkey_hex)?;
// tags.push(Tag::PubKey(pubkey, None));
// }
// // Any e-tag
// for etag in sub_command_args.etag.iter() {
// let event_id = EventId::from_hex(etag)?;
// tags.push(Tag::Event(event_id, None, None));
// }
// // Set expiration tag
// if let Some(expiration) = sub_command_args.expiration {
// let timestamp =
// Timestamp::now().add(Duration::from_secs(expiration));
// tags.push(Tag::Expiration(timestamp));
// }
let pubkey = client.get_npub().await?;
let unsigned_event =
nostr_sdk::EventBuilder::new_text_note(sub_command_args.clone().content, &tags)
.to_unsigned_event(pubkey);
client.request_sign_event(unsigned_event.clone()).await?;

// // Publish event
// let event_id = client.publish_text_note(sub_command_args.content.clone(),
// &tags)?; if !sub_command_args.hex {
// println!("Published text note with id: {}", event_id.to_bech32()?);
// } else {
// println!("Published text note with id: {}", event_id.to_hex());
// }
// then
// get signed event back

// Ok(())
println!(
"Published text note with id: {}",
unsigned_event.id.to_bech32()?
);

Ok(unsigned_event.id)
}
5 changes: 3 additions & 2 deletions modules/resolvr-common/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ use fedimint_core::api::{FederationApiExt, FederationResult, IModuleFederationAp
use fedimint_core::module::ApiRequestErased;
use fedimint_core::task::{MaybeSend, MaybeSync};
use fedimint_core::{apply, async_trait_maybe_send};
use nostr_sdk::Event;

use crate::UnsignedEvent;

#[apply(async_trait_maybe_send!)]
pub trait ResolvrFederationApi {
async fn request_sign_event(&self, unsigned_event: UnsignedEvent) -> FederationResult<()>;
async fn request_sign_event(&self, unsigned_event: UnsignedEvent) -> FederationResult<Event>;
async fn get_npub(&self) -> FederationResult<nostr_sdk::key::XOnlyPublicKey>;
}

Expand All @@ -16,7 +17,7 @@ impl<T: ?Sized> ResolvrFederationApi for T
where
T: IModuleFederationApi + MaybeSend + MaybeSync + 'static,
{
async fn request_sign_event(&self, unsigned_event: UnsignedEvent) -> FederationResult<()> {
async fn request_sign_event(&self, unsigned_event: UnsignedEvent) -> FederationResult<Event> {
self.request_current_consensus(
"sign_event".to_string(),
ApiRequestErased::new(unsigned_event),
Expand Down

0 comments on commit 921dc18

Please sign in to comment.