feat(pubky): return cached packets if nothing else is available

This commit is contained in:
nazeh
2024-10-07 17:17:58 +03:00
parent 5a1a3da70b
commit 76e9520138

View File

@@ -11,7 +11,7 @@ use reqwest::{RequestBuilder, Response};
use tokio::sync::oneshot;
use url::Url;
use pkarr::{Keypair, PkarrClientAsync};
use pkarr::{mainline::MutableItem, Keypair, PkarrClientAsync};
use ::pkarr::{mainline::dht::Testnet, PkarrClient, PublicKey, SignedPacket};
@@ -240,7 +240,10 @@ impl PubkyClient {
&self,
public_key: &PublicKey,
) -> Result<Option<SignedPacket>> {
Ok(self.pkarr.resolve(public_key).await?)
Ok(self.pkarr.resolve(public_key).await?.or(self
.pkarr
.cache()
.get(&MutableItem::target_from_key(public_key.as_bytes(), &None))))
}
pub(crate) async fn pkarr_publish(&self, signed_packet: &SignedPacket) -> Result<()> {