diff --git a/ride4dapps/fomo.ride b/ride4dapps/fomo.ride index 65fd9ab..2b92d0a 100644 --- a/ride4dapps/fomo.ride +++ b/ride4dapps/fomo.ride @@ -1,3 +1,7 @@ +# FOMO - Fear of missing out - is a game +# users send Waves to the FOMO account. each payment has to be bigger than the previous one +# if there are no payments in the last 24 hours, the last transaction owner can withdraw the full bank + {-# STDLIB_VERSION 3 #-} {-# CONTENT_TYPE DAPP #-} {-# SCRIPT_TYPE ACCOUNT #-} @@ -9,23 +13,25 @@ let day = 1440 @Callable(i) func fearmissing() = { - let payment = match i.payment { - case p:AttachedPayment => + # this function can be used by anyone to place a bet + # user has to attach a Waves payment to the script invokation + let payment = match i.payment { + case p:AttachedPayment => match p.assetId { - case assetId: ByteVector => throw("fomo waves only") + case assetId: ByteVector => throw("fomo waves only") # waves-only threshold case _ => p.amount } - - case _ => throw("payment must be attached") - } - let lastPayment = match getInteger(this, "lastPayment") { + case _ => throw("payment must be attached") + } + + let lastPayment = match getInteger(this, "lastPayment") { # reading the last payment value from the FOMO account state case p:Int => p case _ => 0 } if(payment <= lastPayment) - then throw("min payment is " +toString(payment)) - else # storing best payment, caller and height + then throw("min payment is " +toString(lastPayment)) # the new payment must be bigger than the previous one + else # storing best payment, caller and actual blockchain height WriteSet([ DataEntry(lpKey, payment), DataEntry(liKey, i.caller.bytes), @@ -35,11 +41,12 @@ func fearmissing() = { @Callable(i) func withdraw() = { - let callerCorrect = i.caller.bytes == extract(getBinary(this, liKey)) - let heightCorrect = extract(getInteger(this, lhKey)) - height >= day - let canWithdraw = heightCorrect && callerCorrect + # this function is used by the FOMO winner to withdraw the full balance + let callerCorrect = i.caller.bytes == extract(getBinary(this, liKey)) # is caller the winner? + let heightCorrect = extract(getInteger(this, lhKey)) - height >= day # are there no more bets in the last 24 hours? + let canWithdraw = heightCorrect && callerCorrect # are both variables true? if (canWithdraw) - then TransferSet([ScriptTransfer(i.caller, wavesBalance(this), unit)]) - else throw("behold") + then TransferSet([ScriptTransfer(i.caller, wavesBalance(this), unit)]) # send full balance to the winner + else throw("This user can not withdraw the balance in this moment") }