Created
May 13, 2020 15:32
-
-
Save KardanovIR/d5e3fd610030313ea4275b2f4eab9ec6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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