fix: update to nostr sdk 0.38

This commit is contained in:
xeruf 2025-01-15 23:16:44 +01:00
parent 50503f7f66
commit 9ea491a301
5 changed files with 568 additions and 343 deletions

874
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,14 +13,15 @@ default-run = "mostr"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nostr-sdk = "0.38"
# Basics
tokio = { version = "1.42", features = ["rt", "rt-multi-thread", "macros"] }
regex = "1.10.6"
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
regex = "1.11"
# System
log = "0.4"
env_logger = "0.11"
colog = "1.3"
colored = "2.1"
colored = "2.2"
rustyline = { git = "https://github.com/xeruf/rustyline", rev = "465b14d" }
# OS-Specific Abstractions
keyring = "3"
@ -30,9 +31,8 @@ whoami = "1.5"
# Application Utils
itertools = "0.12"
chrono = "0.4"
parse_datetime = "0.5.0"
parse_datetime = "0.5"
interim = { version = "0.1", features = ["chrono"] }
nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "e82bc787bdd8490ceadb034fe4483e4df1e91b2a" }
[dev-dependencies]
mostr = { path = ".", default-features = false }

View file

@ -14,21 +14,21 @@ const UNDO_DELAY: u64 = 60;
#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) enum MostrMessage {
Flush,
NewRelay(Url),
AddTasks(Url, Vec<Event>),
NewRelay(RelayUrl),
AddTasks(RelayUrl, Vec<Event>),
}
type Events = Vec<Event>;
#[derive(Debug, Clone)]
pub(crate) struct EventSender {
pub(crate) url: Option<Url>,
pub(crate) url: Option<RelayUrl>,
pub(crate) tx: Sender<MostrMessage>,
pub(crate) keys: Keys,
pub(crate) queue: RefCell<Events>,
}
impl EventSender {
pub(crate) fn from(url: Option<Url>, tx: &Sender<MostrMessage>, keys: &Keys) -> Self {
pub(crate) fn from(url: Option<RelayUrl>, tx: &Sender<MostrMessage>, keys: &Keys) -> Self {
EventSender {
url,
tx: tx.clone(),

View file

@ -206,12 +206,12 @@ async fn main() -> Result<()> {
let metadata_clone = metadata.clone();
let (tx, mut rx) = mpsc::channel::<MostrMessage>(64);
let tasks_for_url = |url: Option<Url>| TasksRelay::from(url, &tx, &keys, Some(metadata.clone()));
let mut relays: HashMap<Option<Url>, TasksRelay> =
let tasks_for_url = |url: Option<RelayUrl>| TasksRelay::from(url, &tx, &keys, Some(metadata.clone()));
let mut relays: HashMap<Option<RelayUrl>, TasksRelay> =
client.relays().await.into_keys().map(|url| (Some(url.clone()), tasks_for_url(Some(url)))).collect();
let sender = tokio::spawn(async move {
let mut queue: Option<(Url, Vec<Event>)> = None;
let mut queue: Option<(RelayUrl, Vec<Event>)> = None;
or_warn!(client.set_metadata(&metadata_clone).await, "Unable to set metadata");
@ -267,9 +267,7 @@ async fn main() -> Result<()> {
if relays.is_empty() {
relays.insert(None, tasks_for_url(None));
}
let mut selected_relay: Option<Url> = relays.keys()
.find_or_first(|url| url.as_ref().is_some_and(|u| u.scheme() == "wss"))
.unwrap().clone();
let mut selected_relay: Option<RelayUrl> = relays.keys().next().unwrap().clone();
{
let tasks = relays.get_mut(&selected_relay).unwrap();
@ -734,7 +732,7 @@ async fn main() -> Result<()> {
println!("{}", tasks);
continue 'repl;
}
or_warn!(Url::parse(&command), "Failed to parse url {}", command).map(|url| {
or_warn!(RelayUrl::parse(&command), "Failed to parse url {}", command).map(|url| {
match tx.try_send(MostrMessage::NewRelay(url.clone())) {
Err(e) => error!("Nostr communication thread failure, cannot add relay \"{url}\": {e}"),
Ok(_) => {

View file

@ -20,10 +20,7 @@ use chrono::{Local, TimeDelta};
use colored::Colorize;
use itertools::Itertools;
use log::{debug, error, info, trace, warn};
use nostr_sdk::{
Alphabet, Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey,
SingleLetterTag, Tag, TagKind, Timestamp, Url,
};
use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, JsonUtil, Keys, Kind, Metadata, PublicKey, RelayUrl, SingleLetterTag, Tag, TagKind, Timestamp, Url};
use regex::bytes::Regex;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::fmt::{Display, Formatter};
@ -155,7 +152,7 @@ impl Display for StateFilter {
impl TasksRelay {
pub(crate) fn from(
url: Option<Url>,
url: Option<RelayUrl>,
tx: &Sender<MostrMessage>,
keys: &Keys,
metadata: Option<Metadata>,