Esempio n. 1
0
def stake(game_type, operation_type):  # 用户购买
    sender = GetTxSender()
    user_list = emoji_random()  # 随机表情列表
    period = get_period_generation()  # 当期期号

    if query_user_time_condition(sender):  # 查询是否过去5秒
        stake_info_key = concat(concat(KEY_USER_STAKE_INFO, sender), period)
        PutArray(stake_info_key, user_list)  # Put 用户购买后产生的列表

        # Put 用户的投注列表,最多保持24个记录
        stake_list = query_user_stake_list(sender)
        stake_list_key = concat(KEY_USER_STAKE_LIST, sender)
        if len(stake_list) == 0:
            PutArray(stake_list_key, [period])
        if len(stake_list) == 24:
            new_stake_list = []
            for i in range(len(stake_list)):
                if i != len(stake_list) - 1:
                    new_stake_list.append(stake_list[i + 1])
            new_stake_list.append(period)
            PutArray(stake_list_key, new_stake_list)
        else:
            new_stake_list = []
            for i in range(len(stake_list)):
                new_stake_list.append(stake_list[i])
            new_stake_list.append(period)
            PutArray(stake_list_key, new_stake_list)

        period_type_key = concat(concat(KEY_USER_PERIOD_TYPE, sender), period)
        Put(period_type_key, game_type)  # Put 用户当期期数的类型,即表情包
        amount = 200 * GARD_FACTOR

        if BalanceOf(sender, [GARD_DENOM])[0] < amount:
            raise Exception("余额不足")

        inject_stake_pool(amount)  # 给合约地址转钱
        add_user_stake_amount(sender, amount)  # 加入自己的消费额中
        time = GetTime()
        period_time_key = concat(concat(KEY_USER_PERIOD_TIME, sender), period)
        Put(period_time_key, time)  # Put 用户期数的时间戳

        save_period_key = concat(KEY_SAVE_PERIOD, sender)
        if operation_type == 1:  # 1为 直接stake
            save_period_key = concat(KEY_SAVE_PERIOD, sender)
            PutArray(save_period_key, [])  # 把用户保存的表清空
        if operation_type != 1:  # 0 为继续
            save_period_list = GetArray(save_period_key)  # 查询用户保存的期号列表
            if len(save_period_list) == 0:
                raise Exception("当期不是继续的场景")

        return True
    else:
        raise Exception("请等待时间")
def get_periods_exceeds(address, rd):  # 返回一个一天内的投注列表
    stake_all_key = concat(KEY_MY_ALL_STAKE, address)  # 我所有的投注期号记录,只记录三天以内的
    stake_all_value = GetArray(stake_all_key)  # 期数列表
    now_time = GetTime()
    list = []
    for i in range(len(stake_all_value)):
        time = query_periods_time(stake_all_value[i])  # 根据期数查询时间戳
        sub = now_time - time
        if rd != stake_all_value[i] and 0 < sub <= 60 * 60 * 24 * 1:  # 小于1天和不重复的
            list.append(stake_all_value[i])
    list.append(rd)
    return list
Esempio n. 3
0
def save(number):  # 用户保存号码
    sender = GetTxSender()
    numbers = split(number, "-")
    stake_list = query_user_stake_list(sender)  # 查询用户的投注列表
    if len(stake_list) == 0:
        raise Exception("当期用户没有投注")

    last_stake = stake_list[len(stake_list) - 1]

    old_time = query_user_period_time(sender, last_stake)  # 最后一期的时间戳
    now_time = GetTime()
    if now_time - old_time > 30:
        raise Exception("当期已经过了时间,无法标记")

    last_stake_info = query_user_stake_info(sender, last_stake)  # 查询用户该期的表单

    if numbers[0] != numbers[1]:
        raise Exception("标记的不是同一个")
    num = 0
    for i in range(len(last_stake_info)):
        if last_stake_info[i] == numbers[0]:
            num = num + 1
    if num < 2:
        raise Exception("标记的号码在表情中未出现两次")

    save_num_key = concat(concat(KEY_SAVE_NUMBER, sender), last_stake)
    Put(save_num_key, number)  # 存取用户保存的号码

    save_period_key = concat(KEY_SAVE_PERIOD, sender)
    save_period = GetArray(save_period_key)

    new_save = []
    if len(save_period) != 0:
        for i in range(len(save_period)):
            new_save.append(save_period[i])
    new_save.append(last_stake)
    PutArray(save_period_key, new_save)  # 存取用户保存的期号

    return True
