UPDATE
I was able to resolve my issue. It has nothing to do with the usage of ownPaymentPubKeyHash. As already correctly stated by others in this thread binding with the help of <-
ownPaymentPubKeyHash returns the type PaymentPubKeyHash.
The problem originated from unwrapping the datum incorrectly. And this was caused due to allowing two different types of datum at the script address using the pipe operator. Therefore, I needed to unwrap the datum twice.
My solution looks something like this now:
data ParentDatum = One ADatum | Two BDatum
-- Helper function
getParentDatum :: ChainIndexTxOut -> ParentDatum
getLotteryDatum o = case _ciTxOutDatum o of
Left _ -> traceError "unexpected datum"
Right (Datum d) -> do
let parsedDatum = PlutusTx.fromBuiltinData d :: Maybe ParentDatum
case parsedDatum of
Just s -> s
_ -> traceError "Unknown datum type"
-- inside the off-chain endpoint code
-- {...}
where
isSuitable :: PaymentPubKeyHash -> ChainIndexTxOut -> Bool
isSuitable pkh o = case getParentDatum o of
One ADatum{..} -> owner == pkh
Two BDatum{..} -> owner == pkh
_ -> traceError "Unhandled datum type"