Hello everyone,
I have been diving into Plutus Smart Contracts lately and one of the main things that I would like to understand better is when and how to use the startWatching
function.
For example in guess game on available on the Playground
it is necessary for the person who’s guessing to run StartGame before the number is locked.
This is somewhat counter intuitive, and I had the following questions about the situation:
-
Is there anyway to just "extract" all funds from an address?
-
Why doesn't it know the outputs of the address of the game if used after lock?
-
Isn't this quite limiting in regards of what it is possible to achieve with Plutus smart contracts? What if a player only "knew" about the game after it was "locked"?
-
Wallet #1 (person who "locks" the number) still lost 1 ADA in this situation, where does that money go? Does it stay in the contract forever? (It's possible to use triggers, but that is still up to the programmer to do, which is suboptimal)
Thank you for your time!
I have also posted a similar post on reddit if anyone is interested
@Phantom_of_the_Opera
I believe the Game source code has been updated, I will try to answer some of these questions based on the new Game version and what I have been learning about Plutus and smart contracts:
What if a player only “knew” about the game after it was “locked”?
Someone needs to start the game and lock the guessing number, in this case is the “Wallet 1”.
But if anyone wants to participate in the game later on, it is possible to set a deadline in the future so anyone can join the game and play before that date.
So even though the number was already locked, as long your wallet has access to the “guess” endpoint and the deadline hasn’t passed you still can join and play the game.
The other questions seems to be related to old source code. Please take a look at the name code and let me know if I can help.
1 Like
@Phantom_of_the_Opera Please take a look at this answer I found at StackOverflow:
“When the emulator was implemented, there was no specification of the wallet capabilities that Plutus contracts can expect - in fact, one of the motivations for building the emulator was to help us write the specification. And it’s quite likely that the current, restrictive interface (forward-looking queries only) will be replaced by something more powerful so that the startGame
endpoint won’t be necessary anymore.”
1 Like
Yes, in the newer version startGame
is not necessary anymore.
(Regarding the lock situation)
I understand that there are workarounds, nevertheless programmers will eventually forget to include these clauses specially for circunstances where the logic is more elaborate and that can cause losses of ADA which is not desirable and it’s a vulnerability of the programming language.