3

re: https://plutus.readthedocs.io/en/latest/plutus/tutorials/basic-apps.html

Given that the explanation is ""The validator checks that the transaction, represented by scriptContextTxInfo, pays half the specified amount to each recipient.", why does the code not simply use ==half in both cases?

validateSplit :: SplitData -> () -> ScriptContext -> Bool
validateSplit SplitData{recipient1, recipient2, amount} _ ScriptContext{scriptContextTxInfo} =
    let half = Ada.divide amount 2 in
    Ada.fromValue (valuePaidTo scriptContextTxInfo recipient1) >= half &&
    Ada.fromValue (valuePaidTo scriptContextTxInfo recipient2) >= (amount - half)```
2

Ada is an integer under the hood and divide rounds down.

So, if amount is 5, half would be 2 and (amount - half) would be 3 (totaling to 5).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.