Skip to content

Instantly share code, notes, and snippets.

View KardanovIR's full-sized avatar
🥸
Focusing

Inal Kardanov KardanovIR

🥸
Focusing
View GitHub Profile
func keyVoteByAddress(votingId: Int, address: String) = "voting_" + votingId + "_vote_" + address
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)
{-# 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
@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)) {
@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 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 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 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)
const adminSeed = '...';
const issueTx = issue({
name: `Thanks`,
description: 'Say thank you to all of your teammates in Slack. By Billy.',
decimals: 0,
quantity: 100000000,
reissuable: false
}, adminSeed);
await broadcast(issueTx);
{-# STDLIB_VERSION 4 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
let adminPublicKey = base58'...'
func addToWhiteList(address: String) = {
let userInTheList = getBoolean(this, address)
let newValue = match userInTheList {