validation/count
This module contains code to accurately count the number of inputs and outputs in a transaction containing an address or a datum.
Functions
Verify that the number of inputs with an inline datum or datum hash is equal to the number intended in the contract. The amount must be exactly the counter.
count.inputs_by_datum(tx.inputs, 1)
Count the number of inputs with a payment credential that is a script. This does not take in an address but is a general count of validator hashes.
count.inputs_by_vkh(tx.inputs, 1)
Count the number of outputs with a payment credential that is a script. This does not take in an address but is a general count of validator hashes.
count.outputs_by_vkh(tx.outputs, 1)
Verify that the number of inputs from a specific script is equal to the amount intended in the contract. The amount must be exactly the counter.
count.inputs_by_addr(tx.inputs, this_addr, 1)
Verify that the number of outputs from a specific script is equal the amount intended in the contract. The amount must be exact with the counter.
count.outputs_by_addr(tx.outputs, this_addr, 1)
Verify that the number of outputs with an inline datum or datum hash is equal to the number intended in the contract. The amount must be exactly the counter.
count.outputs_by_datum(tx.outputs, 1)
single_input_with_bypass(
inputs: List<Input>,
this_addr: Address,
those_addrs: List<Address>,
) -> Bool
The contract can only be spent by itself or along side some list of known script addresses. Loop all the inputs and count how many are locked by this address’s script. Script inputs belonging to any of those addresses are passed over, but any other script input fails the check. Wallet inputs are always allowed. The check passes when exactly one input belongs to this address. This should prevent unregulated contracts from being spent along side this script.
Addresses are compared by payment credential only, so stake credentials are ignored. Datums are ignored too: since Plutus V3 a script output can be spent without any datum, so the presence of a datum says nothing about whether an input is a script input.
count.single_input_with_bypass(this_tx.inputs, this_addr, [that_addr])