Skip to content

Commit

Permalink
Fix crash on inscription not found
Browse files Browse the repository at this point in the history
  • Loading branch information
mi-yu committed Oct 16, 2023
1 parent 5175a79 commit eec21d0
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/index/updater/inscription_updater/stream.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::inscription::TransactionInscription;
use crate::subcommand::traits::Output;
use base64::{engine::general_purpose, Engine as _};
use log::{error, warn};

use super::*;
use rdkafka::{
Expand Down Expand Up @@ -260,29 +261,34 @@ impl StreamEvent {

pub(crate) fn with_transfer(&mut self, old_satpoint: SatPoint, index: &Index) -> &mut Self {
self.old_location = Some(old_satpoint);
if let Some(inscription) = index
self.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| {
error!(
"StreamEvent::with_transfer could not parse old_owner address: {}",
e
);
})
.ok()
})
});
match index
.get_inscription_by_id_unsafe(self.inscription_id)
.unwrap_or_else(|_| panic!("Inscription should exist: {}", self.inscription_id))
.unwrap_or(None)
{
self.enrich_content(inscription);
self.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| {
log::error!(
"StreamEvent::with_transfer could not parse old_owner address: {}",
e
);
})
.ok()
})
});
};
Some(inscription) => {
self.enrich_content(inscription);
}
None => {
warn!("could not find inscription for id {}", self.inscription_id);
}
}
self
}

Expand Down

0 comments on commit eec21d0

Please sign in to comment.