Skip to content

Instantly share code, notes, and snippets.

@KardanovIR
Created June 9, 2020 13:53
Show Gist options
  • Save KardanovIR/6cac3bd83e72d1eefa672042f9aa5b1e to your computer and use it in GitHub Desktop.
Save KardanovIR/6cac3bd83e72d1eefa672042f9aa5b1e to your computer and use it in GitHub Desktop.
@Callable(i)
func startFunding(id: Int, fundraisingEndTimestamp: Int, implmenetationEndTimestamp: Int, targetSum: Int) = {
# current time
let lastBlockTimestamp = lastBlock.timestamp
# The campaign end cannot be less than 60 seconds
if (fundraisingEndTimestamp - lastBlockTimestamp - 60 < 0) then throw("End time should at least 60 seconds more than the last block time") else
# The campaign end time cannot be less than the project execution time
if (implmenetationEndTimestamp < fundraisingEndTimestamp) then throw("Implementation end time should more or equal to endTimestamp") else
# Campaign ID has to be unique
if (isDefined(getInteger(this, keyFunding(id)))) then throw("Funding with the same ID already exists") else
# Minimum token amount for collection is 1000
if (targetSum < 1000) then throw("You cannot fundraise less than 1000 tokens")
else {
let fundingPrefix = "funding_" + id.toString()
[
# saving the height at which the campaign began
IntegerEntry(fundingPrefix, height),
# saving the campaign end time
IntegerEntry(fundingPrefix + "_timestamp", fundraisingEndTimestamp),
# saving the project execution tim
IntegerEntry(fundingPrefix + "_impl_timestamp", implmenetationEndTimestamp),
# saving the amount of collected tokens for the campaign to be successful
IntegerEntry(fundingPrefix + "_targetSum", targetSum),
# creating a key in which the current number of collected tokens will be held and put 0 as the starting value
IntegerEntry(fundingPrefix + "_raised", 0),
# creating a key in which the number of votes confirming that the project has been executed and put 0 as the starting value
IntegerEntry(fundingPrefix + "_release_votes", 0),
# saving the campaign initiator’s private key (in the form of a line for easy reading in the explorer)
StringEntry(fundingPrefix + "_owner", i.callerPublicKey.toBase58String(),
# creating a key in which we will store data on whether the campaign initiator has received their tokens after the voting and put false as the starting value
BooleanEntry(keyReleasedTokens(id), false)
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment