From 79f153d8d0504f077d07905f66cf02693634e803 Mon Sep 17 00:00:00 2001 From: Michael Yu Date: Tue, 9 Jan 2024 19:24:48 -0800 Subject: [PATCH] Fix old owner cache key (#54) --- .../updater/inscription_updater/stream.rs | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/index/updater/inscription_updater/stream.rs b/src/index/updater/inscription_updater/stream.rs index 23514e3717..e53bbb88a7 100644 --- a/src/index/updater/inscription_updater/stream.rs +++ b/src/index/updater/inscription_updater/stream.rs @@ -16,7 +16,7 @@ use std::str::FromStr; lazy_static! { static ref CLIENT: StreamClient = StreamClient::new(); - static ref OLD_OWNER_CACHE: Cache> = + static ref OLD_OWNER_CACHE: Cache> = Cache::new(Some(Duration::from_secs(60))); static ref IS_BRC20: bool = env::var("KAFKA_TOPIC") .map(|kafka_topic| kafka_topic.to_lowercase().contains("brc20")) @@ -298,28 +298,29 @@ impl StreamEvent { pub(crate) fn with_transfer(&mut self, old_satpoint: SatPoint, index: &Index) -> &mut Self { self.old_location = Some(old_satpoint); - let txid = old_satpoint.outpoint.txid; - self.old_owner = OLD_OWNER_CACHE.get(&txid).unwrap_or_else(|| { - let old_owner = index - .get_transaction(old_satpoint.outpoint.txid) - .unwrap_or(None) - .and_then(|tx| { - tx.output - .get(old_satpoint.outpoint.vout as usize) - .and_then(|txout| { - Address::from_script(&txout.script_pubkey, StreamEvent::get_network()) - .map_err(|e| { - warn!( - "StreamEvent::with_transfer could not parse old_owner address: {}", - e - ); - }) - .ok() - }) - }); - OLD_OWNER_CACHE.set(txid, old_owner.clone()); - old_owner - }); + self.old_owner = OLD_OWNER_CACHE + .get(&old_satpoint.outpoint) + .unwrap_or_else(|| { + let old_owner = index + .get_transaction(old_satpoint.outpoint.txid) + .unwrap_or(None) + .and_then(|tx| { + tx.output + .get(old_satpoint.outpoint.vout as usize) + .and_then(|txout| { + Address::from_script(&txout.script_pubkey, StreamEvent::get_network()) + .map_err(|e| { + warn!( + "StreamEvent::with_transfer could not parse old_owner address: {}", + e + ); + }) + .ok() + }) + }); + OLD_OWNER_CACHE.set(old_satpoint.outpoint, old_owner.clone()); + old_owner + }); // Only enrich the inscription if it is a BRC20 transfer if *IS_BRC20 {