Skip to content

Commit

Permalink
nostr: rewrite tag
Browse files Browse the repository at this point in the history
* Rename `Tag` enum to `TagStandard`
* Add `Tag` struct
* Remove `GenericTagValue`

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
  • Loading branch information
yukibtc committed Apr 25, 2024
1 parent dd3375c commit 0802f29
Show file tree
Hide file tree
Showing 37 changed files with 1,785 additions and 1,235 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* nostr: adj. kind to be `u16` instead of `u64` according to NIP01 ([Yuki Kishimoto])
* nostr: improve NIP19 serialization performance ([Yuki Kishimoto])
* nostr: improve `EventId::from_hex` performance ([Yuki Kishimoto])
* nostr: rename `Tag` enum to `TagStandard` ([Yuki Kishimoto])
* database: small improvements to flatbuffers `Event::encode` ([Yuki Kishimoto])
* pool: inline `RelayPool` methods ([Yuki Kishimoto])
* sdk: inline `Client`, `ClientBuilder` and `Options` methods ([Yuki Kishimoto])
Expand All @@ -40,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* nostr: add tags indexes to `Event` ([Yuki Kishimoto])
* nostr: add `hex::decode_to_slice` ([Yuki Kishimoto])
* nostr: add `SecretKey::generate` ([Yuki Kishimoto])
* nostr: add `Tag` struct ([Yuki Kishimoto])
* pool: add `RelayPool::start` ([Yuki Kishimoto])
* pool: add `NegentropyDirection` default ([Yuki Kishimoto])
* sdk: add `Client::builder()` ([Yuki Kishimoto])
Expand All @@ -56,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

* nostr: remove `GenericTagValue` ([Yuki Kishimoto])
* ffi(nostr): remove `Kind::match*` methods ([Yuki Kishimoto])

## [v0.30.0]
Expand Down
15 changes: 9 additions & 6 deletions bindings/nostr-ffi/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ impl EventBuilder {
}

#[uniffi::constructor]
pub fn relay_list(list: HashMap<String, Option<RelayMetadata>>) -> Self {
let iter = list
.into_iter()
.map(|(url, r)| (UncheckedUrl::from(url), r.map(|r| r.into())));
Self {
inner: nostr::EventBuilder::relay_list(iter),
pub fn relay_list(map: HashMap<String, Option<RelayMetadata>>) -> Result<Self> {
let mut list = Vec::with_capacity(map.len());
for (url, metadata) in map.into_iter() {
let relay_url: Url = Url::parse(&url)?;
let metadata = metadata.map(|m| m.into());
list.push((relay_url, metadata))
}
Ok(Self {
inner: nostr::EventBuilder::relay_list(list),
})
}

#[uniffi::constructor]
Expand Down
2 changes: 1 addition & 1 deletion bindings/nostr-ffi/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod unsigned;
pub use self::builder::EventBuilder;
pub use self::id::EventId;
pub use self::kind::{Kind, KindEnum};
pub use self::tag::{RelayMetadata, Tag, TagEnum, TagKind};
pub use self::tag::{RelayMetadata, Tag, TagKind};
pub use self::unsigned::UnsignedEvent;
use crate::error::Result;
use crate::nips::nip01::Coordinate;
Expand Down
Loading

0 comments on commit 0802f29

Please sign in to comment.