validation/find
This module contains code for finding various aspects of
a validating transaction. Every function here fails with a descriptive
trace when nothing is found. For Option-returning lookups see stdlib’s
list.find, transaction.find_input, and pairs.get_first.
Functions
Find the first input’s output reference index.
Output references have the form TxId#Idx, this function
extracts the Idx part. If nothing is found then error.
find.first_input_index(tx.inputs)
Find the first input’s output reference transaction id hash.
Output references have the form TxId#Idx, this function
extracts the TxId part. If nothing is found then error.
find.first_input_txid(tx.inputs)
Find an input by an output reference. If nothing is found then error.
Similar to stdlib’s transaction.find_input but errors instead of
returning an Option, and to transaction.resolve_input but returns the
whole Input instead of its Output.
find.input_by_ref(tx.inputs, out_ref)
Find the first occurrence of an input by a specific address. If nothing is found then error. The address here is an exact match, so both the pkh and sc need to be correct.
find.input_by_addr(tx.reference_inputs, ref_addr)
Find the first occurrence of an output by a specific address. If nothing is found then error. The address here is an exact match.
find.output_by_addr(tx.outputs, your_address)
Find the first output with an inline datum and return the datum. If nothing is found then error. This works great for tx with a single output and datum or where ordering is irrelevant.
find.first_output_datum(tx.outputs)
Find the first occurrence of output datum by some address. If nothing is found then error.
expect datum: Datum = find.output_datum_by_addr(tx.outputs, this_addr)
Return the first occurrence of an output that contains at least some specific value at some address. If nothing is found then error. This function does not search for an exact UTxO match.
find.output_by_addr_value(tx.outputs, wallet_addr, just_token_value)
Return the first occurrence of an output that contains at least some specific value. If nothing is found then error. This function does not search for an exact UTxO match.
find.output_by_value(tx.outputs, just_token_value)
Find the staking reward amount in lovelace for some stake credential. If no rewards are available then error. This is a great method for checking on-chain staking rewards and withdrawal validation.
find.stake_reward_by_sc(tx.withdrawals, datum.wallet.sc)
Find a redeemer data by an output reference. This is good for checking if a specific redeemer is being used on some specific UTxO inside the transaction.
find.redeemer_by_ref(tx.redeemers, that_out_ref)
Find the inline datum on the first output that holds exactly one of a
specific token (see assets.has_nft). Fails if no output holds the token,
or if the first output holding it has no inline datum.
expect datum: Datum = find.output_datum_by_nft(tx.outputs, pid, tkn)