Пример #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
Пример #2
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
Пример #3
0
def change_owner(operator, address):
    # check if operator is token owner
    if not IsValid(operator) or not IsValid(address):
        raise Exception("Address length error.")

    if GetTxSender() != operator:
        raise Exception("Please use the operator account.")
    if operator != Get(KEY_OWNER):
        raise Exception("Please use the owner address.")
    if operator == address:
        raise Exception("Old address and new address are the same.")

    Put(KEY_OWNER, address)
    return True
Пример #4
0
def transfer(from_address, to_address, amount):
    # check if from_address is tx sender
    if not IsValid(from_address) or not IsValid(to_address):
        raise Exception("Address length error.")
    if GetTxSender() != from_address:
        raise Exception("Please use the operator account.")
    if amount < 0:
        raise Exception("Please enter the correct amount.")
    # check balance of from_address
    if balance_of(from_address) < amount:
        raise Exception("Insufficient balance.")


    TokenSend(from_address, to_address, amount)
    return True
Пример #5
0
def change_owner(address):  # 改变 owner 地址
    if not IsValid(address):
        raise Exception("地址格式错误")
    if GetTxSender() != Get(KEY_OWNER):
        raise Exception("请使用 owner 地址调用")
    Put(KEY_OWNER, address)
    return True
Пример #6
0
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
Пример #7
0
def query_users_number_amount(sender_address, rd,
                              number):  # 根据该地址对应期数的用户投注号码,查询该号码的投注金额
    if not IsValid(sender_address):
        raise Exception("Incorrect address format.")
    amount_key = concat(concat(concat(rd, KEY_BETTING_AMOUNT), number),
                        sender_address)
    return Get(amount_key)
Пример #8
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
Пример #9
0
def mint(operator, to_address, amount):
    # check if mint disabled
    if not IsValid(operator) or not IsValid(to_address):
        raise Exception("Address length error.")
    if mint_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.")
    if amount < 0:
        raise Exception("Please enter the correct amount.")

    TokenAdd(to_address, amount)

    supply = Get(KEY_SUPPLY)
    Put(KEY_SUPPLY, supply + amount)
    return True
Пример #10
0
def describe(operator, info):
    # check if operator is token owner
    if not IsValid(operator):
        raise Exception("Address length error.")

    if GetTxSender() != operator:
        raise Exception("Please use the operator account.")
    if operator != Get(KEY_OWNER):
        raise Exception("Please use the owner address.")
    Put(KEY_DESCRIPTION, info)
    return True
Пример #11
0
def mint(to_address, amount, symbol):
    if not IsValid(to_address):
        raise Exception("地址长度不合规")

    if amount < 0:
        raise Exception("请输入正确的数量")

    sender = GetTxSender()
    owner = issue_owner(symbol)
    if owner != sender:
        raise Exception("请使用该积分的 owner 地址")
    AssetAdd(to_address, amount, symbol)

    return True
Пример #12
0
def query_user_time_condition(address):  # 查询是否距离最后一期,是否过去5秒
    if not IsValid(address):
        raise Exception("地址格式错误")

    stake_list = query_user_stake_list(address)
    if len(stake_list) == 0:
        return True

    last_period = stake_list[len(stake_list) - 1]  # 最后一期
    old_time = query_user_period_time(address, last_period)  # 最后一期的时间戳
    now_time = GetTime()
    if now_time - old_time > GAME_TIME_FOR_A_ROUND:
        return True

    return False
Пример #13
0
def disable_freeze(operator):
    # check if freeze disabled
    if not IsValid(operator):
        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(KEY_FREEZE_DISABLED, True)
    return True
Пример #14
0
def burn(to_address, amount, symbol):
    if not IsValid(to_address):
        raise Exception("地址长度不合规")

    balance = balance_of(to_address, symbol)
    if amount < 0:
        raise Exception("请输入正确的数量")

    if balance < amount:
        raise Exception("需要销毁的积分大于被销毁者持有积分")

    sender = GetTxSender()
    owner = issue_owner(symbol)
    if owner != sender:
        raise Exception("请使用该积分的 owner 地址")

    AssetSub(to_address, amount, symbol)

    return True
Пример #15
0
def query_user_if_prize(address, period):       # 查询用户指定的期数是否中奖
    if not IsValid(address):
        raise Exception("地址格式错误")

    prize_number = query_period_prize_number(period)      # 查询中奖号码
    user_info = query_user_stake(address, period)       # 查询用户得投注信息
    user_numbers = user_info[2]                         # 用户的投注号码
    mul = user_info[1]                                  # 用户的倍数
    if user_info[0] == "0" and prize_number == user_numbers:    # 散号
        amount = scatter_value_match(prize_number)
        return amount * int(mul)
    if user_info[0] == "1":  # 和值
        prize_sum = 0
        for i in range(len(prize_number)):
            prize_sum = int(prize_number[i]) + prize_sum
        if prize_sum == int(user_numbers):
            amount = sum_value_match(prize_number)
            return amount * int(mul)
    amount = 0
    return amount
Пример #16
0
def box_transfer(to_address):  # 存款盒子凭证交易
    if not IsValid(to_address):
        raise Exception("请填写正确的地址")
    sender = GetTxSender()
    if not transfer_on():
        raise Exception("不允许存款凭证交易")

    box_status = query_box_status()
    if box_status != LOCK_STATUS:
        raise Exception("当前不允许交易存款凭证")

    sender_deposit_amount = query_user_deposit_amount(sender)  # 用户的存款
    if not sender_deposit_amount or sender_deposit_amount == 0:
        raise Exception("当前用户没有存款,无法转让")

    sender_deposit_key = concat(KEY_USER_DEPOSIT_AMOUNT, sender)  # 转让人
    to_address_deposit_key = concat(KEY_USER_DEPOSIT_AMOUNT, to_address)  # 接收人
    Put(sender_deposit_key, 0)  # 提交转让人的额度变成 0
    Put(to_address_deposit_key, sender_deposit_amount)  # 提交接收人的额度

    return True
Пример #17
0
def burn(holder, amount):
    # check if burn disabled
    if not IsValid(holder):
        raise Exception("Address length error.")

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

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

    balance = balance_of(holder)
    if amount < 0:
        raise Exception("Please enter the correct amount.")

    if balance < amount:
        raise Exception("Insufficient balance.")

    TokenSub(holder, amount)

    supply = Get(KEY_SUPPLY)
    Put(KEY_SUPPLY, supply - amount)
    return True
Пример #18
0
def query_user_period_time(address, period):  # 查询用户期数的时间戳
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(concat(KEY_USER_PERIOD_TIME, address), period)
    return Get(key)
Пример #19
0
def query_user_stake_list(address):  # 查询用户的投注列表
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(KEY_USER_STAKE_LIST, address)
    return GetArray(key)
Пример #20
0
def query_user_stake_info(address, period):  # 查询用户详情
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(concat(KEY_USER_STAKE_INFO, address), period)
    return GetArray(key)
Пример #21
0
def query_my_inviter(sender_address):  # 查询该地址的上级邀请人
    if not IsValid(sender_address):
        raise Exception("Incorrect address format.")
    key = concat(KEY_INVITED_RECORD, sender_address)
    return Get(key)
Пример #22
0
def query_invitee(sender_address):  # 查询被该地址邀请的人
    if not IsValid(sender_address):
        raise Exception("Incorrect address format.")
    key = concat(KEY_INVITATION_RECORD, sender_address)
    return GetArray(key)
Пример #23
0
def query_user_invitation_code(sender):  # 查询地址查看生成的邀请码
    if not IsValid(sender):
        raise Exception("Incorrect address format.")
    key = concat(KEY_INVITATION_CODE, sender)
    return Get(key)
Пример #24
0
def get_redemption_information(sender_address, draws):  # 查询该地址对应期数的兑奖信息
    if not IsValid(sender_address):
        raise Exception("Incorrect address format.")
    key = concat(concat(KEY_REDEMPTION_USER, draws), sender_address)  # 兑奖信息
    return GetArray(key)
Пример #25
0
def query_users_number(sender_address, rd):  # 查询该地址对应期数,查询用户的所有投注号码
    if not IsValid(sender_address):
        raise Exception("Incorrect address format.")
    number_key = concat(concat(rd, KEY_BETTING_NUMBER), sender_address)
    return GetArray(number_key)  # 返回一个列表
Пример #26
0
def query_user_save_number(address, period):  # 查询用户保存的期号时的号码
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(concat(KEY_SAVE_NUMBER, address), period)
    return Get(key)
Пример #27
0
def query_period_type(address, period):  # 查询用户期数类型
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(concat(KEY_USER_PERIOD_TYPE, address), period)
    return Get(key)
Пример #28
0
def query_user_table_generation(address, period):  # 查询用户指定期数购买的表单,返回一个列表
    if not IsValid(address):
        raise Exception("请填写正确的地址格式")
    period_lottery_key = concat(concat(KEY_USER_LOTTERY, address), period)
    return GetArray(period_lottery_key)
Пример #29
0
def query_user_save_period(address):  # 查询用户保存的期号
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(KEY_SAVE_PERIOD, address)
    return GetArray(key)
Пример #30
0
def draw_rules(address, period):  # 中奖匹配规则
    if not IsValid(address):
        raise Exception("请填写正确的地址格式")

    numbers = query_user_grade(address, period)  # 因为用户标记的号码

    stake_table = query_user_table_generation(address, period)  # 用户购买的表单

    options = []
    for _option in range(5):
        options.append([])
    for t in range(len(stake_table)):
        if t <= 4:
            options[0].append(stake_table[t])  # B 横向五个
            continue
        if 4 < t <= 9:
            options[1].append(stake_table[t])  # I
            continue
        if 9 < t <= 14:
            options[2].append(stake_table[t])  # N
            continue
        if 14 < t <= 19:
            options[3].append(stake_table[t])  # G
            continue
        if 19 < t <= 24:
            options[4].append(stake_table[t])  # O
            continue
    op_l = []
    for _op in range(5):
        op_l.append([])

    for l in range(len(options)):
        op_l[0].append(options[l][0])  # 竖向五个
        op_l[1].append(options[l][1])
        op_l[2].append(options[l][2])
        op_l[3].append(options[l][3])
        op_l[4].append(options[l][4])

    op_r = []
    for _op in range(2):
        op_r.append([])

    for r in range(len(options)):  # 两个斜的一列
        op_r[0].append(options[r][r])
        op_r[1].append(options[r][len(options) - 1 - r])

    status = False
    for i in range(len(options)):
        l_n = 0
        for index in range(len(numbers)):
            if elt_in(options[i], numbers[index]):
                l_n = l_n + 1
        if l_n >= 5:
            status = True
            break

    for i in range(len(op_l)):
        l_n = 0
        for index in range(len(numbers)):
            if elt_in(op_l[i], numbers[index]):
                l_n = l_n + 1
        if l_n >= 5:
            status = True
            break

    for i in range(len(op_r)):
        l_n = 0
        for index in range(len(numbers)):
            if elt_in(op_r[i], numbers[index]):
                l_n = l_n + 1
        if l_n >= 5:
            status = True
            break

    call_list = query_period_call_number(period)  # 查询中奖叫号号码
    for i in range(len(numbers)):
        if not elt_in(call_list, numbers[i]):
            status = False

    return status