Esempio n. 4
0
def query_withdraw_info(period):        # 查询该期的兑奖人信息
    withdraw_info_key = concat(KEY_GAME_WITHDRAW_INFO, period)
    return GetArray(withdraw_info_key)
Esempio n. 5
0
def get_promotion_reward(address):  # 查询推广奖励
    sr_key = concat(KEY_SHARED_REWARD, address)
    return GetArray(sr_key)  # 我的推广奖励,我被推广的奖励
Esempio n. 6
0
def query_user_stake_list(address):  # 查询用户的投注列表
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(KEY_USER_STAKE_LIST, address)
    return GetArray(key)
Esempio n. 7
0
def query_user_save_period(address):  # 查询用户保存的期号
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(KEY_SAVE_PERIOD, address)
    return GetArray(key)
Esempio n. 8
0
def query_issue_account():  # 查询累计中奖额度信息
    return GetArray(KEY_ISSUE_ACCOUNT)
Esempio n. 9
0
def query_periods_list():  # 查询所有的期数列表,仅显示24个
    return GetArray(KEY_PERIODS_LIST)
Esempio n. 10
0
def lastissue():  # 最后一期期数
    last_draw = GetArray(KEY_LAST_NUMBER_DRAWS)
    return last_draw
Esempio n. 11
0
def get_stake_account(address):  # 我的投注统计
    stake_count_key = concat(KEY_MY_STAKE_COUNT, address)
    return GetArray(stake_count_key)
Esempio n. 12
0
def stake(multiple):  # 用户购买卡单
    if multiple != 1 and multiple != 2 and multiple != 5 and multiple != 10:
        raise Exception("只支持一倍,两倍,五倍,十倍")

    sender = GetTxSender()  # 当前用户

    if BalanceOf(sender, [GARD_DENOM])[0] < 200 * GARD_FACTOR:
        raise Exception("当前余额不足购买")

    now_time = GetTime()

    if not issue():  # 如果当期没有期数
        period = get_period_generation()
        Put(KEY_GAME_PERIOD, period)  # Put 初始的期号
        pid_key = concat(KEY_GAME_PID, period)
        Put(pid_key, get_peroid_pid())  # Put 初始期号的 pid
        time_key = concat(KEY_ISSUE_TIME, period)
        Put(time_key, now_time)  # Put 初始的时间戳

    if if_update_period():  # 已经过了五分钟 返回 true
        period = get_period_generation()  # 新的期号
        Put(KEY_GAME_PERIOD, period)  # Put 新的期号
        now_pid = get_peroid_pid()  # 当前 pid
        pid_key = concat(KEY_GAME_PID, period)
        Put(pid_key, now_pid)  # Put 新的期号的pid
        time_key = concat(KEY_ISSUE_TIME, period)
        Put(time_key, now_time)  # Put 新的期号的时间戳

    now_period = Get(KEY_GAME_PERIOD)  # 当前期

    table_generation = get_table_generation()  # 获取表格
    period_lottery_key = concat(concat(KEY_USER_LOTTERY, sender), now_period)
    user_table = query_user_table_generation(sender, now_period)
    if len(user_table) > 0:
        raise Exception("当期已经买过卡单")

    PutArray(period_lottery_key, table_generation)  # 如果没有购买过,则提交当前表单

    stake_key = concat(KEY_USER_STAKE, sender)
    stake_list = GetArray(stake_key)  # 查询用户的投注列表

    ls = []
    if len(stake_list) == 0:
        ls.append(now_period)
    if len(stake_list) == 24:
        for i in range(len(stake_list)):
            if i != len(stake_list) - 1:
                ls.append(stake_list[i + 1])
        ls.append(now_period)
    if 0 < len(stake_list) < 24:
        for i in range(len(stake_list)):
            ls.append(stake_list[i])
        ls.append(now_period)

    PutArray(stake_key, ls)  # 只记录用户的24期

    stake_amount = stakepool()
    if not stake_amount:
        Put(KEY_STAKE_POOL, 200 * GARD_FACTOR)
    else:
        stake_amount = stake_amount + 200 * GARD_FACTOR
        Put(KEY_STAKE_POOL, stake_amount)  # put 投注池子

    multiple_key = concat(concat(KEY_MULTIPLE, sender), now_period)  # 用户该期的倍数

    Put(multiple_key, multiple)

    call_numbers = query_period_call_number(now_period)  # 返回一个列表, 查询本期的叫号列表
    call_number_key = concat(KEY_GAME_PERIOD_CALL_NUMBER, now_period)
    if len(call_numbers) == 0:
        PutArray(call_number_key, call_number())  # Put 本期的叫号号码

    amount = multiple * 200 * GARD_FACTOR
    stake_amount_key = concat(KEY_USER_STAKE_AMOUNT, sender)
    user_stake_amount = query_user_stake_amount(sender)
    if not user_stake_amount:
        Put(stake_amount_key, amount)  # Put 用户总共购买过的金额
    else:
        user_stake_amount = user_stake_amount + amount
        Put(stake_amount_key, user_stake_amount)

    user_multiple_key = concat(concat(KEY_USER_ISSUE_MULTIPLE, sender), now_period)  # 用户当期购买的倍数
    Put(user_multiple_key, multiple)

    ContractBalanceInject(sender, GARD_DENOM, amount)  # 每次投注花费200个gard

    return True
