Simplify optional datum extraction by removing duplication
This commit is contained in:
parent
defce9be4e
commit
8a3bbfc89a
|
@ -1,7 +1,4 @@
|
|||
use super::{
|
||||
to_plutus_data::{MintValue, ToPlutusData},
|
||||
Error,
|
||||
};
|
||||
use super::{to_plutus_data::MintValue, Error};
|
||||
use itertools::Itertools;
|
||||
use pallas_addresses::{Address, Network, StakePayload};
|
||||
use pallas_codec::utils::{
|
||||
|
@ -834,23 +831,13 @@ pub fn find_script(
|
|||
|
||||
let lookup_datum = |datum: Option<DatumOption>| match datum {
|
||||
Some(DatumOption::Hash(hash)) => match lookup_table.datum.get(&hash) {
|
||||
Some(d) => Ok(d.clone()),
|
||||
Some(d) => Ok(Some(d.clone())),
|
||||
None => Err(Error::MissingRequiredDatum {
|
||||
hash: hash.to_string(),
|
||||
}),
|
||||
},
|
||||
Some(DatumOption::Data(data)) => Ok(data.0.clone()),
|
||||
_ => Err(Error::MissingRequiredInlineDatumOrHash),
|
||||
};
|
||||
let lookup_datum_v3 = |datum: Option<DatumOption>| match datum {
|
||||
Some(DatumOption::Hash(hash)) => match lookup_table.datum.get(&hash) {
|
||||
Some(d) => Ok(d.clone()),
|
||||
None => Err(Error::MissingRequiredDatum {
|
||||
hash: hash.to_string(),
|
||||
}),
|
||||
},
|
||||
Some(DatumOption::Data(data)) => Ok(data.0.clone()),
|
||||
_ => Ok(None::<PlutusData>.to_plutus_data()),
|
||||
Some(DatumOption::Data(data)) => Ok(Some(data.0.clone())),
|
||||
None => Ok(None),
|
||||
};
|
||||
|
||||
match redeemer.tag {
|
||||
|
@ -922,11 +909,15 @@ pub fn find_script(
|
|||
Address::Shelley(shelley_address) => {
|
||||
let hash = shelley_address.payment().as_hash();
|
||||
let (script, _) = lookup_script(hash)?;
|
||||
let datum = match script {
|
||||
ScriptVersion::V3(_) => lookup_datum_v3(output_datum(&input.resolved)),
|
||||
_ => lookup_datum(output_datum(&input.resolved)),
|
||||
}?;
|
||||
Ok((script, Some(datum)))
|
||||
let datum = lookup_datum(output_datum(&input.resolved))?;
|
||||
|
||||
if datum.is_none()
|
||||
&& matches!(script, ScriptVersion::V1(..) | ScriptVersion::V2(..))
|
||||
{
|
||||
return Err(Error::MissingRequiredInlineDatumOrHash);
|
||||
}
|
||||
|
||||
Ok((script, datum))
|
||||
}
|
||||
_ => Err(Error::NonScriptStakeCredential),
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue