Skip to content

Commit

Permalink
sdk: add Client::sync and Client::sync_with methods
Browse files Browse the repository at this point in the history
* Deprecate `Client::reconcile` and `Client::reconcile_with`

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Oct 21, 2024
1 parent 3dd0625 commit 998d45f
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 261 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* sdk: deprecate `Client::get_events_of` and `Client::get_events_from` methods ([Yuki Kishimoto])
* sdk: use `Events` instead of `Vec<Event>` in fetch and query methods ([Yuki Kishimoto])
* sdk: rename `stream_events_of` to `stream_events` ([Yuki Kishimoto])
* sdk: deprecate `Client::reconcile` and `Client::reconcile_with` ([Yuki Kishimoto])
* signer: auto enable `nip44` feature if `nip59` is enabled ([Yuki Kishimoto])
* database: improve `BTreeCappedSet` ([Yuki Kishimoto])
* database: not save invalid event deletion ([Yuki Kishimoto])
Expand Down Expand Up @@ -76,10 +77,11 @@
* relay-builder: handle ephemeral events ([Yuki Kishimoto])
* pool: add `RelayPool::force_remove_relay` method ([Yuki Kishimoto])
* pool: add `RelayFiltering::overwrite_public_keys` method ([Yuki Kishimoto])
* pool: add `RelayPool::reconcile_targeted` ([Yuki Kishimoto])
* pool: add `RelayPool::sync_targeted` ([Yuki Kishimoto])
* pool: add `Relay::reconcile_multi` ([Yuki Kishimoto])
* sdk: add `Client::fetch_events` and `Client::fetch_events_from` methods ([Yuki Kishimoto])
* sdk: add gossip support to `Client::reconcile` ([Yuki Kishimoto])
* sdk: add `Client::sync` and `Client::sync_with` methods ([Yuki Kishimoto])
* sdk: add gossip support to `Client::sync` ([Yuki Kishimoto])
* signer: add `NostrSigner::gift_wrap` ([Yuki Kishimoto])
* zapper: add `WebLNZapper` struct (moved from `nostr-webln` crate) ([Yuki Kishimoto])
* ffi(nostr): add `tag_kind_to_string` func ([Yuki Kishimoto])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async def wipe(self):
# Negentropy reconciliation
f = Filter().author(keys.public_key())
opts = NegentropyOptions()
await client.reconcile(f, opts)
await client.sync(f, opts)

# Query events from database
f = Filter().author(keys.public_key()).limit(10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def main():
# Negentropy reconciliation
f = Filter().author(keys.public_key())
opts = NegentropyOptions()
await client.reconcile(f, opts)
await client.sync(f, opts)

# Query events from database
f = Filter().author(keys.public_key()).limit(10)
Expand Down
36 changes: 18 additions & 18 deletions bindings/nostr-sdk-ffi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ impl Client {
self.inner.unsubscribe_all().await
}

/// Sync events with relays (negentropy reconciliation)
///
/// If `gossip` is enabled (see `Options`) the events will be reconciled also with
/// NIP65 relays (automatically discovered) of public keys included in filters (if any).
///
/// <https://github.com/hoytech/negentropy>
pub async fn sync(
&self,
filter: Arc<Filter>,
opts: Arc<NegentropyOptions>,
) -> Result<ReconciliationOutput> {
Ok(self
.inner
.sync(filter.as_ref().deref().clone(), **opts)
.await?
.into())
}

/// Fetch events from relays
///
/// If `gossip` is enabled (see `Options`) the events will be requested also to
Expand Down Expand Up @@ -621,24 +639,6 @@ impl Client {
.into())
}

/// Negentropy reconciliation
///
/// If `gossip` is enabled (see `Options`) the events will be reconciled also with
/// NIP65 relays (automatically discovered) of public keys included in filters (if any).
///
/// <https://github.com/hoytech/negentropy>
pub async fn reconcile(
&self,
filter: Arc<Filter>,
opts: Arc<NegentropyOptions>,
) -> Result<ReconciliationOutput> {
Ok(self
.inner
.reconcile(filter.as_ref().deref().clone(), **opts)
.await?
.into())
}