Esempio n. 13
0
def query_user_grade(address, period):  # 查询该期用户的标记号码
    key = concat(concat(KEY_USER_GRADE, address), period)
    return GetArray(key)
Esempio n. 14
0
def query_period_call_number(period):  # 查询期数的叫号号码
    call_number_key = concat(KEY_GAME_PERIOD_CALL_NUMBER, period)
    return GetArray(call_number_key)  # 返回一个列表
Esempio n. 15
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)
Esempio n. 16
0
def query_user_stake(address):
    if not IsValid(address):
        raise Exception("请填写正确的地址格式")
    key = concat(KEY_USER_STAKE, address)
    return GetArray(key)  # 查询用户的投注期数, 返回一个列表
Esempio n. 17
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)
Esempio n. 18
0
def stake(number, amount, invitation_code):  # 用户投注
    if len(number) != 3:
        raise Exception("请输入正确的投注号码")
    if amount < 10000 * GARD_FACTOR:
        raise Exception("每次投注不能少于 10000gard")
    if if_lottery():
        raise Exception('当前期已经结束,处于开奖期,前往开奖')

    sender_address = GetTxSender()  # 当前调用地址
    if BalanceOf(sender_address, [GARD_DENOM])[0] < 10000 * GARD_FACTOR:
        raise Exception("账户余额不足投注")

    now_time = GetTime()  # 当前时间
    rd = Get(KEY_NUMBER_DRAWS)  # 当前期数
    user_bets_key = concat(concat(KEY_USER_BETS, sender_address), rd)  # 用户投注次数
    user_bets = Get(user_bets_key)

    if not user_bets:
        Put(user_bets_key, 1)
    else:
        if user_bets >= 3:
            raise Exception("当前用户投注次数超过三次")
        else:
            Put(user_bets_key, user_bets + 1)

    now_user_pool = stakepool()  # 当前用户池额度
    if not now_user_pool:
        Put(KEY_USER_POOL, amount)
    else:
        Put(KEY_USER_POOL, amount + now_user_pool)  # 添加入总的用户池额度

    now_issue_stakepool = query_issue_stakepool(rd)
    issue_stakepool_key = concat(rd, KEY_USER_POOL)  # 当期的用户池总额度
    if now_issue_stakepool > 0:
        Put(issue_stakepool_key, now_issue_stakepool + amount)
    else:
        Put(issue_stakepool_key, amount)

    note_key = concat(rd, KEY_CALUCLATION_NOTE)
    num_note = Get(note_key)  # 获取投注数
    now_note = num_note + 1  # 每个用户投注一次,次数增加一次
    Put(note_key, now_note)  # 记录每一期的总的投注数
    # 投注数每次都增加,避免出现一个过大的列表

    betting_record_key = concat(concat(KEY_NUMBER_BETS_PEER_ISSUE, rd),
                                str(now_note))  # 每一期的投注记录 key

    user_info = [str(now_time), sender_address, number, str(amount)]  # 保存为一个数组
    Assert(user_info[3] == str(amount), "erro")  # 输出address
    PutArray(betting_record_key, user_info)  # 记录投注记录

    number_key = concat(concat(rd, KEY_BETTING_NUMBER),
                        sender_address)  # 用户的投注号码
    amount_key = concat(concat(concat(rd, KEY_BETTING_AMOUNT), number),
                        sender_address)  # 记录用户投注的金额
    stake_all_key = concat(KEY_MY_ALL_STAKE,
                           sender_address)  # 我所有的投注记录,只记录三天以内的

    stake_list = GetArray(stake_all_key)
    if len(stake_list) == 0:
        ls = []
        ls.append(rd)
        PutArray(stake_all_key, ls)  # 记录我的投注记录期号
    else:
        periods_exceeds_list = get_periods_exceeds(sender_address,
                                                   rd)  # 返回去掉一天外的数组
        PutArray(stake_all_key, periods_exceeds_list)

    numbers = GetArray(number_key)
    if len(numbers) == 0:
        PutArray(number_key, [number])  # 记录用户的投注号码
        Put(amount_key, amount)  # 记录用户对这个号码的投注金额
    else:
        ls = []
        existed = False
        for i in range(len(numbers)):
            ls.append(numbers[i])
            if numbers[i] == number:
                balance = query_users_number_amount(sender_address, rd, number)
                balance_amount = balance + amount
                Put(amount_key, balance_amount)
                existed = True
        if not existed:
            ls.append(number)
            PutArray(number_key, ls)
            Put(amount_key, amount)  # 记录用户对这个号码的投注金额

    invited_key = concat(KEY_INVITED_RECORD, sender_address)  # 被邀请记录
    invited = Get(invited_key)
    invitation_user = query_invitation_code_user(invitation_code)  # 生成邀请码的地址
    invitation_key = concat(KEY_INVITATION_RECORD, invitation_user)  # 上级邀请记录
    if len(
            invitation_code
    ) == 4 and not invited and invitation_user and invitation_user != sender_address:
        Put(invited_key, invitation_user)  # 提交被邀请记录
        invitation_list_value = GetArray(invitation_key)
        invitation_list = []
        for i in range(len(invitation_list_value)):
            invitation_list.append(invitation_list_value[i])
        invitation_list.append(sender_address)
        PutArray(invitation_key,
                 invitation_list)  # 提交邀请人的邀请记录,由于可以邀请很多人,所有是个列表

    stake_count_key = concat(
        KEY_MY_STAKE_COUNT,
        sender_address)  # 我的投注统计,包括投注的总 token,和获取奖励的总 token
    count_value = GetArray(stake_count_key)
    if len(count_value) == 0:
        PutArray(stake_count_key, [str(amount), str(0)])
    if len(count_value) == 2:
        betting_amount = int(count_value[0])  # 总共投注
        reward_amount = int(count_value[1])  # 获得奖励
        PutArray(stake_count_key,
                 [str(betting_amount + amount),
                  str(reward_amount)])  # 提交自己投注记录

    ContractBalanceInject(sender_address, GARD_DENOM, amount)
    return True
