Example #1
0
def GetKey(key):
    msg = concat("Get key: ", key)
    Log(msg)

    #get key
    context = GetContext()
    data = Get(context, key)
    msg = concat("Data found: ", data)
    Log(msg)
    return data
Example #2
0
def add_to_circulation(amount):
    """
    Adds an amount of tokens to add to the circulation.

    :param amount:int The amount of tokens to add to the total circulation.
    """
    context = GetContext()
    current_supply = Get(context,in_circulation_key)
    current_supply += amount
    Put(context,in_circulation_key,current_supply)
Example #3
0
def balance_of(address):
    """
    Query the LOOT balance of an address.

    :param address:str The address to query the balance of.
    :return:
        int: The balance of the given address.
    """
    context = GetContext()
    balance = Get(context, address)
    return balance
Example #4
0
def sale_amount_remaining():
    """
    The amount of tokens that are left for the sale.

    :return:
        int: The number of tokens left for sale.
    """
    context = GetContext()
    in_circulation = Get(context,in_circulation_key)
    available = total_supply - in_circulation
    return available
Example #5
0
def kyc_status(address):
    """
    Get the KYC status of an address.

    :param address: str An address to check if KYC registered.
    :return:
        bool: The kyc status of an address.
    """
    context = GetContext()
    kyc_storage_key = concat(kyc_key, address)
    return Get(context, kyc_storage_key)
Example #6
0
def DepositNeo():

    # get reference to the tx the invocation is in
    tx = GetScriptContainer()

    references = tx.References

    if len(references) < 1:
        print("no neo attached")
        return False

    # we need to determine who sent the tx
    reference = references[0]
    sender = GetScriptHash(reference)

    # this will keep track of how much neo was deposited
    value = 0

    # this is the contract's address
    receiver = GetExecutingScriptHash()

    # go through all the outputs
    # and check if the receiver is the contract
    # if that is true, we add the value of the output to the
    # total sum that was deposited

    for output in tx.Outputs:
        shash = GetScriptHash(output)
        if shash == receiver:

            output_asset_id = GetAssetId(output)

            if output_asset_id == NEO_ASSET_ID:

                output_val = GetValue(output)
                value = value + output_val

    if value > 0:

        # now we know value was deposited from the sender

        # check the current balance of the sender
        # add it to the deposit amount, and save
        context = GetContext()
        current_balance = Get(context, sender)
        new_balance = current_balance + value
        Put(context, sender, new_balance)

        # send deposit event
        onDeposit(sender, value)

        return True

    return False
Example #7
0
def ResultNotice(agreement_key, weather_param, oracle_cost):
    """
    Method to signal resulte by oracle

    :param agreement_key: the key of the agreement
    :type agreement_key: bytearray

    :param weather_param: weather parameter that the contract is depending on
    :type weather_param: int

    :param oracle_cost: costs made by the oracle to do this assignment
    :type oracle_cost: int

    :return: whether a pay out to the customer is done
    :rtype: bool
    """

    # Check if the method is triggered by the oracle for this agreement
    context = GetContext()
    agreement_data = Get(context, agreement_key)
    oracle = agreement_data[8]

    if not CheckWitness(oracle):
        Log("Must be oracle to notice results")
        return False

    timestamp = agreement_data[3]
    utc_offset = agreement_data[4]
    status = agreement_data[12]

    if not status == 'initialized':
        Log("Contract has incorrect status to do a result notice")
        return False

    agreement_data[12] = 'result-noticed'
    agreement_data[13] = weather_param
    agreement_data[14] = oracle_cost

    # Get timestamp of current block
    currentHeight = GetHeight()
    currentBlock = GetHeader(currentHeight)
    current_time = currentBlock.Timestamp

    Put(context, agreement_key, agreement_data)

    timezone_timestamp = timestamp + (3600 * utc_offset)
    timezone_current_time = current_time + (3600 * utc_offset)

    if timezone_current_time < timezone_timestamp:
        Log("Datetime of result notice is lower than agreed datetime")
        return False
    else:
        DispatchResultNoticeEvent(agreement_key, weather_param, oracle_cost)
        return True