/// Handle notifications
pub async fn handle_notifications(&self, handler: Arc<dyn HandleNotification>) -> Result<()> {
Ok(self
Expand Down
8 changes: 3 additions & 5 deletions bindings/nostr-sdk-ffi/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,17 +376,15 @@ impl RelayPool {
.into())
}

/// Negentropy reconciliation
///
/// Use events stored in database
pub async fn reconcile(
/// Sync events with relays (negentropy reconciliation)
pub async fn sync(
&self,
filter: &Filter,
opts: &NegentropyOptions,
) -> Result<ReconciliationOutput> {
Ok(self
.inner
.reconcile(filter.deref().clone(), **opts)
.sync(filter.deref().clone(), **opts)
.await?
.into())
}
Expand Down
18 changes: 6 additions & 12 deletions bindings/nostr-sdk-ffi/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,23 +354,17 @@ impl Relay {
Ok(self.inner.count_events(filters, timeout).await? as u64)
}

/// Negentropy reconciliation
///
/// Use events stored in database
pub async fn reconcile(
&self,
filter: &Filter,
opts: &NegentropyOptions,
) -> Result<Reconciliation> {
/// Sync events with relays (negentropy reconciliation)
pub async fn sync(&self, filter: &Filter, opts: &NegentropyOptions) -> Result<Reconciliation> {
Ok(self
.inner
.reconcile(filter.deref().clone(), **opts)
.sync(filter.deref().clone(), **opts)
.await?
.into())
}

/// Negentropy reconciliation with custom items
pub async fn reconcile_with_items(
/// Sync events with relays (negentropy reconciliation)
pub async fn sync_with_items(
&self,
filter: &Filter,
items: Vec<NegentropyItem>,
Expand All @@ -382,7 +376,7 @@ impl Relay {
.collect();
Ok(self
.inner
.reconcile_with_items(filter.deref().clone(), items, **opts)
.sync_with_items(filter.deref().clone(), items, **opts)
.await?
.into())
}
Expand Down
2 changes: 1 addition & 1 deletion bindings/nostr-sdk-js/examples/negentropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main() {
let direction = NegentropyDirection.Down;
let opts = new NegentropyOptions().direction(direction);
let filter = new Filter().kind(1).limit(1000);
await client.reconcile(filter, opts);
await client.sync(filter, opts);
}

main();
2 changes: 1 addition & 1 deletion bindings/nostr-sdk-js/examples/webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class App extends Component {
try {
let filter = new Filter().author(this.state.public_key);
let opts = new NegentropyOptions();
await this.state.client.reconcile(filter, opts);
await this.state.client.sync(filter, opts);
} catch (error) {
console.log(error)
}
Expand Down
36 changes: 18 additions & 18 deletions bindings/nostr-sdk-js/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,24 @@ impl JsClient {
self.inner.unsubscribe_all().await;
}

/// Sync events with relays (negentropy reconciliation)
///
/// If `gossip` is enabled (see `Options`) the events will be reconciled also with
/// NIP65 relays (automatically discovered) of public keys included in filters (if any).
///
/// <https://github.com/hoytech/negentropy>
pub async fn sync(
&self,
filter: &JsFilter,
opts: &JsNegentropyOptions,
) -> Result<JsReconciliationOutput> {
self.inner
.sync(filter.deref().clone(), **opts)
.await
.map_err(into_err)
.map(|o| o.into())
}

/// Fetch events from relays
///
/// If `gossip` is enabled (see `Options`) the events will be requested also to
Expand Down Expand Up @@ -755,24 +773,6 @@ impl JsClient {
.into())
}

/// Negentropy reconciliation
///
/// If `gossip` is enabled (see `Options`) the events will be reconciled also with
/// NIP65 relays (automatically discovered) of public keys included in filters (if any).
///
/// <https://github.com/hoytech/negentropy>
pub async fn reconcile(
&self,
filter: &JsFilter,
opts: &JsNegentropyOptions,
) -> Result<JsReconciliationOutput> {
self.inner
.reconcile(filter.deref().clone(), **opts)
.await
.map_err(into_err)
.map(|o| o.into())
}

/// Handle notifications
///
/// **This method spawn a thread**, so ensure to keep up the app after calling this (if needed).
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-js/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ impl JsRelayPool {
/// Negentropy reconciliation
///
/// Use events stored in database
pub async fn reconcile(
pub async fn sync(
&self,
filter: &JsFilter,
opts: &JsNegentropyOptions,
) -> Result<JsReconciliationOutput> {
self.inner
.reconcile(filter.deref().clone(), **opts)
.sync(filter.deref().clone(), **opts)
.await
.map_err(into_err)
.map(|o| o.into())
Expand Down
4 changes: 2 additions & 2 deletions bindings/nostr-sdk-js/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ impl JsRelay {
/// Use events stored in database
///
/// <https://github.com/hoytech/negentropy>
pub async fn reconcile(
pub async fn sync(
&self,
filter: &JsFilter,
opts: &JsNegentropyOptions,
) -> Result<JsReconciliation> {
self.inner
.reconcile(filter.deref().clone(), **opts)
.sync(filter.deref().clone(), **opts)
.await
.map_err(into_err)
.map(|o| o.into())
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async fn handle_command(command: ShellCommand, client: &Client) -> Result<()> {

// Dry run
let output: Output<Reconciliation> = client
.reconcile_with(list.iter(), filter.clone(), opts.dry_run())
.sync_with(list.iter(), filter.clone(), opts.dry_run())
.await?;

println!(
Expand All @@ -198,7 +198,7 @@ async fn handle_command(command: ShellCommand, client: &Client) -> Result<()> {
);

// Reconcile
let output: Output<Reconciliation> = client.reconcile_with(list, filter, opts).await?;
let output: Output<Reconciliation> = client.sync_with(list, filter, opts).await?;

println!("Reconciliation terminated:");
println!("- Sent {} events", output.sent.len());
Expand Down
Loading

0 comments on commit 998d45f

Please sign in to comment.