Skip to content

Instantly share code, notes, and snippets.

@KardanovIR
Created June 9, 2020 14:01
Show Gist options
  • Save KardanovIR/d790ce7aef1ca3691ad148e0ef8abb00 to your computer and use it in GitHub Desktop.
Save KardanovIR/d790ce7aef1ca3691ad148e0ef8abb00 to your computer and use it in GitHub Desktop.
@Callable(i)
func refundUser(id: Int) = {
# receiving campaign parameters
let endTimestamp = getIntegerValue(this, keyEndTimestamp(id))
let targetSum = getIntegerValue(this, keyTargetSum(id))
let raised = getIntegerValue(this, keyRaised(id))
# receiving the number of tokens sent by the current investor
let fundedAmount = getIntegerValue(this, keyUserFunded(id, i.callerPublicKey.toBase58String()))
# making sure that the campaign end date has already passed
if (endTimestamp > lastBlock.timestamp) then throw("This target time is not finished yet") else
# making sure that the target campaign sum has NOT been collected
if (raised > targetSum) then throw("This target raised enough tokens") else
# making sure that the current investor supported the campaign
if (fundedAmount == 0) then throw("You have no power here") else
[
# turning the total number of tokens from the current investor to zero
IntegerEntry(keyUserFunded(id, i.callerPublicKey.toBase58String()), 0)
# returning tokens to the investor
ScriptTransfer(i.caller, fundedAmount, thanksTokenId)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment