Exemple #1
0
def transfer_from(spender, holder, to, amount):
    # check if spender_address is tx sender
    if not IsValid(spender) or not IsValid(holder) or not IsValid(to):
        raise Exception("Address length error.")

    if GetTxSender() != spender:
        raise Exception("Please use the operator account.")

    if amount < 0:
        raise Exception("Please enter the correct amount.")

    # check allowance
    key = concat(concat(KEY_APPROVE, holder), spender)
    approved = Get(key)
    if approved < amount:
        raise Exception("The authorized amount is less than the account balance.")

    # check balance of holder
    if balance_of(holder) < amount:
        raise Exception("Insufficient balance.")


    # send token and update allowance
    TokenSend(holder, to, amount)
    if approved == amount:
        Delete(key)
    if approved > amount:
        Put(key, approved - amount)
    return True
def transfer(from_address, to_address, amount):
    # check if address freezing
    timestamp = GetTime()
    freeze_out_end = Get(concat(KEY_FREEZE_OUT, from_address))
    freeze_in_end = Get(concat(KEY_FREEZE_IN, to_address))
    if timestamp < freeze_out_end or timestamp < freeze_in_end:
        raise Exception("There is currently a frozen address.")

    #call StandardTokenContract transfer
    param = state('string:transfer', '[string:', from_address, 'string:',
                  to_address, 'int:', amount, ']')
    StandardTokenContract(param)
    return True
Exemple #3
0
def approve(holder, spender, amount):
    # check if holder_address is tx sender
    if not IsValid(holder) or not IsValid(spender):
        raise Exception("Address length error.")

    if GetTxSender() != holder:
        raise Exception("Please use the operator account.")
    if amount < 0:
        raise Exception("Please enter the correct amount.")

    key = concat(concat(KEY_APPROVE, holder), spender)
    Put(key, amount)
    return True
Exemple #4
0
def decrease_approval(holder, spender, subtracted):
    # check if holder_address is tx sender
    if not IsValid(holder) or not IsValid(spender):
        raise Exception("Address length error.")

    if GetTxSender() != holder:
        raise Exception("Please use the operator account.")
    if subtracted < 0:
        raise Exception("Please enter the correct amount.")

    amount = allowance(holder, spender) - subtracted
    if amount < 0:
        raise Exception("The amount to be reduced is greater than the current amount.")

    key = concat(concat(KEY_APPROVE, holder), spender)
    Put(key, amount)
    return True
def freeze_out(operator, address, end_time):
    # check if freeze disabled
    if not IsValid(operator) or not IsValid(address):
        raise Exception("Address length error.")

    if freeze_disabled():
        raise Exception("Currently disabled.")

    # check if operator is token owner
    if GetTxSender() != operator:
        raise Exception("Please use the operator account.")
    if operator != Get(KEY_OWNER):
        raise Exception("Please use the owner address.")

    Put(concat(KEY_FREEZE_OUT, address), end_time)
    return True
Exemple #6
0
def allowance(holder, spender):
    if not IsValid(holder) or not IsValid(spender):
        raise Exception("Address length error.")
    key = concat(concat(KEY_APPROVE, holder), spender)
    return Get(key)