Esempio n. 19
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)
Esempio n. 20
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)  # 返回一个列表
Esempio n. 21
0
def get_stake_issue(address):  # 我的投注列表
    stake_all_key = concat(KEY_MY_ALL_STAKE, address)
    return GetArray(stake_all_key)  # 期数列表
Esempio n. 22
0
def query_draws_lottery_user(draws):  # 根据期数,查询开奖人的记录
    draws_lettry_key = concat(KEY_LOTTERY_USER, draws)
    return GetArray(draws_lettry_key)
Esempio n. 23
0
def query_withdraw_account(rd):  # 查询指定期数的中奖额度信息
    withdraw_account_key = concat(KEY_ISSUE_ACCOUNT, rd)
    return GetArray(withdraw_account_key)
Esempio n. 24
0
def query_bets_note(draws, notes):  # 返回对应期数和对应注数的信息
    betting_record_key = concat(concat(KEY_NUMBER_BETS_PEER_ISSUE, draws),
                                notes)
    betting_info = GetArray(betting_record_key)
    return betting_info
Esempio n. 25
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)
Esempio n. 26
0
def query_user_stake(address, period):   # 返回用户对于该期的投注详情,[投注方式(散,和),号码,金额]
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(concat(KEY_USER_STAKE, address), period)
    return GetArray(key)  # 返回用户投注信息,列表
