Skip to content

Instantly share code, notes, and snippets.

View KardanovIR's full-sized avatar
🥸
Focusing

Inal Kardanov KardanovIR

🥸
Focusing
View GitHub Profile
@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)
@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)
@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)
[
@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)) {
{-# 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
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)
func keyVoteByAddress(votingId: Int, address: String) = "voting_" + votingId + "_vote_" + address
@Callable(i)
func foo() = {
[StringEntry("foo", "bar")]
}
@Verifier(tx)
func verify = {
match (tx){
case i: InvokeScriptTransaction => true
case _ => false
{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE EXPRESSION #-}
{-# SCRIPT_TYPE ACCOUNT #-}
match (tx) {
case t:TransferTransaction => false
case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublikey)
}
{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE EXPRESSION #-}
{-# SCRIPT_TYPE ACCOUNT #-}
match (tx) {
case t:TransferTransaction => false
case _ => true # NEVER DO THIS!
}