Skip to content

Commit f221dfc

Browse files
committed
sdk: update reconcilie method
1 parent 5c35019 commit f221dfc

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

crates/nostr-sdk/examples/reconcilie.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@ async fn main() -> Result<()> {
1313
let my_keys = Keys::new(secret_key);
1414

1515
let client = Client::new(&my_keys);
16-
client.add_relay("wss://relay.damus.io", None).await?;
16+
client.add_relay("wss://atl.purplerelay.com", None).await?;
1717

1818
client.connect().await;
1919

2020
let filter = Filter::new()
2121
.author(my_keys.public_key().to_string())
2222
.limit(10);
23-
let relay = client.relay("wss://relay.damus.io").await?;
24-
relay
25-
.reconcilie(filter, vec![(EventId::all_zeros(), Timestamp::now())])
26-
.await?;
23+
let relay = client.relay("wss://atl.purplerelay.com").await?;
24+
relay.reconcilie(filter, Vec::new()).await?;
2725

2826
Ok(())
2927
}

crates/nostr-sdk/src/relay/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,8 @@ impl Relay {
15771577

15781578
negentropy.seal()?;
15791579

1580-
let id = SubscriptionId::generate();
1581-
let open_msg = ClientMessage::neg_open(&mut negentropy, &id, filter)?;
1580+
let sub_id = SubscriptionId::generate();
1581+
let open_msg = ClientMessage::neg_open(&mut negentropy, &sub_id, filter)?;
15821582

15831583
self.send_msg(open_msg, Some(Duration::from_secs(10)))
15841584
.await?;
@@ -1592,7 +1592,7 @@ impl Relay {
15921592
subscription_id,
15931593
message,
15941594
} => {
1595-
if subscription_id == id {
1595+
if subscription_id == sub_id {
15961596
let query: Bytes = Bytes::from_hex(message)?;
15971597
let mut need_ids: Vec<Bytes> = Vec::new();
15981598
let msg: Option<Bytes> = negentropy.reconcile_with_ids(
@@ -1601,14 +1601,24 @@ impl Relay {
16011601
&mut need_ids,
16021602
)?;
16031603

1604-
// TODO: request ids to relay
1605-
println!("IDs: {need_ids:?}");
1604+
let ids: Vec<String> =
1605+
need_ids.into_iter().map(|id| id.to_hex()).collect();
1606+
let filter = Filter::new().ids(ids);
1607+
self.req_events_of(
1608+
vec![filter],
1609+
Duration::from_secs(120),
1610+
FilterOptions::ExitOnEOSE,
1611+
);
16061612

16071613
match msg {
16081614
Some(query) => {
1615+
tracing::info!(
1616+
"Continue with reconciliation with {}",
1617+
self.url
1618+
);
16091619
self.send_msg(
16101620
ClientMessage::NegMsg {
1611-
subscription_id: id.clone(),
1621+
subscription_id: sub_id.clone(),
16121622
message: query.to_hex(),
16131623
},
16141624
None,
@@ -1626,7 +1636,7 @@ impl Relay {
16261636
subscription_id,
16271637
code,
16281638
} => {
1629-
if subscription_id == id {
1639+
if subscription_id == sub_id {
16301640
tracing::error!("Negentropy syncing error: {code}");
16311641
break;
16321642
}

0 commit comments

Comments
 (0)