upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs16
-rw-r--r--src/sub_commands/init.rs12
-rw-r--r--src/sub_commands/send.rs25
3 files changed, 39 insertions, 14 deletions
diff --git a/src/client.rs b/src/client.rs
index 97cb856..9bc171a 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -26,6 +26,7 @@ pub struct Client {
26 client: nostr_sdk::Client, 26 client: nostr_sdk::Client,
27 fallback_relays: Vec<String>, 27 fallback_relays: Vec<String>,
28 more_fallback_relays: Vec<String>, 28 more_fallback_relays: Vec<String>,
29 blaster_relays: Vec<String>,
29} 30}
30 31
31#[cfg_attr(test, automock)] 32#[cfg_attr(test, automock)]
@@ -37,6 +38,7 @@ pub trait Connect {
37 async fn disconnect(&self) -> Result<()>; 38 async fn disconnect(&self) -> Result<()>;
38 fn get_fallback_relays(&self) -> &Vec<String>; 39 fn get_fallback_relays(&self) -> &Vec<String>;
39 fn get_more_fallback_relays(&self) -> &Vec<String>; 40 fn get_more_fallback_relays(&self) -> &Vec<String>;
41 fn get_blaster_relays(&self) -> &Vec<String>;
40 async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>; 42 async fn send_event_to(&self, url: &str, event: nostr::event::Event) -> Result<nostr::EventId>;
41 async fn get_events( 43 async fn get_events(
42 &self, 44 &self,
@@ -55,7 +57,6 @@ impl Connect for Client {
55 ] 57 ]
56 } else { 58 } else {
57 vec![ 59 vec![
58 "wss://purplepages.es".to_string(),
59 "wss://relay.damus.io".to_string(), 60 "wss://relay.damus.io".to_string(),
60 "wss://nostr-pub.wellorder.net".to_string(), 61 "wss://nostr-pub.wellorder.net".to_string(),
61 "wss://nos.lol".to_string(), 62 "wss://nos.lol".to_string(),
@@ -70,6 +71,7 @@ impl Connect for Client {
70 ] 71 ]
71 } else { 72 } else {
72 vec![ 73 vec![
74 "wss://purplepages.es".to_string(),
73 "wss://nostr.wine/".to_string(), 75 "wss://nostr.wine/".to_string(),
74 "wss://eden.nostr.land/".to_string(), 76 "wss://eden.nostr.land/".to_string(),
75 "wss://relay.nostr.band/".to_string(), 77 "wss://relay.nostr.band/".to_string(),
@@ -77,10 +79,16 @@ impl Connect for Client {
77 ] 79 ]
78 }; 80 };
79 81
82 let blaster_relays: Vec<String> = if std::env::var("NGITTEST").is_ok() {
83 vec!["ws://localhost:8057".to_string()]
84 } else {
85 vec!["wss://nostr.mutinywallet.com".to_string()]
86 };
80 Client { 87 Client {
81 client: nostr_sdk::Client::new(&nostr::Keys::generate()), 88 client: nostr_sdk::Client::new(&nostr::Keys::generate()),
82 fallback_relays, 89 fallback_relays,
83 more_fallback_relays, 90 more_fallback_relays,
91 blaster_relays,
84 } 92 }
85 } 93 }
86 fn new(opts: Params) -> Self { 94 fn new(opts: Params) -> Self {
@@ -88,6 +96,7 @@ impl Connect for Client {
88 client: nostr_sdk::Client::new(&opts.keys.unwrap_or(nostr::Keys::generate())), 96 client: nostr_sdk::Client::new(&opts.keys.unwrap_or(nostr::Keys::generate())),
89 fallback_relays: opts.fallback_relays, 97 fallback_relays: opts.fallback_relays,
90 more_fallback_relays: opts.more_fallback_relays, 98 more_fallback_relays: opts.more_fallback_relays,
99 blaster_relays: opts.blaster_relays,
91 } 100 }
92 } 101 }
93 102
@@ -110,6 +119,10 @@ impl Connect for Client {
110 &self.more_fallback_relays 119 &self.more_fallback_relays
111 } 120 }
112 121
122 fn get_blaster_relays(&self) -> &Vec<String> {
123 &self.blaster_relays
124 }
125
113 async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> { 126 async fn send_event_to(&self, url: &str, event: Event) -> Result<nostr::EventId> {
114 self.client.add_relay(url).await?; 127 self.client.add_relay(url).await?;
115 self.client.connect_relay(url).await?; 128 self.client.connect_relay(url).await?;
@@ -243,6 +256,7 @@ pub struct Params {
243 pub keys: Option<nostr::Keys>, 256 pub keys: Option<nostr::Keys>,
244 pub fallback_relays: Vec<String>, 257 pub fallback_relays: Vec<String>,
245 pub more_fallback_relays: Vec<String>, 258 pub more_fallback_relays: Vec<String>,
259 pub blaster_relays: Vec<String>,
246} 260}
247 261
248fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> { 262fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> {
diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs
index a95021d..9fdcca5 100644
--- a/src/sub_commands/init.rs
+++ b/src/sub_commands/init.rs
@@ -81,7 +81,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
81 81
82 let mut maintainers = vec![keys.public_key()]; 82 let mut maintainers = vec![keys.public_key()];
83 83
84 let mut repo_relays: Vec<String> = if !args.relays.is_empty() { 84 let repo_relays: Vec<String> = if !args.relays.is_empty() {
85 args.relays.clone() 85 args.relays.clone()
86 } else if let Ok(config) = &repo_config_result { 86 } else if let Ok(config) = &repo_config_result {
87 config.relays.clone() 87 config.relays.clone()
@@ -92,16 +92,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
92 user_ref.relays.write() 92 user_ref.relays.write()
93 }; 93 };
94 94
95 // TODO: add blaster for just repo event and don't add it to repo relays
96 // TODO: fix the tests to support blaster
97 if std::env::var("NGITTEST").is_err()
98 && !repo_relays
99 .iter()
100 .any(|s| s.contains("nostr.mutinywallet.com"))
101 {
102 repo_relays.push("wss://nostr.mutinywallet.com".to_string());
103 }
104
105 if let Ok(config) = &repo_config_result { 95 if let Ok(config) = &repo_config_result {
106 maintainers = extract_pks(config.maintainers.clone())?; 96 maintainers = extract_pks(config.maintainers.clone())?;
107 } 97 }
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs
index 2c1dec8..b8cb271 100644
--- a/src/sub_commands/send.rs
+++ b/src/sub_commands/send.rs
@@ -183,7 +183,23 @@ pub async fn send_events(
183 repo_read_relays: Vec<String>, 183 repo_read_relays: Vec<String>,
184 animate: bool, 184 animate: bool,
185) -> Result<()> { 185) -> Result<()> {
186 let (_, _, _, all) = unique_and_duplicate_all(&my_write_relays, &repo_read_relays); 186 let (_, _, _, mut all) = unique_and_duplicate_all(&my_write_relays, &repo_read_relays);
187
188 let mut fallback = client.get_fallback_relays().clone();
189
190 // blast repo events
191 if events.iter().any(|e| e.kind().as_u64().eq(&REPO_REF_KIND)) {
192 for r in client.get_blaster_relays() {
193 fallback.push(r.to_string());
194 }
195 }
196
197 // then remaining fallback list
198 for r in &fallback {
199 if !all.iter().any(|r2| r2.eq(&r)) {
200 all.push(r);
201 }
202 }
187 203
188 let m = MultiProgress::new(); 204 let m = MultiProgress::new();
189 let pb_style = ProgressStyle::with_template(if animate { 205 let pb_style = ProgressStyle::with_template(if animate {
@@ -215,7 +231,7 @@ pub async fn send_events(
215 231
216 join_all(all.iter().map(|&relay| async { 232 join_all(all.iter().map(|&relay| async {
217 let details = format!( 233 let details = format!(
218 "{}{} {}", 234 "{}{}{} {}",
219 if my_write_relays.iter().any(|r| relay.eq(r)) { 235 if my_write_relays.iter().any(|r| relay.eq(r)) {
220 " [my-relay]" 236 " [my-relay]"
221 } else { 237 } else {
@@ -226,6 +242,11 @@ pub async fn send_events(
226 } else { 242 } else {
227 "" 243 ""
228 }, 244 },
245 if fallback.iter().any(|r| relay.eq(r)) {
246 " [default]"
247 } else {
248 ""
249 },
229 *relay, 250 *relay,
230 ); 251 );
231 let pb = m.add( 252 let pb = m.add(