Revert "json: deserialize note ids into bytes"
This reverts commit 1ba597fc0a.
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1051,7 +1051,6 @@ name = "enostr"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ewebsock",
|
"ewebsock",
|
||||||
"hex",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
|||||||
7
enostr/Cargo.lock
generated
7
enostr/Cargo.lock
generated
@@ -108,7 +108,6 @@ name = "enostr"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ewebsock",
|
"ewebsock",
|
||||||
"hex",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -259,12 +258,6 @@ dependencies = [
|
|||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hex"
|
|
||||||
version = "0.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
|
|||||||
@@ -11,4 +11,3 @@ serde_derive = "1"
|
|||||||
serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence
|
serde = { version = "1", features = ["derive"] } # You only need this if you want app persistence
|
||||||
serde_json = "1.0.89"
|
serde_json = "1.0.89"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
hex = "0.4.3"
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ pub enum Error {
|
|||||||
MessageDecodeFailed,
|
MessageDecodeFailed,
|
||||||
InvalidSignature,
|
InvalidSignature,
|
||||||
Json(serde_json::Error),
|
Json(serde_json::Error),
|
||||||
Hex(hex::FromHexError),
|
|
||||||
Generic(String),
|
Generic(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +36,3 @@ impl From<serde_json::Error> for Error {
|
|||||||
Error::Json(e)
|
Error::Json(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<hex::FromHexError> for Error {
|
|
||||||
fn from(e: hex::FromHexError) -> Self {
|
|
||||||
Error::Hex(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use crate::{Error, Pubkey, Result};
|
use crate::{Error, Pubkey, Result};
|
||||||
use hex;
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
@@ -7,7 +6,7 @@ use std::hash::{Hash, Hasher};
|
|||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Event {
|
pub struct Event {
|
||||||
/// 32-bytes sha256 of the the serialized event data
|
/// 32-bytes sha256 of the the serialized event data
|
||||||
pub id: NoteId,
|
pub id: EventId,
|
||||||
/// 32-bytes hex-encoded public key of the event creator
|
/// 32-bytes hex-encoded public key of the event creator
|
||||||
#[serde(rename = "pubkey")]
|
#[serde(rename = "pubkey")]
|
||||||
pub pubkey: Pubkey,
|
pub pubkey: Pubkey,
|
||||||
@@ -60,7 +59,7 @@ impl Event {
|
|||||||
sig: &str,
|
sig: &str,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let event = Event {
|
let event = Event {
|
||||||
id: id.try_into()?,
|
id: id.to_string().into(),
|
||||||
pubkey: pubkey.to_string().into(),
|
pubkey: pubkey.to_string().into(),
|
||||||
created_at,
|
created_at,
|
||||||
kind,
|
kind,
|
||||||
@@ -81,57 +80,17 @@ impl std::str::FromStr for Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Eq, PartialEq, Clone, Hash)]
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Hash)]
|
||||||
pub struct NoteId([u8; 32]);
|
pub struct EventId(String);
|
||||||
|
|
||||||
// Implement `Deserialize` for `NoteId`.
|
impl From<String> for EventId {
|
||||||
impl<'de> serde::Deserialize<'de> for NoteId {
|
fn from(s: String) -> Self {
|
||||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
EventId(s)
|
||||||
where
|
|
||||||
D: serde::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
// Deserialize the JSON string
|
|
||||||
let s = String::deserialize(deserializer)?;
|
|
||||||
|
|
||||||
// Convert the hex string to bytes
|
|
||||||
let bytes = hex::decode(&s).map_err(serde::de::Error::custom)?;
|
|
||||||
|
|
||||||
// Check that the length is exactly 32
|
|
||||||
if bytes.len() != 32 {
|
|
||||||
return Err(serde::de::Error::custom("Expected exactly 32 bytes"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert the Vec<u8> to [u8; 32]
|
|
||||||
let mut array = [0; 32];
|
|
||||||
array.copy_from_slice(&bytes);
|
|
||||||
|
|
||||||
Ok(NoteId(array))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<String> for NoteId {
|
impl From<EventId> for String {
|
||||||
type Error = hex::FromHexError;
|
fn from(evid: EventId) -> Self {
|
||||||
|
evid.0
|
||||||
fn try_from(s: String) -> std::result::Result<Self, Self::Error> {
|
|
||||||
let s: &str = &s;
|
|
||||||
NoteId::try_from(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<[u8; 32]> for NoteId {
|
|
||||||
fn from(s: [u8; 32]) -> Self {
|
|
||||||
NoteId(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&str> for NoteId {
|
|
||||||
type Error = hex::FromHexError;
|
|
||||||
|
|
||||||
fn try_from(s: &str) -> std::result::Result<Self, Self::Error> {
|
|
||||||
let decoded = hex::decode(s)?;
|
|
||||||
match decoded.try_into() {
|
|
||||||
Ok(bs) => Ok(NoteId(bs)),
|
|
||||||
Err(_) => Err(hex::FromHexError::InvalidStringLength),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
use crate::{NoteId, Pubkey};
|
use crate::{EventId, Pubkey};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
|
||||||
pub struct Filter {
|
pub struct Filter {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
ids: Option<Vec<NoteId>>,
|
ids: Option<Vec<EventId>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
authors: Option<Vec<Pubkey>>,
|
authors: Option<Vec<Pubkey>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
kinds: Option<Vec<u64>>,
|
kinds: Option<Vec<u64>>,
|
||||||
#[serde(rename = "#e")]
|
#[serde(rename = "#e")]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
events: Option<Vec<NoteId>>,
|
events: Option<Vec<EventId>>,
|
||||||
#[serde(rename = "#p")]
|
#[serde(rename = "#p")]
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pubkeys: Option<Vec<Pubkey>>,
|
pubkeys: Option<Vec<Pubkey>>,
|
||||||
@@ -37,7 +37,7 @@ impl Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ids(mut self, ids: Vec<NoteId>) -> Self {
|
pub fn ids(mut self, ids: Vec<EventId>) -> Self {
|
||||||
self.ids = Some(ids);
|
self.ids = Some(ids);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ impl Filter {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn events(mut self, events: Vec<NoteId>) -> Self {
|
pub fn events(mut self, events: Vec<EventId>) -> Self {
|
||||||
self.events = Some(events);
|
self.events = Some(events);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ mod relay;
|
|||||||
|
|
||||||
pub use client::ClientMessage;
|
pub use client::ClientMessage;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use event::{Event, NoteId};
|
pub use event::{Event, EventId};
|
||||||
pub use ewebsock;
|
pub use ewebsock;
|
||||||
pub use filter::Filter;
|
pub use filter::Filter;
|
||||||
pub use profile::Profile;
|
pub use profile::Profile;
|
||||||
|
|||||||
20
src/app.rs
20
src/app.rs
@@ -5,8 +5,8 @@ use crate::ui::padding;
|
|||||||
use crate::Result;
|
use crate::Result;
|
||||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||||
use egui::widgets::Spinner;
|
use egui::widgets::Spinner;
|
||||||
use egui::{Context, Frame, TextureHandle, TextureId};
|
use egui::{Color32, Context, Frame, TextureHandle, TextureId};
|
||||||
use enostr::{ClientMessage, Filter, NoteId, Profile, Pubkey, RelayEvent, RelayMessage};
|
use enostr::{ClientMessage, EventId, Filter, Profile, Pubkey, RelayEvent, RelayMessage};
|
||||||
use poll_promise::Promise;
|
use poll_promise::Promise;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
@@ -44,10 +44,11 @@ pub struct Damus {
|
|||||||
|
|
||||||
pool: RelayPool,
|
pool: RelayPool,
|
||||||
|
|
||||||
all_events: HashMap<NoteId, Event>,
|
all_events: HashMap<EventId, Event>,
|
||||||
events: Vec<NoteId>,
|
events: Vec<EventId>,
|
||||||
|
|
||||||
img_cache: ImageCache,
|
img_cache: ImageCache,
|
||||||
|
bg_color: Color32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Damus {
|
impl Default for Damus {
|
||||||
@@ -57,9 +58,10 @@ impl Default for Damus {
|
|||||||
contacts: Contacts::new(),
|
contacts: Contacts::new(),
|
||||||
all_events: HashMap::new(),
|
all_events: HashMap::new(),
|
||||||
pool: RelayPool::default(),
|
pool: RelayPool::default(),
|
||||||
events: Vec::with_capacity(2000),
|
events: vec![],
|
||||||
img_cache: HashMap::new(),
|
img_cache: HashMap::new(),
|
||||||
n_panels: 1,
|
n_panels: 1,
|
||||||
|
bg_color: Color32::from_rgb(31, 31, 31),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,8 +459,8 @@ fn add_test_events(damus: &mut Damus) {
|
|||||||
// For inspiration and more examples, go to https://emilk.github.io/egui
|
// For inspiration and more examples, go to https://emilk.github.io/egui
|
||||||
|
|
||||||
let test_event = Event {
|
let test_event = Event {
|
||||||
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".try_into().unwrap(),
|
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string().into(),
|
||||||
pubkey: "f0a6ff7f70b872de6d82c8daec692a433fd23b6a49f25923c6f034df715cdeec".try_into().unwrap(),
|
pubkey: "f0a6ff7f70b872de6d82c8daec692a433fd23b6a49f25923c6f034df715cdeec".to_string().into(),
|
||||||
created_at: 1667781968,
|
created_at: 1667781968,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
@@ -467,8 +469,8 @@ fn add_test_events(damus: &mut Damus) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let test_event2 = Event {
|
let test_event2 = Event {
|
||||||
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".try_into().unwrap(),
|
id: "6938e3cd841f3111dbdbd909f87fd52c3d1f1e4a07fd121d1243196e532811cb".to_string().into(),
|
||||||
pubkey: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".try_into().unwrap(),
|
pubkey: "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245".to_string().into(),
|
||||||
created_at: 1667781968,
|
created_at: 1667781968,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
tags: vec![],
|
tags: vec![],
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use enostr::{NoteId, Profile, Pubkey};
|
use enostr::{EventId, Profile, Pubkey};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct Contacts {
|
pub struct Contacts {
|
||||||
pub events: HashMap<Pubkey, NoteId>,
|
pub events: HashMap<Pubkey, EventId>,
|
||||||
pub profiles: HashMap<Pubkey, Profile>,
|
pub profiles: HashMap<Pubkey, Profile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user