I need to get only one UTxO from the script address, where its datum hash matches the redeemer hash. For example I have locked two UTxO with 10 Ada and the DatumHash "house" at the script and only want to unlock one of them.
I use the guessing game example of the Plutus Playground, but it unlocks both UTxO when the Redeemer has the same hash:
guess = endpoint @"guess" @GuessParams $ \(GuessParams theGuess) -> do
-- Wait for script to have a UTxO of a least 1 lovelace
utxos <- fundsAtAddressGeq gameAddress (Ada.lovelaceValueOf 1)
let redeemer = clearString theGuess
tx = collectFromScript utxos redeemer
let hashedSecretWord = findSecretWordValue utxos
isCorrectSecretWord = fmap (`isGoodGuess` redeemer) hashedSecretWord == Just
void (submitTxConstraintsSpending gameInstance utxos tx)
-- | Find the secret word in the Datum of the UTxOs
findSecretWordValue :: Map TxOutRef ChainIndexTxOut -> Maybe HashedString
findSecretWordValue =
listToMaybe . catMaybes . Map.elems . Map.map secretWordValue
-- | Extract the secret word in the Datum of a given transaction output is possible
secretWordValue :: ChainIndexTxOut -> Maybe HashedString
secretWordValue o = do
Datum d <- either (const Nothing) Just (_ciTxOutDatum o)
PlutusTx.fromBuiltinData d
At which part do I have to change the code, so it only unlocks one UTxO (best case: a random choice of both)?