Skip to content

Commit

Permalink
pool: merge all outputs in a single Output<T> struct
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jun 25, 2024
1 parent 3a20dd0 commit aff6fce
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 175 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* nostr: add `EventBuilder::interest_set` ([Yuki Kishimoto])
* nostr: add `title`, `image` and `description` constructors to `Tag` ([Yuki Kishimoto])
* nostr: add `Timestamp::zero` and `Timestamp::is_zero` methods ([Yuki Kishimoto])
* pool: add `Output` and `SendEventOutput` structs ([Yuki Kishimoto])
* pool: add `Output<T>` struct ([Yuki Kishimoto])
* pool: return `ReconciliationOutput` for all `reconcile*` methods ([Yuki Kishimoto])
* signer: add `NostrSigner::unwrap_gift_wrap` method ([Yuki Kishimoto])
* sdk: add `Client::unwrap_gift_wrap` method ([Yuki Kishimoto])
Expand Down
40 changes: 27 additions & 13 deletions bindings/nostr-sdk-ffi/src/pool/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use nostr_ffi::EventId;
use nostr_sdk::pool;
use nostr_sdk::{pool, SubscriptionId};
use uniffi::Record;

/// Output
Expand All @@ -20,11 +20,11 @@ pub struct Output {
pub failed: HashMap<String, Option<String>>,
}

impl From<pool::Output> for Output {
fn from(value: pool::Output) -> Self {
impl From<pool::Output<()>> for Output {
fn from(output: pool::Output<()>) -> Self {
Self {
success: value.success.into_iter().map(|u| u.to_string()).collect(),
failed: value
success: output.success.into_iter().map(|u| u.to_string()).collect(),
failed: output
.failed
.into_iter()
.map(|(u, e)| (u.to_string(), e))
Expand All @@ -42,11 +42,18 @@ pub struct SendEventOutput {
pub output: Output,
}

impl From<pool::SendEventOutput> for SendEventOutput {
fn from(value: pool::SendEventOutput) -> Self {
impl From<pool::Output<nostr_sdk::EventId>> for SendEventOutput {
fn from(output: pool::Output<nostr_sdk::EventId>) -> Self {
Self {
id: Arc::new(value.id.into()),
output: value.output.into(),
id: Arc::new(output.val.into()),
output: Output {
success: output.success.into_iter().map(|u| u.to_string()).collect(),
failed: output
.failed
.into_iter()
.map(|(u, e)| (u.to_string(), e))
.collect(),
},
}
}
}
Expand All @@ -60,11 +67,18 @@ pub struct SubscribeOutput {
pub output: Output,
}

impl From<pool::SubscribeOutput> for SubscribeOutput {
fn from(value: pool::SubscribeOutput) -> Self {
impl From<pool::Output<SubscriptionId>> for SubscribeOutput {
fn from(output: pool::Output<SubscriptionId>) -> Self {
Self {
id: value.id.to_string(),
output: value.output.into(),
id: output.val.to_string(),
output: Output {
success: output.success.into_iter().map(|u| u.to_string()).collect(),
failed: output
.failed
.into_iter()
.map(|(u, e)| (u.to_string(), e))
.collect(),
},
}
}
}
40 changes: 30 additions & 10 deletions bindings/nostr-sdk-js/src/pool/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct JsOutput {
pub failed: Vec<JsFailedOutputItem>,
}

impl From<Output> for JsOutput {
fn from(value: Output) -> Self {
impl From<Output<()>> for JsOutput {
fn from(value: Output<()>) -> Self {
Self {
success: value.success.into_iter().map(|u| u.to_string()).collect(),
failed: value
Expand All @@ -55,11 +55,21 @@ pub struct JsSendEventOutput {
pub output: JsOutput,
}

impl From<SendEventOutput> for JsSendEventOutput {
fn from(value: SendEventOutput) -> Self {
impl From<Output<EventId>> for JsSendEventOutput {
fn from(output: Output<EventId>) -> Self {
Self {
id: value.id.into(),
output: value.output.into(),
id: output.val.into(),
output: JsOutput {
success: output.success.into_iter().map(|u| u.to_string()).collect(),
failed: output
.failed
.into_iter()
.map(|(u, e)| JsFailedOutputItem {
url: u.to_string(),
error: e,
})
.collect(),
},
}
}
}
Expand All @@ -75,11 +85,21 @@ pub struct JsSubscribeOutput {
pub output: JsOutput,
}

impl From<SubscribeOutput> for JsSubscribeOutput {
fn from(value: SubscribeOutput) -> Self {
impl From<Output<SubscriptionId>> for JsSubscribeOutput {
fn from(output: Output<SubscriptionId>) -> Self {
Self {
id: value.id.to_string(),
output: value.output.into(),
id: output.val.to_string(),
output: JsOutput {
success: output.success.into_iter().map(|u| u.to_string()).collect(),
failed: output
.failed
.into_iter()
.map(|(u, e)| JsFailedOutputItem {
url: u.to_string(),
error: e,
})
.collect(),
},
}
}
}
2 changes: 1 addition & 1 deletion crates/nostr-relay-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod relay;
mod util;

pub use self::pool::options::RelayPoolOptions;
pub use self::pool::{Output, RelayPool, RelayPoolNotification, SendEventOutput, SubscribeOutput};
pub use self::pool::{Output, RelayPool, RelayPoolNotification};
pub use self::relay::flags::{AtomicRelayServiceFlags, RelayServiceFlags};
pub use self::relay::limits::RelayLimits;
pub use self::relay::options::{
Expand Down
Loading

0 comments on commit aff6fce

Please sign in to comment.