Created
May 13, 2020 15:30
-
-
Save KardanovIR/0e3256a5bcde5ea77b2b38fa5409b132 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 response(id: String, data: String) = { | |
# Step 0 is validity check for provided data | |
let requestId = checkIdExists(id) | |
let checkedData = checkDataIllegalCharacters(data) | |
# Step 1 is checking the query state (the number of replies at this point) | |
let currentResponsesCount = getResponsesCount(id) | |
let newResponsesCount = checkNewResponsesCount(currentResponsesCount, id) | |
# Step 2 is checking if the oracle is whitelisted and if it has already replied to the query | |
let oraclePubKey = i.callerPublicKey.toBase58String() | |
let oracleIsAllowed = checkOracleInWhiteList(oraclePubKey, id) == true || checkOracleResponded(oraclePubKey, id) == false | |
let maxHeight = getIntegerValue(this, keyTillHeight(id)) | |
let isDone = getBooleanValue(this, keyRequestIsDone(id)) == true | |
let requestIsActive = maxHeight > height || isDone | |
if (oracleIsAllowed == false) then throw("Oracle is not in the white list or already responded") else | |
if (requestIsActive == false) then throw("Request is not active anymore due to max height (" + maxHeight.toString() + "/" + height.toString() + ") or it is just done (" + isDone.toString() + ")") | |
else { | |
let currentResponders = getResponders(id) | |
let currentResponses = getResponses(id) | |
let newResponders = if currentResponders == "" then oraclePubKey | |
else currentResponders + ";" + oraclePubKey | |
let newResponses = if currentResponses == "" then checkedData | |
else currentResponses + ";" + checkedData | |
let currentResponsePoints = getCurrentResponsePoints(id, checkedData) | |
let oracleRating = getOracleRating(oraclePubKey) | |
let newResponsePoint = currentResponsePoints + if oracleRating < 200 then oracleRating / 3 else log(oracleRating, 0, 8, 0, 5, HALFEVEN) | |
[ | |
IntegerEntry(keyCurrentResponsePoints(requestId, checkedData), newResponsePoint), | |
IntegerEntry(keyResponsesCount(requestId), newResponsesCount), | |
StringEntry(keyResponseFromOracle(requestId, oraclePubKey), checkedData), | |
StringEntry(keyResponders(requestId), newResponders), | |
StringEntry(keyResponses(requestId), newResponses), | |
BooleanEntry(keyTookPayment(requestId, oraclePubKey), false), | |
# StringEntry(keyOneResponse(requestId, i, checkedData), newResponders),newResponsePoint) | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment