Exemplo n.º 1
0
    def claimUnits(self, uid, units_to_claim):
        storage_api = StorageApi()
        consume_type = storage_api.getValue(self.STORAGE_KEY_CONSUME_TYPE, uid)

        if consume_type == self.CONSUME_TYPE_TIME:
            Notify('error: you cant claim units for a time contract')
            return False

        current_units = storage_api.getValue(self.STORAGE_KEY_CURRENT_UNITS,
                                             uid)
        open_units = storage_api.getValue(self.STORAGE_KEY_OPEN_UNITS, uid)
        total_units = storage_api.getValue(self.STORAGE_KEY_TOTAL_UNITS, uid)

        if units_to_claim == 0:
            Notify('error: you cant claim 0 units')
            return False

        if units_to_claim > total_units:
            Notify('error: number of claimed units is higher than total units')
            return False

        claimable_units = total_units - current_units - open_units

        if units_to_claim > claimable_units:
            Notify(
                'error: number of claimed units is higher than available units'
            )
            return False

        open_units += units_to_claim
        storage_api.putValue(self.STORAGE_KEY_OPEN_UNITS, uid, open_units)

        return open_units
Exemplo n.º 2
0
def Main(operation):
    """

    :param operation:
    :return:
    """
    hash = GetExecutingScriptHash()

    Notify(hash)

    account = GetAccount(hash)

    print("account!")

    Notify(account)

    print("will get asset")
    asset = GetAsset(GAS)

    Notify(asset)

    print("will get balance")
    balance = GetBalance(account, GAS)

    Notify(balance)

    return operation
Exemplo n.º 3
0
def Main():
    """

    :return:
    """
    a = 4

    b = a << 2

    c = a >> 2

    print("shifted a!")

    Notify(b)

    Notify(c)

    m = 16

    m >>= 3

    q = 670

    q >>= 8

    Notify(m)

    if q == m:
        print("all ok!")

    else:
        print("not ok")

    return b
Exemplo n.º 4
0
def Main(a, b, c, d):
    """

    :param a:
    :param b:
    :param c:
    :param d:
    :return:
    """
    print("Executing Four Param Verification code")
    trigger = GetTrigger()

    if trigger == Verification():

        print("Running verification")
        is_owner = CheckWitness(OWNER)
        Notify(is_owner)
        return is_owner

    print("runnig app routine")

    result = a + b - c + d

    Notify(result)

    return result
Exemplo n.º 5
0
def Main():

    #    blockhash = b'\xe9F.\xbd\x83\x99\xb4\xa3Z\xdc\xdde\xe5^\xed\xf6\x9f\x82\xa3\x14\xc9y\x04\xb8\xfe\x8cb\xafO.\xe7\xd9'
    """

    :return:
    """

    print("hello?")
    block = GetCurrentBlock()

    index = block.Index
    print("hello")

    hash = block.Hash

    header = GetHeader(index)

    Notify(hash)

    Notify(header)

    Notify(header.Index)

    return index
def getAttachedAssets(receiver) -> Attachments:

    attachment = Attachments()
    tx = GetScriptContainer()
    references = tx.References
    attachment.receiver_addr = receiver

    if len(references) > 0:
        reference = references[0]
        attachment.sender_addr = reference.ScriptHash

        sent_amount_gas = 0

        for output in tx.Outputs:
            if output.AssetId != attachment.gas_asset_id:
                Notify('error: only gas please')
                return False

            if output.ScriptHash == receiver:
                sent_amount_gas += output.Value

            else:
                n = 0

        Notify(sent_amount_gas)
        attachment.gas_attached = sent_amount_gas

    return attachment
Exemplo n.º 7
0
def Main():
    """

    :return:
    """
    header = GetHeader(1234)

    m2 = header.Timestamp + header.Timestamp

    Notify(m2)

    bheight = 32

    block = GetBlock(bheight)

    Notify(block)

    tx = block.Transactions[0]

    Notify(tx.Hash)

    #    Notify(tx)
    #    tx = block.Transactions[0] #  this doesnt seem to work
    #    txhash = tx.Hash

    #    Notify(txhash)

    return 1
Exemplo n.º 8
0
def Main(a):

    storage = StorageAPI()

    storage.putitem('hello', 9)

    helloval = storage.getitem('hello')

    Notify(helloval)

    storage.deleteitem('hello')

    hval2 = storage.getitem('hello')

    Notify(hval2)

    # put it again
    storage.putitem('hello', 6)

    m = storage.getitem('hello')

    storage.putitem('h1', 2)
    storage.putitem('h2', 5)

    # this messes up the stack
    # res = storage.getitem('h1') + storage.getitem('h2')

    h1 = storage.getitem('h1')

    # this is ok?
    res = h1 + storage.getitem('h2')

    return res
Exemplo n.º 9
0
def CanWithdrawNeo():

    print("[can withdraw Neo]")

    tx = GetScriptContainer()
    context = GetContext()

    for output in tx.Outputs:
        shash = GetScriptHash(output)
        output_asset_id = GetAssetId(output)

        if output_asset_id == NEO_ASSET_ID:
            print("Asset is Neo")

        else:

            return False

    return True

    saved_timestamp = Get(context, "timestamp")

    Notify("saved_timestamp: ", saved_timestamp)

    current_timestamp = GetHeight()

    Notify("current_timestamp: ", current_timestamp)

    return current_timestamp > (saved_timestamp + 4)
Exemplo n.º 10
0
def Main():
    print("log via print (1)")
    Log("normal log (2)")
    Notify("notify (3)")

    # Sending multiple arguments as notify payload:
    msg = ["a", 1, 2, b"3"]
    Notify(msg)
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
0
def DoTransfer(sender, receiver, amount):
    """
    Method to transfer tokens from one account to another

    :param sender: the address to transfer from
    :type sender: bytearray

    :param receiver: the address to transfer to
    :type receiver: bytearray

    :param amount: the amount of tokens to transfer
    :type amount: int

    :return: whether the transfer was successful
    :rtype: bool

    """
    if amount <= 0:
        Notify("Cannot transfer negative amount")
        return False

    from_is_sender = CheckWitness(sender)

    if not from_is_sender:
        Notify("Not owner of funds to be transferred")
        return False

    if sender == receiver:
        Notify("Sending funds to self")
        return True

    context = GetContext()
    from_val = Get(context, sender)

    if from_val < amount:
        Notify("Insufficient funds to transfer")
        return False

    if from_val == amount:
        Delete(context, sender)

    else:
        difference = from_val - amount
        Put(context, sender, difference)

    to_value = Get(context, receiver)

    to_total = to_value + amount

    Put(context, receiver, to_total)
    DispatchTransferEvent(sender, receiver, amount)

    return True
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
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
Exemplo n.º 18
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
Exemplo n.º 19
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
Exemplo n.º 20
0
def ShouldRentQuery(renter_wallet_address, property_address):
    msg = concat("ShouldRentQuery: ", renter_wallet_address)
    Notify(msg)

    context = GetContext()
    renter = Get(context, renter_wallet_address)
    if not renter:
        Notify("Renter is not yet registered")
        return False
    else:
        renter = json.loads(renter)

    Notify(owner)
    return owner
Exemplo n.º 21
0
def QueryUser(query, user):
    """
    Query a user on the KRYPTON network

    :param query: type of query is UUID or provider
    :type query: str

    :param user: the public address of the user
    :type user: str

    :return: whether the query was successful
    :rtype: bool
    """

    context = GetContext()

    uuid = Get(context, user)

    if (uuid == 0):
        Log('QUERY_USER_FAILED')
        return False

    if (query == "uuid"):
        Notify(uuid)
        return True

    provider = Get(context, uuid)

    if (provider == 0):
        Log('QUERY_PROVIDER_FAILED')
        return False

    if (query == "provider"):
        Notify(provider)
        return True

    location = Get(context, provider)

    if (location == 0):
        Log('QUERY_LOCATION_FAILED')
        return False

    if (query == "location"):
        Notify(location)
        return True

    # User or data not found
    Log('QUERY_FAILED')
    return False
Exemplo n.º 22
0
def Main(operation, args):
    """

    :param operation: The name of the operation to perform
    :param args: A list of arguments along with the operation
    :type operation: str
    :type args: list
    :return: The result of the operation
    :rtype: bytearray
    """
    if operation == 'init':
        return do_init()
    elif operation == 'delete':
        return do_delete()
    elif operation == 'fetch':
        return do_fetch()
    elif operation == 'count':
        return do_count()
    elif operation == 'append_1':
        return do_append_1()
    elif operation == 'append_10':
        return do_append_10()
    else:
        Notify('unknown operation')
        return False
Exemplo n.º 23
0
def DeleteRenter(renter_wallet_address):
    msg = concat("DeleteRenter: ", renter_wallet_address)
    Notify(msg)

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

    if not CheckWitness(owner):
        Notify("Sender is not the owner, cannot transfer")
        return False

    Delete(context, renter_wallet_address)
    return True
Exemplo n.º 24
0
def get_asset_attachments() -> Attachments:

    attachment = Attachments()

    tx = GetScriptContainer()  # type:Transaction
    references = GetReferences(tx)
    attachment.receiver_addr = GetExecutingScriptHash()

    m = len(references)
    Notify(m)
    if len(references) > 0:

        reference = references[0]
        attachment.sender_addr = reference.ScriptHash

        sent_amount_neo = 0
        sent_amount_gas = 0
        for output in tx.Outputs:
            if output.ScriptHash == attachment.receiver_addr and output.AssetId == attachment.neo_asset_id:
                sent_amount_neo += output.Value

            if output.ScriptHash == attachment.receiver_addr and output.AssetId == attachment.gas_asset_id:
                sent_amount_gas += output.Value

        print("hello!")
        attachment.neo_attached = sent_amount_neo
        attachment.gas_attached = sent_amount_gas

    return attachment
Exemplo n.º 25
0
def crowdfunding_get_members(crowdfunding_address):
    storage = StorageAPI()

    crowdfunding_meta_key = storage.get_crowdfunding_members_key(
        crowdfunding_address)
    print(crowdfunding_meta_key)

    # Check if this address or crowdfunding_meta already exists
    addresses = storage.get(crowdfunding_meta_key)
    if len(addresses) == 0:
        print("Error: address does not belong to a crowdfunding")
        return False

    n = len(addresses)
    num_addresses = n / 20

    msg = ["Crowdfunding found. Members:", num_addresses]
    Notify(msg)

    address_list = []
    i = 0
    while i < num_addresses:
        addr = addresses[0:20]
        addresses = addresses[20:]
        address_list.append(addr)
        i += 1

    return address_list
Exemplo n.º 26
0
def Main(operation: str, args: list) -> bytearray:
    # Purpose of this contract is to demonstrate possible multi file structure. Hence there will be no documentations on its implementations.
    """
    Note:
        - Usage of static methods or properties are discouraged, due to unconventional syntax. You'll have better luck to instantiate classes when needed.
    """
    if operation == 'version':
        result = do_version()
        return result
    elif operation == 'magic_word':
        result = do_magic_word()
        return result
    elif operation == 'add':
        result = do_add(args)
        return result
    elif operation == 'get_count':
        result = do_get_count()
        return result
    elif operation == 'count_up':
        result = do_count_up()
        return result
    elif operation == 'count_down':
        result = do_count_down()
        return result
    err = ErrorResponse()
    Notify(err.unknown_operation)
    return False
Exemplo n.º 27
0
 def down(self) -> None:
     Notify('Counter.down triggered.')
     current_count = self.get()
     new_count = current_count - 1
     storage = Storage()
     storage.put(self.KEY, new_count)
     return None
Exemplo n.º 28
0
def Main():
    context = GetContext()
    Notify(context)

    item_key = 'hello'
    item_val = 123
    Notify(item_val)

    # Save the value to storage
    Put(context, item_key, item_val)

    # Read the key again
    out = Get(context, item_key)
    out = out + 10
    Notify(out)
    return out
Exemplo n.º 29
0
def Main():
    """

    :return:
    """
    start = 4
    stop = 9  # int

    #    out = [10,2, 3, 4, 6, 7]

    length = stop - start

    out = list(length=length)

    index = 0
    orig_start = start

    while start < stop:
        val = index + orig_start
        out[index] = val
        index = index + 1
        start = orig_start + index

        Notify(start)

        # d = stuff(1, 2) # this doesn't work at the moment

    return out[4]
Exemplo n.º 30
0
def RegisterFarm(Farm_name, owner):
    msg = concat("RegisterFarm: ", Farm_name)
    Notify(msg)

    if not CheckWitness(owner):
        Notify("Owner argument is not the same as the person who registered")
        return False

    context = GetContext()
    exists = Get(context, Farm_name)
    if exists:
        Notify("Farm is already registered")
        return False

    Put(context, Farm_name, owner)
    return True