form.lang.1.5.7.source-code.fomo.ride Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lang Show documentation
Show all versions of lang Show documentation
The RIDE smart contract language compiler
The newest version!
{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP -#}
let lpKey = "lastPayment"
let liKey = "bestFomoer"
let lhKey = "height"
let day = 1440
@Callable(i)
func fearmissing() = {
let payment = match i.payment {
case p:AttachedPayment =>
match p.asset {
case asset: ByteVector => throw("fomo waves only")
case _ => p.amount
}
case _ => throw("payment must be attached")
}
let lastPayment = match getInteger(this, "lastPayment") {
case p:Int => p
case _ => 0
}
if(payment <= lastPayment)
then throw("min payment is " +toString(payment))
else # storing best payment, caller and height
WriteSet([
DataEntry(lpKey, payment),
DataEntry(liKey, i.caller.bytes),
DataEntry(lhKey, height)
])
}
@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
if (canWithdraw)
then TransferSet([ScriptTransfer(i.caller, wavesBalance(this), unit)])
else throw("behold")
}