Esempio n. 27
0
def query_user_stake_list(address):         # 返回用户投注的期数列表
    if not IsValid(address):
        raise Exception("地址格式错误")

    key = concat(KEY_USER_ISSUE, address)
    return GetArray(key)
Esempio n. 28
0
def withdraw(draws):  # 根据期数兑奖
    sender = GetTxSender()
    now_draws = Get(KEY_NUMBER_DRAWS)  # 当前期数
    time = GetTime()  # 当前时间
    last_number = GetArray(KEY_LAST_NUMBER_DRAWS)

    if query_user_withdraw_status(draws, sender):
        raise Exception("当期已经兑过奖")

    if len(last_number) == 0:
        raise Exception("当前期还无法兑奖")
    last_draws_time = int(last_number[1])  # 最后一期时间
    if int(draws) >= int(now_draws):
        raise Exception("当前期无法兑奖")

    if len(query_users_number(sender, draws)) == 0:
        raise Exception("当前期数没有投注")

    if time - last_draws_time >= 60 * 60 * 24 * 1:  # 计算是否超过一天
        raise Exception("当前已经超过一天未兑奖,无法兑现")

    amount_award_list = query_amount_award(draws)  # 查询每一期的中奖额度信息
    lottery_sys_pool = int(amount_award_list[0])  # 开奖时的系统池额度
    lottery_users_pool = int(amount_award_list[1])  # 开奖时的用户池额度
    fist_pool_amount = int(amount_award_list[2])  # 开奖时候的一等奖额度
    second_pool_amount = int(amount_award_list[3])  # 开奖时候的二等奖额度
    thrid_pool_amount = int(amount_award_list[4])  # 开奖时候的三等奖额度

    numbers = query_users_number(sender, draws)  # 用户投注的所有号码
    withdraws_all_amount = 0  # 应该获取到的所有奖金额度
    user_pool_amount = 0  # 应该要减去的用户奖池额度
    sys_pool_amount = 0  # 应该要减去的系统奖池额度

    fist_withdraws_amount = 0  # 用户兑奖的一等奖额度
    second_withdraws_amount = 0  # 用户兑奖的二等奖额度
    thrid_withdraws_amount = 0  # 用户兑奖的三等奖额度

    for num in numbers:  # 遍历所有号码
        if first_prize_match(draws, num):
            fist_amount = query_users_number_amount(sender, draws, num)
            withdraws_fist_amount = fist_amount * lottery_users_pool / 10 * 4 / fist_pool_amount + lottery_sys_pool / 1000
            user_pool_amount = user_pool_amount + fist_amount * lottery_users_pool / 10 * 4 / fist_pool_amount
            sys_pool_amount = sys_pool_amount + lottery_sys_pool / 1000
            withdraws_all_amount = withdraws_all_amount + withdraws_fist_amount
            fist_withdraws_amount = fist_withdraws_amount + withdraws_fist_amount
            continue
        if second_prize_match(draws, num):
            second_amount = query_users_number_amount(sender, draws, num)
            withdraw_second_amount = second_amount * lottery_users_pool / 10 * 2 / second_pool_amount
            withdraws_all_amount = withdraws_all_amount + withdraw_second_amount
            user_pool_amount = user_pool_amount + withdraw_second_amount
            second_withdraws_amount = second_withdraws_amount + withdraw_second_amount
            continue
        if thrid_prize_match(draws, num):
            thrid_amount = query_users_number_amount(sender, draws, num)
            withdraws_thrid_amount = thrid_amount * lottery_users_pool / 10 * 1 / thrid_pool_amount
            withdraws_all_amount = withdraws_all_amount + withdraws_thrid_amount
            user_pool_amount = user_pool_amount + withdraws_thrid_amount
            thrid_withdraws_amount = thrid_withdraws_amount + withdraws_thrid_amount
            continue

    if withdraws_all_amount > 0:  # 如果中奖则给其转账,并判断邀请逻辑
        inviter_address = query_my_inviter(sender)  # 上级地址
        event_pool = ppool()  # 查询活动奖池额度
        sys_pool = syspool()  # 查询系统奖池额度
        user_pool = stakepool()  # 查询活动奖池
        if inviter_address and event_pool > 0:  # 如果存在邀请者,并或活动奖池大于0

            rd = int(GetRand(1))  # 随机字符串
            pted_event_amount = event_pool / 1000 + event_pool * rd / 1000  # 分配随机 0.1% 到 1% 不等

            sr_key = concat(KEY_SHARED_REWARD, sender)  # 被邀请的被推广奖励
            sender_reward_list = GetArray(sr_key)
            if len(sender_reward_list) == 0:
                PutArray(sr_key, [str(0), str(pted_event_amount)])
            else:
                promotion_amount = sender_reward_list[0]  # 推广奖励
                promoted_amount = int(sender_reward_list[1])  # 被推广奖励
                PutArray(sr_key, [
                    promotion_amount,
                    str(promoted_amount + pted_event_amount)
                ])  # 提交自己的被推广奖励

            rd = int(GetRand(1))  # 随机字符串
            pro_event_amount = event_pool / 1000 + event_pool * rd / 1000  # 分配随机 0.1% 到 1% 不等

            sr_key = concat(KEY_SHARED_REWARD, inviter_address)  # 推广者的推广奖励
            invited_reward_list = GetArray(sr_key)  # 邀请者
            if len(invited_reward_list) == 0:
                PutArray(sr_key, [str(pro_event_amount), str(0)])
            else:
                promotion_amount = int(invited_reward_list[0])  # 推广奖励
                promoted_amount = invited_reward_list[1]  # 被推广奖励
                PutArray(sr_key, [
                    str(promotion_amount + pro_event_amount), promoted_amount
                ])  # 提交推广者的推广奖励

            ContractBalanceSend(sender, GARD_DENOM,
                                pted_event_amount)  # 给投注人转入被邀请奖励
            ContractBalanceSend(inviter_address, GARD_DENOM,
                                pro_event_amount)  # 给邀请人转推广奖励

            now_event_pool = event_pool - pted_event_amount - pro_event_amount
            Put(KEY_EVENT_POOL, now_event_pool)  # 更新活动奖池额度

        issue_account = query_issue_account()  # 查询总的中奖额度信息
        withdraw_account = query_withdraw_account(draws)  # 查询该兑奖期的兑奖额度信息
        withdraw_account_key = concat(KEY_ISSUE_ACCOUNT, draws)
        if len(issue_account) != 0:
            old_fist = int(issue_account[0])
            old_second = int(issue_account[1])
            old_thrid = int(issue_account[2])
            PutArray(KEY_ISSUE_ACCOUNT, [
                str(old_fist + fist_withdraws_amount),
                str(old_second + second_withdraws_amount),
                str(old_thrid + thrid_withdraws_amount)
            ])  # 提交总的中奖额度信息
        else:
            PutArray(KEY_ISSUE_ACCOUNT, [
                str(fist_withdraws_amount),
                str(second_withdraws_amount),
                str(thrid_withdraws_amount)
            ])  # 提交总的中奖额度信息

        if len(withdraw_account) != 0:
            old_withdraws_fist = int(withdraw_account[0])
            old_withdraws_second = int(withdraw_account[1])
            old_withdraws_thrid = int(withdraw_account[2])
            PutArray(withdraw_account_key, [
                str(old_withdraws_fist + fist_withdraws_amount),
                str(old_withdraws_second + second_withdraws_amount),
                str(old_withdraws_thrid + thrid_withdraws_amount)
            ])  # 提交指定期的兑奖额度信息
        else:
            PutArray(withdraw_account_key, [
                str(fist_withdraws_amount),
                str(second_withdraws_amount),
                str(thrid_withdraws_amount)
            ])  # 提交指定期的兑奖额度信息

        Put(KEY_USER_POOL, user_pool - user_pool_amount)  # 提交用户奖池
        Put(KEY_SYSTEM_POOL, sys_pool - sys_pool_amount)  # 提交系统奖池额度

        stake_count_key = concat(KEY_MY_STAKE_COUNT,
                                 sender)  # 我的投注统计,包括投注的总 token,和获取奖励的总 token
        count_value = GetArray(stake_count_key)
        betting_amount = count_value[0]  # 总共投注
        reward_amount = int(count_value[1])  # 获得奖励
        PutArray(stake_count_key,
                 [betting_amount,
                  str(reward_amount + withdraws_all_amount)])  # 提交自己投注记录

        key = concat(concat(KEY_REDEMPTION_USER, draws), sender)  # 兑奖信息
        PutArray(key, [str(time), str(withdraws_all_amount)])  # 提交用户的兑奖信息

        withdraw_status_key = concat(concat(KEY_WITZHDRAWS_STATUS, draws),
                                     sender)
        Put(withdraw_status_key, True)  # 将用户此期的兑奖状态改成true
        ContractBalanceSend(sender, GARD_DENOM,
                            withdraws_all_amount)  # 给投注人转入获取的奖励
        return True
    else:
        raise Exception("当前投注没有中奖")
