user6170: I managed to get the homework transactions to work as expected (happy), so far so good...
I also tried the following scenario which did not work.
Q1: Why doesn't it work?
Q2: How would it be possible to make it work!
wallet 1: give 20 Ada
wait 1
wallet 2: grab false/true
wait 1
wallet 2: grab true/true
wait 1
As expected, the first grab is not handled, as it evaluates false
But the second grab is also not handled ?
The logtrace shows:
Slot 3: 00000000-0000-4000-8000-000000000002 {Wallet Wc30e}:
No requests handled ]
Why isn't it possible for the same wallet to "correct" its previous mistake and try again with acceptible parameters ?


user6113: Your scenario fails because the way off-chain code was implemented: Once on-chain grab validation fails, the off-chain caller grab fails and the execution finishes. Why? - Because off-chain code is not handling errors.
How to make it work? - Replace function endpoint with these 2 functions.
endpoints :: AsContractError e => Contract () GiftSchema e ()
endpoints = handleError handler (selectList [give', grab']) >> endpoints
  where
    give' = endpoint @"give" give
    grab' = endpoint @"grab" grab

handler :: AsContractError e => e -> Contract w s e ()
handler _ = logError @String "an error occurred"

Note: If I'm not wrong, in lecture 4 Lars talks about error handling in off-chain code.

6170: <p>I managed to get the homework transactions to work as expected (<em>happy</em>), so far so good...</p>
<p>I also tried the following scenario which did not work.</p>
<p><strong>Q1: Why doesn't it work?</strong></p>
<p><strong>Q2: How would it be possible to make it work!</strong></p>
<p>wallet 1: give 20 Ada
wait 1
wallet 2: grab false/true
wait 1
wallet 2: grab true/true
wait 1</p>
<p>As expected, the first grab is not handled, as it evaluates false
But the second grab is also not handled ?
The logtrace shows:</p>
<p><em>Slot 3: 00000000-0000-4000-8000-000000000002 {Wallet Wc30e}:
No requests handled ]</em></p>
<p>Why isn't it possible for the same wallet to &quot;correct&quot; its previous mistake and try again with acceptible parameters ?</p>
<p><a href="https://i.stack.imgur.com/6N34g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6N34g.png" alt="playground actions resluting in no grab" /></a></p>
 6113: <p>Your scenario fails because the way off-chain code was implemented: Once on-chain grab validation fails, the off-chain caller grab fails and the execution finishes. Why? - Because off-chain code is not handling errors.</p>
<p>How to make it work? - Replace function <code>endpoint</code> with these 2 functions.</p>
<pre><code>endpoints :: AsContractError e =&gt; Contract () GiftSchema e ()
endpoints = handleError handler (selectList [give', grab']) &gt;&gt; endpoints
  where
    give' = endpoint @&quot;give&quot; give
    grab' = endpoint @&quot;grab&quot; grab

handler :: AsContractError e =&gt; e -&gt; Contract w s e ()
handler _ = logError @String &quot;an error occurred&quot;
</code></pre>
<p>Note: If I'm not wrong, in lecture 4 Lars talks about error handling in off-chain code.</p>
