3

I'm working through the week 4 homework for the Plutus Pioneer program. I've found an answer to the homework problem and now I'm trying to get a deeper understanding of the code. I've noticed that the payContract returns itself (I'm still learning Haskell so that terminology might not be correct).

I find that if I comment out this line of code, then the second invocation of callEndpoint doesn't do anything. I also notice that the logs of payTest1 say Contract Stopped:

Prelude Week04.Solution> payTest1
Slot 00000: TxnValidate 0636250aef275497b4f3807d661a299e34e53e5ad3bc1110e43d1f3420bc8fae
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Receive endpoint call on 'pay' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "pay")]),Object (fromList [("unEndpointValue",Object (fromList [("ppLovelace",Number 1000000.0),("ppRecipient",Object (fromList [("getPubKeyHash",String "977efb35ab621d39dbeb7274ec7795a34708ff4d25a01a1df04c1f27")]))]))])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W1: TxSubmit: 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance stopped (no errors)
Slot 00001: TxnValidate 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: SlotAdd Slot 2
Slot 00002: SlotAdd Slot 3
Slot 00003: SlotAdd Slot 4

I feel like I can intuit what Contract Stopped means but I'd like to understand on a more technical level what this means and under which conditions this happens.

2

The line of interest is:

pp <- endpoint @"pay"

Which is essentially blocking until someone hits the "pay" endpoint and then returning whatever PayParams the caller included (see PaySchema).

In the case where you include the recursive payContract function call, you are essentially saying, "after running payContract, wait for someone else to hit the "pay" endpoint."

In the case that the recursive payContract function call is removed, the Contract monad will exit, since it isn't blocked on any endpoints or anything.

Hope that helps :)

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.