Skip to content

Instantly share code, notes, and snippets.

@KardanovIR
Created May 13, 2020 15:32
Show Gist options
  • Save KardanovIR/d5e3fd610030313ea4275b2f4eab9ec6 to your computer and use it in GitHub Desktop.
Save KardanovIR/d5e3fd610030313ea4275b2f4eab9ec6 to your computer and use it in GitHub Desktop.
@Callable(i)
func takeReward(id: String) = {
if (keyIsDefined(id) == false) then throwIdError(id) else {
let paymentValue = getIntegerValue(this, keyPayment(id))
let oraclePubKey = i.callerPublicKey.toBase58String()
let oracleResponseKey = keyResponseFromOracle(id, oraclePubKey)
let oracleResponse = getStringValue(this, oracleResponseKey)
let resultKey = keyResult(id)
let resultDataEntry = getStringValue(this, resultKey)
let alreadyTookKey = keyTookPayment(id, oraclePubKey)
let alreadyTookPayment = getBooleanValue(this, alreadyTookKey)
let responsesCount = getResponsesCount(id)
if (oracleResponse == resultDataEntry && alreadyTookPayment == false) then {
let paymentAmount = paymentValue / responsesCount
[
BooleanEntry(alreadyTookKey, true),
ScriptTransfer(i.caller, paymentAmount, unit)
]
}else {
throw("Already took payment or provided data was not valid")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment