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
spend(
withdraw_script_hash: ScriptHash,
withdraw_redeemer_validator: fn(Redeemer, Lovelace) -> Bool,
tx: Transaction,
) -> 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 reward withdrawal of the given script in transaction, this UTxO can be spent.
Allows you to validate based on both the withdrawal’s redeemer (mostly useful for ensuring specific endpoints are invoked), and the withdrawal Lovelace count.
A more minimal version of spend
, where only the withdrawals
field is traversed, and no other validations are performed.
withdraw(
withdrawal_logic: fn(a, ScriptHash, Transaction) -> Bool,
redeemer: a,
stake_cred: Credential,
tx: Transaction,
) -> Bool
Function to be used under your withdrawal endpoint. The only convenience
this function provides is that it’ll provide you with the ScriptHash
of
your withdrawal script, so that you don’t have to unwrap it yourself.