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

first_input_index(inputs: List<Input>) -> Int

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)

first_input_txid(inputs: List<Input>) -> ByteArray

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)

input_by_ref(inputs: List<Input>, out_ref: OutputReference) -> Input

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)

input_by_addr(inputs: List<Input>, addr: Address) -> Input

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)

output_by_addr(outputs: List<Output>, addr: Address) -> Output

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)

first_output_datum(outputs: List<Output>) -> Data

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)

output_datum_by_addr(outputs: List<Output>, addr: Address) -> Data

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)

output_by_addr_value(
  outputs: List<Output>,
  addr: Address,
  value: Assets,
) -> Output

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)

output_by_value(outputs: List<Output>, value: Assets) -> Output

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)

stake_reward_by_sc(
  withdraws: Pairs<Credential, Int>,
  stake_credential: Credential,
) -> Int

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)

redeemer_by_ref(
  redeemers: Pairs<ScriptPurpose, Redeemer>,
  out_ref: OutputReference,
) -> Data

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)

output_datum_by_nft(
  outputs: List<Output>,
  pid: PolicyId,
  tkn: AssetName,
) -> Data

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)

input_by_nft(inputs: List<Input>, pid: PolicyId, tkn: AssetName) -> Input

Find the first input that holds exactly one of a specific token (see assets.has_nft). If nothing is found then error.

find.input_by_nft(tx.inputs, pid, tkn)
Search Document