Wrapped errors in redeemer error
This commit is contained in:
parent
2a360ced3d
commit
3256bfbc32
|
@ -21,11 +21,11 @@ pub enum Error {
|
||||||
missing: Vec<String>,
|
missing: Vec<String>,
|
||||||
extra: Vec<String>,
|
extra: Vec<String>,
|
||||||
},
|
},
|
||||||
#[error("Extraneous redeemer found: Tag {:?}, Index {}", tag, index)]
|
#[error("Extraneous redeemer")]
|
||||||
ExtraneousRedeemer { tag: String, index: u32 },
|
ExtraneousRedeemer,
|
||||||
#[error("Resolved Input not found")]
|
#[error("Resolved Input not found.")]
|
||||||
ResolvedInputNotFound,
|
ResolvedInputNotFound,
|
||||||
#[error("A key hash cannot be the hash of a script")]
|
#[error("A key hash cannot be the hash of a script.")]
|
||||||
ScriptKeyHash,
|
ScriptKeyHash,
|
||||||
#[error("PlutusV1 cost model not found.")]
|
#[error("PlutusV1 cost model not found.")]
|
||||||
V1CostModelNotFound,
|
V1CostModelNotFound,
|
||||||
|
@ -41,12 +41,18 @@ pub enum Error {
|
||||||
ScriptAndInputRefNotAllowed,
|
ScriptAndInputRefNotAllowed,
|
||||||
#[error("Address doesn't contain a payment credential.")]
|
#[error("Address doesn't contain a payment credential.")]
|
||||||
NoPaymentCredential,
|
NoPaymentCredential,
|
||||||
#[error("Missing required datum in witness set. Datum hash: {}", hash)]
|
#[error("Missing required datum: {}", hash)]
|
||||||
MissingRequiredDatum { hash: String },
|
MissingRequiredDatum { hash: String },
|
||||||
#[error("Missing required script. Script hash: {}", hash)]
|
#[error("Missing required script: {}", hash)]
|
||||||
MissingRequiredScript { hash: String },
|
MissingRequiredScript { hash: String },
|
||||||
#[error("Missing required inline datum or datum hash in script input.")]
|
#[error("Missing required inline datum or datum hash in script input.")]
|
||||||
MissingRequiredInlineDatumOrHash,
|
MissingRequiredInlineDatumOrHash,
|
||||||
#[error("Only stake deregistration and delegation are valid certificate script purposes.")]
|
#[error("Only stake deregistration and delegation are valid certificate script purposes.")]
|
||||||
OnlyStakeDeregAndDelegAllowed,
|
OnlyStakeDeregAndDelegAllowed,
|
||||||
|
#[error("Redeemer ({}, {}): {}", tag, index, err)]
|
||||||
|
RedeemerError {
|
||||||
|
tag: String,
|
||||||
|
index: u32,
|
||||||
|
err: Box<Error>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,15 @@ fn slot_range_to_posix_time_range(slot_range: TimeRange, sc: &SlotConfig) -> Tim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn redeemer_tag_to_string(redeemer_tag: &RedeemerTag) -> String {
|
||||||
|
match redeemer_tag {
|
||||||
|
RedeemerTag::Spend => "Spend".to_string(),
|
||||||
|
RedeemerTag::Mint => "Mint".to_string(),
|
||||||
|
RedeemerTag::Cert => "Cert".to_string(),
|
||||||
|
RedeemerTag::Reward => "Reward".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum ScriptVersion {
|
pub enum ScriptVersion {
|
||||||
Native(NativeScript),
|
Native(NativeScript),
|
||||||
|
@ -168,10 +177,7 @@ fn get_script_purpose(
|
||||||
policy_ids.sort();
|
policy_ids.sort();
|
||||||
match policy_ids.get(index as usize) {
|
match policy_ids.get(index as usize) {
|
||||||
Some(policy_id) => Ok(ScriptPurpose::Minting(*policy_id)),
|
Some(policy_id) => Ok(ScriptPurpose::Minting(*policy_id)),
|
||||||
None => Err(Error::ExtraneousRedeemer {
|
None => Err(Error::ExtraneousRedeemer),
|
||||||
tag: "Mint".to_string(),
|
|
||||||
index,
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RedeemerTag::Spend => {
|
RedeemerTag::Spend => {
|
||||||
|
@ -180,10 +186,7 @@ fn get_script_purpose(
|
||||||
inputs.sort();
|
inputs.sort();
|
||||||
match inputs.get(index as usize) {
|
match inputs.get(index as usize) {
|
||||||
Some(input) => Ok(ScriptPurpose::Spending(input.clone())),
|
Some(input) => Ok(ScriptPurpose::Spending(input.clone())),
|
||||||
None => Err(Error::ExtraneousRedeemer {
|
None => Err(Error::ExtraneousRedeemer),
|
||||||
tag: "Spend".to_string(),
|
|
||||||
index,
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RedeemerTag::Reward => {
|
RedeemerTag::Reward => {
|
||||||
|
@ -197,12 +200,7 @@ fn get_script_purpose(
|
||||||
reward_accounts.sort();
|
reward_accounts.sort();
|
||||||
let reward_account = match reward_accounts.get(index as usize) {
|
let reward_account = match reward_accounts.get(index as usize) {
|
||||||
Some(ra) => ra.clone(),
|
Some(ra) => ra.clone(),
|
||||||
None => {
|
None => return Err(Error::ExtraneousRedeemer),
|
||||||
return Err(Error::ExtraneousRedeemer {
|
|
||||||
tag: "Reward".to_string(),
|
|
||||||
index,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let address = Address::from_bytes(&reward_account)?;
|
let address = Address::from_bytes(&reward_account)?;
|
||||||
let credential = match address {
|
let credential = match address {
|
||||||
|
@ -224,10 +222,7 @@ fn get_script_purpose(
|
||||||
.get(index as usize)
|
.get(index as usize)
|
||||||
{
|
{
|
||||||
Some(cert) => Ok(ScriptPurpose::Certifying(cert.clone())),
|
Some(cert) => Ok(ScriptPurpose::Certifying(cert.clone())),
|
||||||
None => Err(Error::ExtraneousRedeemer {
|
None => Err(Error::ExtraneousRedeemer),
|
||||||
tag: "Cert".to_string(),
|
|
||||||
index,
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -610,6 +605,7 @@ pub fn eval_redeemer(
|
||||||
cost_mdls_opt: Option<&CostMdls>,
|
cost_mdls_opt: Option<&CostMdls>,
|
||||||
initial_budget: Option<&ExBudget>,
|
initial_budget: Option<&ExBudget>,
|
||||||
) -> Result<Redeemer, Error> {
|
) -> Result<Redeemer, Error> {
|
||||||
|
let result = || {
|
||||||
let purpose = get_script_purpose(
|
let purpose = get_script_purpose(
|
||||||
redeemer,
|
redeemer,
|
||||||
&tx.transaction_body.inputs,
|
&tx.transaction_body.inputs,
|
||||||
|
@ -618,7 +614,8 @@ pub fn eval_redeemer(
|
||||||
&tx.transaction_body.withdrawals,
|
&tx.transaction_body.withdrawals,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let execution_purpose: ExecutionPurpose = get_execution_purpose(utxos, &purpose, lookup_table)?;
|
let execution_purpose: ExecutionPurpose =
|
||||||
|
get_execution_purpose(utxos, &purpose, lookup_table)?;
|
||||||
|
|
||||||
match execution_purpose {
|
match execution_purpose {
|
||||||
ExecutionPurpose::WithDatum(script_version, datum) => match script_version {
|
ExecutionPurpose::WithDatum(script_version, datum) => match script_version {
|
||||||
|
@ -830,4 +827,14 @@ pub fn eval_redeemer(
|
||||||
ScriptVersion::Native(_) => Err(Error::NativeScriptPhaseTwo),
|
ScriptVersion::Native(_) => Err(Error::NativeScriptPhaseTwo),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match result() {
|
||||||
|
Ok(r) => Ok(r),
|
||||||
|
Err(err) => Err(Error::RedeemerError {
|
||||||
|
tag: redeemer_tag_to_string(&redeemer.tag),
|
||||||
|
index: redeemer.index,
|
||||||
|
err: Box::new(err),
|
||||||
|
}),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue