Ejemplo n.º 1
0
def process_tx(txins, txouts):
    # 用于设置标志的的局部实例
    flag = statistics.Flag()
    groups = []  # 每个地址对应的组              [26, 38, 26, 26, 99...]
    new_address = []  # 该交易中新地址的集合
    stat.TX_NUM += 1  # 处理的交易数累加

    # 处理输入集合中的地址
    last_group_id = -1
    for address in txins:
        if is_hub_node(address):
            flag.hub_in = 1
        stat.total_addrs.add(address)  # 统计不重复的地址个数
        group_id = db.get_group_id(address)  # 查询该地址的组号
        # in中地址不同组
        if group_id != -1 and last_group_id != -1 and group_id != last_group_id:
            flag.diff_in = 1
        if group_id == -1:
            stat.NUM_NEW_IN += 1  # in中的新地址数
            new_address.append(address)  # 新地址单独存放
        else:
            last_group_id = group_id  # 设置上一个地址的组号
            groups.append(group_id)

    # 处理输出集合中的地址
    for address in txouts:
        if is_hub_node(address):
            flag.hub_out = 1
        stat.total_addrs.add(address)  # 统计不重复的地址个数
        group_id = db.get_group_id(address)
        if group_id == -1:
            new_address.append(address)  # 新地址单独存放
        else:
            flag.have_old_out = 1  # out中有旧地址
            groups.append(group_id)

    # 所有地址都是新地址, 随机选择组号全部加入
    if len(groups) == 0:
        add_new_addrs(new_address, get_random(stat.GROUP_NUM))
        stat.IN_SAME_GROUP += 1  # 非跨组交易
        stat.ALL_NEW_ADDRESS += 1  # 全新交易
        stat.INSIDE_NEW_OUT += 1  # out全新
        return

    group_no = vote_for_result(groups, flag)  # 投票选出该交易的最终组号
    # 将新地址加入组中 (组号为该交易大多数地址所在的组)
    if len(new_address) > 0:
        add_new_addrs(new_address, group_no)
Ejemplo n.º 2
0
def send_mail(subject, text):
    print refresh_user_token()

    group = db.get_group_id()
    uri = '%s/message/%s' % (api_server, group)
    try:
        response = _create_and_send_request('%s/message/%s' % (api_server, group),
                                            {"subject": subject, "message": text})
    except Exception as inst:
        response = inst

    jres = json.loads(response.read())
    return jres['success']
Ejemplo n.º 3
0
def send_mail(subject, text):
    print refresh_user_token()

    group = db.get_group_id()
    uri = '%s/message/%s' % (api_server, group)
    try:
        response = _create_and_send_request(
            '%s/message/%s' % (api_server, group), {
                "subject": subject,
                "message": text
            })
    except Exception as inst:
        response = inst

    jres = json.loads(response.read())
    return jres['success']
Ejemplo n.º 4
0
def add_member(email):
    membership = {"group_name": "football-pool",
                  "address": email,
                  "welcome_message": {"subject": "Welcome to the Football Pool!",
                                      "text": "Welcome to the Football Pool! This list is used to help manage communication between players in the pool."}}

    try:
        response = _create_and_send_request('%s/membership/%s' % 
                                            (api_server, db.get_group_id()),
                                            membership)
    except Exception as inst:
        response = inst

    jres = json.loads(response.read())
    db.save_fiesta_id_for_user(email, jres['data']['user_id'])
    return response
Ejemplo n.º 5
0
def add_member(email):
    membership = {
        "group_name": "football-pool",
        "address": email,
        "welcome_message": {
            "subject":
            "Welcome to the Football Pool!",
            "text":
            "Welcome to the Football Pool! This list is used to help manage communication between players in the pool."
        }
    }

    try:
        response = _create_and_send_request(
            '%s/membership/%s' % (api_server, db.get_group_id()), membership)
    except Exception as inst:
        response = inst

    jres = json.loads(response.read())
    db.save_fiesta_id_for_user(email, jres['data']['user_id'])
    return response