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 getResult(id: String) = { | |
if (keyIsDefined(id) == false) then throwIdError(id) else { | |
let responsesCount = getResponsesCount(id) | |
let minResponsesCount = getMinResponsesCount(id) | |
if (responsesCount < minResponsesCount) then throw("Minimum oracles count not reached yet") else { | |
let result = calculateResult(id) | |
let ratingsDiff = getOracleRatingsDiff(id, result) | |
let resultKey = keyResult(id) | |
let resultDataEntry = StringEntry(resultKey, result) |
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) |
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 request(id: String, question: String, minResponsesCount: Int, maxResponsesCount: Int, oraclesWhiteList: String, tillHeight: Int) = { | |
let whiteList = checkOraclesWhiteListLengthLt1000(oraclesWhiteList) | |
let checkedRequestIdLt64 = checkRequestIdLt32(id) | |
let requestId = checkIdIsNotUsed(checkedRequestIdLt64) | |
let paymentAmount = checkPaymentInWavesGt0(i.payments[0].extract()) | |
let minCount = checkOraclesCountGt3Lt6(minResponsesCount, maxResponsesCount) | |
let maxCount = checkOraclesWhiteListCountGtMinCount(oraclesWhiteList, minCount, maxResponsesCount) | |
let callerPubKey = toBase58String(i.callerPublicKey) | |
[ |
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 registerAsOracle(dataType: String) = { | |
let neededKey = i.callerPublicKey.toBase58String() + "_" + dataType | |
let ratingKey = i.callerPublicKey.toBase58String() + "_rating" | |
let currentRating = match getInteger(this, ratingKey) { | |
case v: Int => v | |
case _ => 100 | |
} | |
match (getString(i.caller, neededKey)) { |
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
{-# STDLIB_VERSION 3 #-} | |
{-# CONTENT_TYPE EXPRESSION #-} | |
{-# SCRIPT_TYPE ACCOUNT #-} | |
# array of 5 public keys | |
let pks = [base58'', base58'', base58'', base58'', base58''] | |
# inner fold step for each signature | |
func signedBy(pk:ByteVector) = { | |
# is signed by the public key or not |
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
let NONE = "NONE" | |
func keyVoteByAddress(votingId: Int, address: String) = "voting_" + votingId + "_vote_" + address | |
@Callable(i) | |
func vote(id: Int) => { | |
let voteKey = keyVoteByAddress(id, i.caller.toBase58String()) | |
let vote = getString(this, voteKey).valueOrElse(NONE) |
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
func keyVoteByAddress(votingId: Int, address: String) = "voting_" + votingId + "_vote_" + address |
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 foo() = { | |
[StringEntry("foo", "bar")] | |
} | |
@Verifier(tx) | |
func verify = { | |
match (tx){ | |
case i: InvokeScriptTransaction => true | |
case _ => false |
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
{-# STDLIB_VERSION 3 #-} | |
{-# CONTENT_TYPE EXPRESSION #-} | |
{-# SCRIPT_TYPE ACCOUNT #-} | |
match (tx) { | |
case t:TransferTransaction => false | |
case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublikey) | |
} |
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
{-# STDLIB_VERSION 3 #-} | |
{-# CONTENT_TYPE EXPRESSION #-} | |
{-# SCRIPT_TYPE ACCOUNT #-} | |
match (tx) { | |
case t:TransferTransaction => false | |
case _ => true # NEVER DO THIS! | |
} |