Does the validator need to check that the transaction sees that pkh?
Yes. There is more than one way to organize the logic though.
Whichever way you structure the lottery, I will assume that the winnings are owned by the script. Any transaction that spends UTxOs owned by the script need to meet the qualifications of the validator.
As you say, one way to construct the smart contract would be to make sure you mustPayToPubkey
of the winner. The validator would then need to guarantee that the output of the "pay out winnings" transaction includes the winnings and they are going to the winner's pkh. This wouldn't use txSignedBy
, but rather do some combination of checks to guarantee the winnings are going to the correct pkh.
The way I would suggest modelling it is by saying only the winner can claim the winnings. In that case you could use txSignedBy
.
This approach is similar to how the vesting example works in the PPP. It doesn't use txSignedBy
, but rather just checks that the beneficiary is among the signers, essentially doing the same thing.
You don't even need to specify mustPayToPubKey
at that point because it will default to the transaction builder's wallet. See the vesting example's grab constraints.