assist/find
This module contains code for finding various aspects of a validating transaction.
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)
first_output_datum(outputs: List<Output>) -> Data
Find the first output with an inline datum and return the data. 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)
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)
input_by_nft(inputs: List<Input>, pid: PolicyId, tkn: AssetName) -> Input
Find the first occurance of an inline datum on an output with a value that contains a specific nft.
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 the builtin function in stdlib but auto errors instead of
returning an Option
.
find.input_by_ref(tx.inputs, out_ref)
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)
output_by_addr_value(
outputs: List<Output>,
addr: Address,
value: Value,
) -> 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: Value) -> 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)
output_datum_by_addr(outputs: List<Output>, addr: Address) -> Data
Find the first occurence 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_datum_by_nft(
outputs: List<Output>,
pid: PolicyId,
tkn: AssetName,
) -> Data
Find the first occurance of an inline datum on an output with a value that contains a specific nft.
redeemer_by_ref(
redeemers: Dict<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)
stake_reward_by_sc(
withdraws: Dict<StakeCredential, Int>,
stake_credential: StakeCredential,
) -> Int
Find the staking reward amount in loveace 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)