Example #8
0
def put_cert(domain, cert):
    curr_domains = Get(GetContext, "all_domains")
    if curr_domains:
        Delete(GetContext, "all_domains")
        curr_domains = concat(curr_domains, ",")
        new_curr_domains = concat(curr_domains, domain)
        Put(GetContext, "all_domains", new_curr_domains)
    else:
        Put(GetContext, "all_domains", domain)
    Put(GetContext, domain, cert)
    return "ok" 
Example #9
0
def init_license(license_id) -> License:
    serialized_license_data = Get(GetContext, license_id)
    license_data = deserialize_bytearray(serialized_license_data)

    license = License()

    license.owner = license_data[0]
    license.expir = license_data[1]
    license.product_id = license_data[2]

    return license
Example #10
0
def isGameInstanceJudged(game_type, instance_ts):
    k1 = concat(key_prefix_game_type, game_type)
    k2 = concat(key_prefix_game_instance, instance_ts)
    k12 = concat(k1, k2)
    key = concat(k12, key_prefix_game_instance_judged)
    context = GetContext()
    v = Get(context, key)
    if v == 0:
        return False
    else:
        return True
Example #11
0
def do_count():
    """
    Fetch length of the stored list.

    :return: the stored list value
    :rtype: int
    """
    context = GetContext()
    list_bytes = Get(context, KEY)
    item_list = deserialize_bytearray(list_bytes)
    return len(item_list)
def _change_owner(uuid, new_owner_address):
    context = GetContext()
    product_data_get = Get(context, uuid)
    if not len(product_data_get) == 0:
        obj = _data_unpacking(product_data)
        obj = [new_owner_address, obj[1], obj[2]]

        product_data = _data_packing(obj)
        Put(context, uuid, product_data)

    return False
Example #13
0
 def betOnOutcome(self, ipfsHash: bytes, outcome: int, amount: int, owner: bytes, contractAddress: bytes):
     #check if witness
     isvoter = CheckWitness(owner)
     if not isvoter:
         #print('Must be voter to vote for outcome')
         return False
     
     #check if event ended
     ctx = GetContext()
     keyEndTime = concat(b'EndTime', ipfsHash)
     endTime = Get(ctx, keyEndTime)
     now = self.now()
     isendTime = (now > endTime)
     if isendTime:
         #print('Event has ended')
         return False
     
     #deposit
     isok = self.deposit(owner, contractAddress, amount)
     
     if not isok:
         #print('Deposit Failed')
         return False
     
     keyOutcomeAmountT = concat(owner, ipfsHash)
     keyOutcomeAmount = concat(outcome, keyOutcomeAmountT)
     outcomeAmount = Get(ctx, keyOutcomeAmount)
     outcomeAmount = outcomeAmount + amount
     Put(ctx, keyOutcomeAmount, outcomeAmount)
     
     keyTotalOutcomeAmounts = concat(outcome, ipfsHash)
     totalOutcomeAmounts = Get(ctx, keyTotalOutcomeAmounts)
     totalOutcomeAmounts = totalOutcomeAmounts + amount
     Put(ctx, keyTotalOutcomeAmounts, totalOutcomeAmounts)
     
     keyTotalAmount = concat(b'TotalAmount', ipfsHash)
     totalAmount = Get(ctx, keyTotalAmount)
     totalAmount = totalAmount + amount
     Put(ctx, keyTotalAmount, totalAmount)
     
     return True
Example #14
0
def IncrementCount(prediction_name, normalised_timestamp, price, context):
    k0 = concat("prediction_count", prediction_name)
    k1 = concat(k0, normalised_timestamp)
    k2 = concat(k1, price)
    count = Get(context, k2)
    if count == 0:
        Put(context, k2, 1)
        return 1
    else:
        count = count + 1
        Put(context, k2, count)
        return count
Example #15
0
def QueryRenter(renter_wallet_address):
    msg = concat("QueryRenter: ", renter_wallet_address)
    Notify(msg)

    context = GetContext()
    owner = Get(context, renter_wallet_address)
    if not owner:
        Notify("Renter is not yet registered")
        return False

    Notify(owner)
    return owner
