From 6b647d216cd52659c9599928b8cd06c2a26478d5 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 2 May 2024 16:18:13 -0500 Subject: [PATCH] wip fedimint recommendations --- .cargo/config.toml | 4 ++++ .gitignore | 1 + Cargo.toml | 6 ++++-- shell.nix | 5 ++++- src/app.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++- src/app_style.rs | 2 +- src/bin/notedeck.rs | 13 +++++++++---- src/error.rs | 17 +++++++++++++++++ 8 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..ab66d4f --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,4 @@ + +[build] +rustflags = ["--cfg", "tokio_unstable"] +rustdocflags = ["--cfg", "tokio_unstable"] diff --git a/.gitignore b/.gitignore index b0aafcd..c8661e9 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ src/camera.rs *.txt /tags *.mdb +multimint diff --git a/Cargo.toml b/Cargo.toml index 3df5eb6..6f6f495 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ crate-type = ["lib", "cdylib"] [dependencies] #egui-android = { git = "https://github.com/jb55/egui-android.git" } egui = "0.27.2" -eframe = { version = "0.27.2", default-features = false, features = [ "glow", "wgpu", "android-native-activity" ] } -#eframe = { version = "0.26.0", default-features = false, features = [ "glow", "android-native-activity" ] } +#eframe = { version = "0.27.2", default-features = false, features = [ "glow", "wgpu", "android-native-activity" ] } +eframe = { version = "0.27.2", default-features = false, features = [ "glow", "android-native-activity" ] } #eframe = "0.22.0" egui_extras = { version = "0.27.2", features = ["all_loaders"] } ehttp = "0.2.0" @@ -41,6 +41,8 @@ strum = "0.26" strum_macros = "0.26" bitflags = "2.5.0" egui_virtual_list = "0.3.0" +multimint = "0.3.4" +anyhow = "1.0.82" [features] diff --git a/shell.nix b/shell.nix index 2265460..61e2b81 100644 --- a/shell.nix +++ b/shell.nix @@ -22,7 +22,8 @@ let in mkShell ({ - buildInputs = [] ++ pkgs.lib.optional use_android [ + buildInputs = [rustPlatform.bindgenHook rocksdb] ++ pkgs.lib.optional use_android [ + android-sdk ]; nativeBuildInputs = [ @@ -33,6 +34,7 @@ mkShell ({ rustfmt libiconv pkg-config + gdb #cmake fontconfig openssl @@ -52,6 +54,7 @@ mkShell ({ darwin.apple_sdk.frameworks.AppKit ]; + LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib"; ANDROID_NDK_ROOT = android-ndk-path; } // (if !stdenv.isDarwin then { LD_LIBRARY_PATH="${x11libs}"; diff --git a/src/app.rs b/src/app.rs index d4a4d07..eb496c5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,12 +8,19 @@ use crate::timeline; use crate::timeline::{NoteRef, Timeline}; use crate::ui::is_mobile; use crate::Result; +use tokio::task::spawn_blocking; + +use std::str::FromStr; + +use multimint::fedimint_core::api::InviteCode; +use multimint::fedimint_core::config::FederationId; +use multimint::MultiMint; use egui::{Context, Frame, Margin, Style}; use egui_extras::{Size, StripBuilder}; use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage}; -use nostrdb::{BlockType, Config, Mention, Ndb, Note, NoteKey, Transaction}; +use nostrdb::{BlockType, Config, Mention, Ndb, Note, NoteKey, ProfileKey, Transaction}; use std::collections::{HashMap, HashSet}; use std::hash::Hash; @@ -42,6 +49,9 @@ pub struct Damus { pub img_cache: ImageCache, pub ndb: Ndb, + mint: MultiMint, + mint_recs: HashMap>, + frame_history: crate::frame_history::FrameHistory, } @@ -298,6 +308,35 @@ fn setup_initial_nostrdb_subs(damus: &mut Damus) -> Result<()> { filters, timeline.filter[0].limit.unwrap_or(200) as i32, )?; + + for result in &res { + if result.note.kind() == 38000 { + for tag in result.note.tags() { + if tag.count() < 2 { + continue; + } + if tag.get_unchecked(0).variant().str() == Some("u") { + let inv_str = if let Some(s) = tag.get_unchecked(1).variant().str() { + s + } else { + continue; + }; + + if let Ok(code) = InviteCode::from_str(inv_str) { + let fed_id = code.federation_id(); + damus + .mint_recs + .entry(fed_id) + .or_insert_with(|| HashSet::new()) + .insert(result.note.pubkey().to_owned()); + } + } + } + } + } + + println!("{:?}", damus.mint_recs); + timeline.notes = res .iter() .map(|qr| NoteRef { @@ -430,6 +469,7 @@ impl Damus { pub fn new>( cc: &eframe::CreationContext<'_>, data_path: P, + mint: MultiMint, args: Vec, ) -> Self { // This is also where you can customized the look at feel of egui using @@ -461,6 +501,8 @@ impl Damus { let mut config = Config::new(); config.set_ingester_threads(2); + let mint_recs = HashMap::new(); + Self { state: DamusState::Initializing, pool: RelayPool::new(), @@ -468,6 +510,8 @@ impl Damus { note_cache: HashMap::new(), timelines, textmode: false, + mint, + mint_recs, ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"), //compose: "".to_string(), frame_history: FrameHistory::default(), diff --git a/src/app_style.rs b/src/app_style.rs index 9b6e6a1..16cbedc 100644 --- a/src/app_style.rs +++ b/src/app_style.rs @@ -184,7 +184,7 @@ pub fn create_themed_visuals(theme: ColorTheme, default: Visuals) -> Visuals { }, extreme_bg_color: theme.extreme_bg_color, error_fg_color: theme.err_fg_color, - window_rounding: Rounding::same(32.0), + window_rounding: Rounding::same(8.0), window_fill: theme.window_fill, window_shadow: Shadow { offset: [0.0, 8.0].into(), diff --git a/src/bin/notedeck.rs b/src/bin/notedeck.rs index 08887b2..5f3739a 100644 --- a/src/bin/notedeck.rs +++ b/src/bin/notedeck.rs @@ -2,6 +2,10 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release use notedeck::app_creation::generate_native_options; use notedeck::Damus; +use multimint::MultiMint; +use notedeck::Error; + +use std::path::PathBuf; // Entry point for wasm //#[cfg(target_arch = "wasm32")] @@ -10,15 +14,16 @@ use notedeck::Damus; // Desktop #[cfg(not(target_arch = "wasm32"))] #[tokio::main] -async fn main() { +async fn main() -> Result<(), Error> { // Log to stdout (if you run with `RUST_LOG=debug`). tracing_subscriber::fmt::init(); - let _res = eframe::run_native( + let mint = MultiMint::new("multimint".into()).await?; + eframe::run_native( "Damus NoteDeck", generate_native_options(), - Box::new(|cc| Box::new(Damus::new(cc, ".", std::env::args().collect()))), - ); + Box::new(|cc| Box::new(Damus::new(cc, ".", mint, std::env::args().collect()))), + ).map_err(|e| Error::Generic(format!("{:?}", e))) } #[cfg(target_arch = "wasm32")] diff --git a/src/error.rs b/src/error.rs index 37f18eb..494ea95 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,6 +8,8 @@ pub enum Error { Nostr(enostr::Error), Ndb(nostrdb::Error), Image(image::error::ImageError), + Anyhow(anyhow::Error), + //Eframe(eframe::Error), Generic(String), } @@ -25,6 +27,7 @@ impl fmt::Display for Error { Self::Image(e) => write!(f, "{e}"), Self::Generic(e) => write!(f, "{e}"), Self::Io(e) => write!(f, "{e}"), + Self::Anyhow(e) => write!(f, "{e}"), } } } @@ -47,12 +50,26 @@ impl From for Error { } } +impl From for Error { + fn from(err: anyhow::Error) -> Self { + Error::Anyhow(err) + } +} + impl From for Error { fn from(err: enostr::Error) -> Self { Error::Nostr(err) } } +/* +impl From for Error { + fn from(err: eframe::Error) -> Self { + Error::Eframe(err) + } +} +*/ + impl From for Error { fn from(err: io::Error) -> Self { Error::Io(err)