Esempio n. 29
0
def query_amount_award(draws):  # 查询每一期的中奖额度信息
    award_key = concat(draws, KEY_AMOUNT_EACH_AWARD)
    return GetArray(award_key)
Esempio n. 30
0
def stake(mode, multipe, number):  # 用户投注
    ls = []
    now_time = GetTime()
    for i in range(len(number)):
        ls.append(int(number[i]))
    if mode == 0:       # 散值
        for i in range(len(ls)):
            if ls[i] > 6:
                raise Exception("每个数字在1到6之间")
    if mode == 1:       # 和值
        if int(number) < 3 or int(number) > 18:
            raise Exception("最大的和值为18")

    if multipe > 99 or multipe < 1:
        raise Exception("不支持的倍数")

    if if_stake():
        num = draw_number()     # 开启下一期前,开放上一期的中奖号码
        draw_num_key = concat(KEY_GAME_PRIZE, issue())
        Put(draw_num_key, num)      # Put 该期的中奖号码
        update_period = get_period_generation()
        Put(KEY_GAME_PERIOD, update_period)  # Put 新的期数
        time_key = concat(KEY_GAME_TIME, update_period)
        Put(time_key, now_time)         # Put新期数的时间戳
        period_list = []
        ls = GetArray(KEY_GAME_LIST)
        for i in range(len(ls)):
            if len(ls) < 24:
                period_list.append(ls[i])
            if len(ls) >= 24 and i < 23:
                period_list.append(ls[i + 1])
        period_list.append(update_period)
        PutArray(KEY_GAME_LIST, period_list)  # Put 24个期数列表

    sender = GetTxSender()
    period = issue()
    amount = multipe * STAKE_AMOUNT

    if BalanceOf(sender, [GARD_DENOM])[0] < amount:
        raise Exception("余额不足")

    if len(query_user_stake(sender, period)) > 0:
        raise Exception("当期已经购买过")
    user_stake_key = concat(concat(KEY_USER_STAKE, sender), period)
    if mode == 0:  # 0 为散号
        PutArray(user_stake_key, [str(mode), str(multipe), number, str(amount)])
    if mode == 1:  # 1 为和值
        PutArray(user_stake_key, [str(mode), str(multipe), number, str(amount)])

    user_stake_list = []
    ls = query_user_stake_list(sender)
    for i in range(len(ls)):
        if len(ls) < 24:
            user_stake_list.append(ls[i])
        if len(ls) >= 24 and i < 23:
            user_stake_list.append(ls[i + 1])
    user_stake_list.append(period)
    user_stake_list_key = concat(KEY_USER_ISSUE, sender)  # Put 24个用户投注的期数列表
    PutArray(user_stake_list_key, user_stake_list)

    stake_all_amount = query_user_stake_amount(sender)
    stake_amount_key = concat(KEY_USER_STAKE, sender)
    if not stake_all_amount:
        Put(stake_amount_key, amount)
    else:
        stake_all_amount = stake_all_amount + amount
        Put(stake_amount_key, stake_all_amount)         # Put 用户的总共投注金额

    inject_stake_pool(amount)
    return True