Example #16
0
def get_kyc_status(ctx, address):
    """
    Looks up the KYC status of an address

    :param address:bytearray The address to lookup
    :param storage:StorageAPI A StorageAPI object for storage interaction
    :return:
        bool: KYC Status of address
    """
    kyc_storage_key = concat(KYC_KEY, address)

    return Get(ctx, kyc_storage_key)
Example #17
0
def isOracleRegisteredForInstance(game_type, instance_ts, oracle):
    k1 = concat(key_prefix_game_type, game_type)
    k2 = concat(key_prefix_game_instance, instance_ts)
    k12 = concat(k1, k2)
    k4 = concat(key_prefix_game_instance_oracle, oracle)
    key = concat(k12, k4)
    context = GetContext()
    v = Get(context, key)
    if v == 0:
        return False
    else:
        return True
def RetrieveTracking(block_id_tracking):
    msg = concat("Retrieving Tracking Number for Block: ", block_id_tracking)
    Notify(msg)

    context = GetContext()
    tracking = Get(context, block_id_tracking)
    if not tracking:
        Notify("No Tracking Stored for Block")
        return False

    Notify(tracking)
    return tracking
def RetrieveAddressList(organization_name):
    msg = concat("Retrieving Address List: ", organization_name)
    Notify(msg)

    context = GetContext()
    list_addr = Get(context, organization_name)
    if not list_addr:
        Notify("No Addresses Stored")
        return False

    Notify(list_addr)
    return list_addr
def RetrieveBlock(block_id):
    msg = concat("Retrieving Block: ", block_id)
    Notify(msg)

    context = GetContext()
    block = Get(context, block_id)
    if not block:
        Notify("No Block with given ID")
        return False

    Notify(block)
    return block
Example #21
0
def QueryBuyer(Buyer_name):
    msg = concat("QueryBuyer: ", Buyer_name)
    Notify(msg)

    context = GetContext()
    owner = Get(context, Buyer_name)
    if not owner:
        Notify("This Buyer is not yet registered")
        return False

    Notify(owner)
    return owner
Example #22
0
def QueryFarm(Farm_name):
    msg = concat("QueryFarm: ", Farm_name)
    Notify(msg)

    context = GetContext()
    owner = Get(context, Farm_name)
    if not owner:
        Notify("This farm is not yet registered")
        return False

    Notify(owner)
    return owner
Example #23
0
def QueryDomain(domain_name):
    msg = concat("QueryDomain: ", domain_name)
    Notify(msg)

    context = GetContext()
    owner = Get(context, domain_name)
    if not owner:
        Notify("Domain is not yet registered")
        return False

    Notify(owner)
    return owner
Example #24
0
def Main(method, args):
    if method == "test":
        return test()

    if method == "deploy":
        return Deploy()

    if not Grow():
        return False

    if method == "name":
        return Name

    if method == "symbol":
        return Symbol

    if method == "decimals":
        return Decimals

    if method == "totalSupply":
        context = GetContext()
        return Get(context, "supply")

    if method == "balanceOf":
        addr = args[0]
        return GetBalance(addr)

    if method == "transfer":
        addr_from = args[0]
        addr_to = args[1]
        amount = args[2]
        return Transfer(addr_from, addr_to, amount)

    if method == "transferFromPool":
        addr_to = args[0]
        amount = args[1]
        return TransferFromPool(addr_to, amount)

    if method == "postGeo":
        addr = args[0]
        geolocation = args[1]
        timestamp = args[2]
        return PostGeolocation(addr, geolocation, timestamp)

    if method == "requestGeo":
        addr = args[0]
        nBlocks = args[1]
        return RequestGeolocations(addr, nBlocks)

    if method == "requestTicket":
        addr = args[0]
        nBlocks = args[1]
        return RequestTicket(addr, nBlocks)
