fixed bug in tx_in_info

This commit is contained in:
alessandrokonrad 2022-09-11 10:07:17 +02:00 committed by rvcas
parent ecd363e67d
commit f0d17897ab
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
1 changed files with 12 additions and 16 deletions

View File

@ -736,11 +736,13 @@ impl ToPlutusData for bool {
// Plutus V2 only for now // Plutus V2 only for now
#[derive(Debug, PartialEq, Clone)]
pub struct TxInInfo { pub struct TxInInfo {
out_ref: TransactionInput, out_ref: TransactionInput,
resolved: TransactionOutput, resolved: TransactionOutput,
} }
#[derive(Debug, PartialEq, Clone)]
pub enum ScriptPurpose { pub enum ScriptPurpose {
Minting(PolicyId), Minting(PolicyId),
Spending(TransactionInput), Spending(TransactionInput),
@ -748,6 +750,7 @@ pub enum ScriptPurpose {
Certifying(Certificate), Certifying(Certificate),
} }
#[derive(Debug, PartialEq, Clone)]
pub struct TxInfo { pub struct TxInfo {
inputs: MaybeIndefArray<TxInInfo>, inputs: MaybeIndefArray<TxInInfo>,
reference_inputs: MaybeIndefArray<TxInInfo>, reference_inputs: MaybeIndefArray<TxInInfo>,
@ -763,13 +766,14 @@ pub struct TxInfo {
id: Hash<32>, id: Hash<32>,
} }
#[derive(Debug, PartialEq, Clone)]
pub struct ScriptContext { pub struct ScriptContext {
tx_info: TxInfo, tx_info: TxInfo,
purpose: ScriptPurpose, purpose: ScriptPurpose,
} }
//---- Time conversion: slot range => posix time range //---- Time conversion: slot range => posix time range
#[derive(Debug, PartialEq, Clone)]
struct TimeRange { struct TimeRange {
lower_bound: Option<u64>, lower_bound: Option<u64>,
upper_bound: Option<u64>, upper_bound: Option<u64>,
@ -800,22 +804,14 @@ fn slot_range_to_posix_time_range(slot_range: TimeRange, sc: &SlotConfig) -> Tim
fn get_tx_in_info( fn get_tx_in_info(
inputs: &MaybeIndefArray<TransactionInput>, inputs: &MaybeIndefArray<TransactionInput>,
utxos: &Vec<(TransactionInput, TransactionOutput)>, utxos: &MaybeIndefArray<TxInInfo>,
) -> anyhow::Result<MaybeIndefArray<TxInInfo>> { ) -> anyhow::Result<MaybeIndefArray<TxInInfo>> {
Ok(MaybeIndefArray::Indef( Ok(MaybeIndefArray::Indef(
inputs utxos
.iter() .iter()
.map(|input| { .filter(|utxo| inputs.contains(&utxo.out_ref))
let utxo = utxos.iter().find(|utxo| utxo.0 == *input); .map(|utxo| utxo.clone())
match utxo { .collect::<Vec<TxInInfo>>(),
Some(u) => TxInInfo {
out_ref: input.clone(),
resolved: u.1.clone(),
},
None => panic!(),
}
})
.collect(),
)) ))
} }
@ -892,7 +888,7 @@ fn get_script_purpose(
fn get_tx_info( fn get_tx_info(
tx: &Tx, tx: &Tx,
utxos: &Vec<(TransactionInput, TransactionOutput)>, utxos: &MaybeIndefArray<TxInInfo>,
slot_config: &SlotConfig, slot_config: &SlotConfig,
) -> anyhow::Result<TxInfo> { ) -> anyhow::Result<TxInfo> {
let body = tx.transaction_body.clone(); let body = tx.transaction_body.clone();
@ -962,7 +958,7 @@ fn get_tx_info(
fn get_script_context( fn get_script_context(
tx: &Tx, tx: &Tx,
utxos: &Vec<(TransactionInput, TransactionOutput)>, utxos: &MaybeIndefArray<TxInInfo>,
slot_config: &SlotConfig, slot_config: &SlotConfig,
redeemer: &Redeemer, redeemer: &Redeemer,
) -> anyhow::Result<ScriptContext> { ) -> anyhow::Result<ScriptContext> {