Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fomo.ride #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions ride4dapps/fomo.ride
Original file line number Diff line number Diff line change
@@ -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 #-}
Expand All @@ -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),
Expand All @@ -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")
}