feat: pow by default
This commit is contained in:
@@ -6,7 +6,7 @@ use std::{str::FromStr, time::Duration};
|
|||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
use crate::common::{create_event_tags, filter_converstation, parse_event, Meta};
|
use crate::common::{create_event_tags, filter_converstation, parse_event, Meta};
|
||||||
use crate::{Nostr, FETCH_LIMIT};
|
use crate::{Nostr, DEFAULT_DIFFICULTY, FETCH_LIMIT};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Type)]
|
#[derive(Debug, Clone, Serialize, Type)]
|
||||||
pub struct RichEvent {
|
pub struct RichEvent {
|
||||||
@@ -442,23 +442,13 @@ pub async fn publish(
|
|||||||
tags.push(tag)
|
tags.push(tag)
|
||||||
};
|
};
|
||||||
|
|
||||||
let signer = client.signer().await.map_err(|err| err.to_string())?;
|
|
||||||
let public_key = signer.public_key().await.map_err(|err| err.to_string())?;
|
|
||||||
|
|
||||||
// Create unsigned event
|
// Create unsigned event
|
||||||
let unsigned_event = match difficulty {
|
let builder =
|
||||||
Some(num) => EventBuilder::text_note(content, tags)
|
EventBuilder::text_note(content, tags).pow(difficulty.unwrap_or(DEFAULT_DIFFICULTY));
|
||||||
.pow(num)
|
|
||||||
.to_unsigned_event(public_key),
|
|
||||||
None => EventBuilder::text_note(content, tags).to_unsigned_event(public_key),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Publish
|
// Publish
|
||||||
match signer.sign_event(unsigned_event).await {
|
match client.send_event_builder(builder).await {
|
||||||
Ok(event) => match client.send_event(event).await {
|
Ok(event_id) => Ok(event_id.to_bech32().unwrap()),
|
||||||
Ok(event_id) => Ok(event_id.to_bech32().map_err(|err| err.to_string())?),
|
|
||||||
Err(err) => Err(err.to_string()),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err.to_string()),
|
Err(err) => Err(err.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ pub struct Profile {
|
|||||||
#[specta::specta]
|
#[specta::specta]
|
||||||
pub async fn get_profile(id: Option<String>, state: State<'_, Nostr>) -> Result<String, String> {
|
pub async fn get_profile(id: Option<String>, state: State<'_, Nostr>) -> Result<String, String> {
|
||||||
let client = &state.client;
|
let client = &state.client;
|
||||||
|
|
||||||
let public_key: PublicKey = match id {
|
let public_key: PublicKey = match id {
|
||||||
Some(user_id) => PublicKey::parse(&user_id).map_err(|e| e.to_string())?,
|
Some(user_id) => PublicKey::parse(&user_id).map_err(|e| e.to_string())?,
|
||||||
None => client.signer().await.unwrap().public_key().await.unwrap(),
|
None => {
|
||||||
|
let signer = client.signer().await.map_err(|e| e.to_string())?;
|
||||||
|
signer.public_key().await.map_err(|e| e.to_string())?
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
@@ -35,10 +39,7 @@ pub async fn get_profile(id: Option<String>, state: State<'_, Nostr>) -> Result<
|
|||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
match client
|
match client
|
||||||
.get_events_of(
|
.get_events_of(vec![filter], EventSource::Database)
|
||||||
vec![filter],
|
|
||||||
EventSource::both(Some(Duration::from_secs(3))),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(events) => {
|
Ok(events) => {
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ struct Subscription {
|
|||||||
#[derive(Serialize, Deserialize, Type, Clone, TauriEvent)]
|
#[derive(Serialize, Deserialize, Type, Clone, TauriEvent)]
|
||||||
struct NewSettings(Settings);
|
struct NewSettings(Settings);
|
||||||
|
|
||||||
|
pub const DEFAULT_DIFFICULTY: u8 = 21;
|
||||||
pub const FETCH_LIMIT: usize = 20;
|
pub const FETCH_LIMIT: usize = 20;
|
||||||
pub const NEWSFEED_NEG_LIMIT: usize = 256;
|
pub const NEWSFEED_NEG_LIMIT: usize = 256;
|
||||||
pub const NOTIFICATION_NEG_LIMIT: usize = 64;
|
pub const NOTIFICATION_NEG_LIMIT: usize = 64;
|
||||||
|
|||||||
Reference in New Issue
Block a user