aiken_design_patterns/stake_validator
This pattern allows for delegating some computations to a given staking script.
The primary application for this is the so-called “withdraw zero trick,” which is most effective for validators that need to go over multiple inputs.
With a minimal spending logic (which is executed for each UTxO), and an arbitrary withdrawal logic (which is executed only once), a much more optimized script can be implemented.
Functions
validate_withdraw(
withdraw_script_hash: ScriptHash,
redeemers: Pairs<ScriptPurpose, Redeemer>,
withdraw_redeemer_index: Int,
withdraw_redeemer_validator: fn(Redeemer) -> Bool,
) -> Bool
Helper function for implementing validation for spending UTxOs, essentially delegating their requirements to the given withdrawal validator.
In simpler terms, it says: As long as there is a redeemer with a withdrawal purpose, for the given script in transaction, this UTxO can be spent.
Allows you to validate based on the withdrawal’s redeemer, which ismostly useful for ensuring specific endpoints are invoked.
validate_withdraw_with_amount(
withdraw_script_hash: ScriptHash,
redeemers: Pairs<ScriptPurpose, Redeemer>,
withdraw_redeemer_index: Int,
withdrawals: Pairs<Credential, Lovelace>,
withdrawal_index: Int,
withdraw_redeemer_validator: fn(Redeemer, Lovelace) -> Bool,
) -> Bool
Similar to validate_withdraw, but with the
additional steps for extracting the withdrawal amount from the withdrawals
field.
validate_withdraw_minimal(
withdraw_script_hash: ScriptHash,
withdrawals: Pairs<Credential, Lovelace>,
withdrawal_index: Int,
) -> Bool
A more minimal version of validate_withdraw, where
only the presence of a given staking script is checked, regardless of
withdraw amount or redeemer.