diff --git a/pallas-utxorpc/src/lib.rs b/pallas-utxorpc/src/lib.rs index b3633957..a63b1883 100644 --- a/pallas-utxorpc/src/lib.rs +++ b/pallas-utxorpc/src/lib.rs @@ -53,6 +53,7 @@ fn i64_to_bigint(value: i64) -> Option { pub trait LedgerContext: Clone { fn get_utxos(&self, refs: &[TxoRef]) -> Option; fn get_slot_timestamp(&self, slot: u64) -> Option; + fn get_historical_utxos(&self, refs: &[TxoRef]) -> Option; } #[derive(Default, Clone)] @@ -636,9 +637,24 @@ impl Mapper { } pub fn map_tx(&self, tx: &trv::MultiEraTx) -> u5c::Tx { - let resolved = self.ledger.as_ref().and_then(|ctx| { + let resolved = self.ledger.as_ref().map(|ctx| { let to_resolve = self.find_related_inputs(tx); - ctx.get_utxos(to_resolve.as_slice()) + + let mut utxos = ctx.get_utxos(to_resolve.as_slice()).unwrap_or_default(); + + let missing_refs: Vec<_> = to_resolve + .iter() + .filter(|r| !utxos.contains_key(r)) + .copied() + .collect(); + + if !missing_refs.is_empty() { + if let Some(historical) = ctx.get_historical_utxos(&missing_refs) { + utxos.extend(historical); + } + } + + utxos }); u5c::Tx { @@ -778,6 +794,10 @@ mod tests { fn get_slot_timestamp(&self, _slot: u64) -> Option { None } + + fn get_historical_utxos(&self, _: &[TxoRef]) -> Option { + None + } } #[test]