Example #25
0
    def redeemWinnings(self, ID: bytes, owner: bytes):
        isFinalOutcomeSet = self.isFinalOutcomeSet(ID)
        if not isFinalOutcomeSet:
            #print('Oracle is not ended yet!')
            return False
        ctx = GetContext()
        finalOutcome = self.getFinalOutcome(ID)

        keyTotalAmount = concat(b'TotalAmount', ID)
        totalAmount = Get(ctx, keyTotalAmount)

        keyOutcomeAmountT = concat(owner, ID)
        keyOutcomeAmount = concat(finalOutcome, keyOutcomeAmountT)
        ownerAmount = Get(ctx, keyOutcomeAmount)

        keyTotalOutcomeAmounts = concat(finalOutcome, ID)
        frontRunnerAmount = Get(ctx, keyTotalOutcomeAmounts)

        amount = (totalAmount * ownerAmount) / frontRunnerAmount

        return amount
Example #26
0
def testAll():
    Put(GetContext, 'original', 1)

    amount = Get(GetContext, 'original')
    amount += 20

    Put(GetContext, 'original', amount)
    Put(GetContext, 'copy', amount)

    Delete(GetContext, 'copy')

    copy = Get(GetContext, 'copy')
    original = Get(GetContext, 'original')

    Put(GetContext, 'storeString', 'this is a string')
    storeString = Get(GetContext, 'storeString')

    test = [original, copy, amount, storeString]
    Notify(test)

    return original
Example #27
0
def StoreKey(key, value):
    msg = concat("StoreKey: ", key)
    Log(msg)

    #store value
    context = GetContext()
    exists = Get(context, key)
    if exists:
        Notify("KEY is already registered")
        return False

    Put(context, key, value)
    return key
Example #28
0
def Main(op, k, v):
    return_val = -999
    context = GetContext()

    # With opcode 1, we create a new itemID, and mark our first repair
    if (op == 1):
        Put(context, k, v)
        return_val = k
        print(k)
    # With opcode 2, we can get the repairs for a given item
    elif (op == 2):
        v = Get(context, k)
        return_val = v
    # With opcode 3, we can append another repair to a given item
    elif (op == 3):
        o = Get(context, k)
        n = concat(o, ";")
        n = concat(n, v)
        Put(context, k, n)
        return_val = n

    return return_val
Example #29
0
def IsPromoExist(promo_id):
    """
    Check if promo identified by promo_id already exists

    Args:
        promo_id (str): promo unique id

    Returns:
        (bool): True if promo_id already exists in storage
    """
    context = GetContext()
    promo_exists = Get(context, promo_id)
    return promo_exists
Example #30
0
def Review(milestone_key, review_score):
    """
    Method to signal result by SC owner or oracle

    :param milestone_key: the key of the milestone
    :type milestone_key: bytearray

    :param review_score: score that the reviewer assigned to this milestone
    :type review_score: int

    :return: whether a pay out to the assignee is done
    :rtype: bool
    """
    # Check if the method is triggered by the SC owner or oracle
    context = GetContext()
    milestone_data_serialized = Get(context, milestone_key)
    milestone_data = deserialize_bytearray(milestone_data_serialized)
    oracle = milestone_data[6]

    if not CheckWitness(OWNER) and not CheckWitness(oracle):
        Notify("Must be SC owner or oracle to submit review")
        return False

    status = milestone_data[11]

    if not status == 'initialized':
        Notify("Contract has incorrect status to do a review")
        return False

    elif status == 'refunded':
        Notify("Contract is already refunded")
        return False

    milestone_data[11] = 'reviewed'
    milestone_data[12] = review_score
    assignee = milestone_data[2]
    threshold = milestone_data[10]
    pay_out = milestone_data[7]

    # Update storage
    Delete(context, milestone_key)
    milestone_data_serialized = serialize_array(milestone_data)
    Put(context, milestone_key, milestone_data_serialized)
    DispatchReviewEvent(milestone_key, review_score)

    if review_score >= threshold:
        Notify("Review score was above threshold, processing pay out")
        DoTransfer(OWNER, assignee, pay_out)
        DispatchTransferEvent(OWNER, assignee, pay_out)

    return True