コード例 #1
0
def task_chain_out_collect():
    """链外资金归集"""

    with db.app.app_context():
        # 归集地址:项目方提供地址boss账户
        vpc_boss_address = consul_clinet.get_digiccy_boss_address(COIN_NAME)

        # 获取矿工费转帐地址
        minerfee_address = consul_clinet.get_digiccy_minerfee_address(
            COIN_NAME)

        # 最小归集数量
        collect_min_amount = consul_clinet.get_digiccy_collect_min(COIN_NAME)

        # 归集手续费
        gas_limit, gas_price = consul_clinet.get_digiccy_collect_fee(COIN_NAME)
        gas_limit_fee = Decimal((gas_limit * gas_price) / (10**18))

        # 转帐手续费
        miner_minfee = consul_clinet.get_miner_fee(COIN_NAME)

        start_num = 0
        limit_num = 100
        len_num = 0
        while True:
            users = User.coin_bind_users(COIN_NAME, start_num, limit_num)
            len_num += len(users)
            if not users:
                logging.info('{}链外归集处理完毕,处理条数:{}'.format(COIN_NAME, len_num))
                print('{}链外归集处理完毕,处理条数:{}'.format(COIN_NAME, len_num))
                break
            for user in users:
                if not consul_clinet.get_task_switch():
                    logging.warning('链外充值定时任务被手动关闭!')
                    return
                # 本地节点是否链接,是否同步
                if not vpc_wallet.is_connected():
                    logging.error('{}节点离线!'.format(COIN_NAME))
                    return
                if vpc_wallet.is_syncing():
                    logging.error('VPC 节点同步未完成')
                    return

                # 用户是否有归集未确认订单
                if Order.is_collect(user.stellar_account, COIN_NAME):
                    print('用户有归集未确认订单')
                    continue

                # 用户绑定地址
                user_digiccy_address = user.address
                user_digiccy_secret = rsa_params_decrypt(user.secret)
                # 用户绑定地址余额,小于最小归集数量跳过
                balance = round(vpc_wallet.get_balance(user_digiccy_address),
                                7)
                if balance <= collect_min_amount:
                    continue
                # print(type(balance), balance, user_digiccy_address, user_digiccy_secret)

                # 归集数量:余额-最小归集数
                collect_amount = balance - collect_min_amount
                miner_fee = vpc_wallet.get_minerFee(user_digiccy_address)
                if miner_fee < miner_minfee:
                    is_success, tx_hash = vpc_wallet.minerfee_transaction(
                        minerfee_address, user_digiccy_address, miner_minfee)
                    if not is_success:
                        logging.error('矿工费转账失败:{}'.format(tx_hash))
                        print("矿工费转账失败:{}".format(tx_hash))
                        continue

                # 创建归集订单
                order_collect = Order(
                    id=str(uuid.uuid1()),
                    user_id=user.id,
                    stellar_account=user.stellar_account,
                    coin_name=user.coin_name,
                    order_type=3,
                    chain_type=2,
                    order_from=user_digiccy_address,
                    order_to=vpc_boss_address,
                    amount=collect_amount,
                    fee=gas_limit_fee,
                    order_hash='',
                    add_time=datetime.now(),
                )
                # 创建裸交易发出
                is_success, msg = vpc_wallet.raw_transaction(
                    user_digiccy_secret, vpc_boss_address, collect_amount,
                    gas_price, gas_limit)

                if is_success:
                    order_collect.status = 2  # 发出成功待确认
                    order_collect.order_hash = msg
                    order_collect.done_time = datetime.now()
                else:
                    print("发出交易失败")
                    continue

                try:
                    db.session.add(order_collect)
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'chain_out_withdraw update order error:{}'.format(
                            str(e)))
                    return

            start_num += limit_num
コード例 #2
0
def task_chain_out_collect():
    """链外资金归集"""
    with db.app.app_context():
        # 归集地址:项目方提供地址boss账户
        eos_boss_address = consul_clinet.get_digiccy_boss_address(COIN_NAME)
        # 最小归集数量
        collect_min_amount = consul_clinet.get_digiccy_collect_min(COIN_NAME)
        # collect_min_amount = 0.01
        start_num = 0
        limit_num = 100
        len_num = 0
        while True:
            users = User.coin_bind_users(COIN_NAME, start_num, limit_num)
            len_num += len(users)
            if not users:
                logging.info('{}链外归集处理完毕,处理条数:{}'.format(COIN_NAME, len_num))
                print('{}链外归集处理完毕,处理条数:{}'.format(COIN_NAME, len_num))
                break
            for user in users:
                if not consul_clinet.get_task_switch():
                    logging.warning('链外充值定时任务被手动关闭!')
                    return
                # 本地节点是否链接,是否同步
                if not eos_wallet.init_consul("", ""):
                    logging.error('{}节点离线!'.format(COIN_NAME))
                    return
                if not eos_wallet.init_eos():
                    logging.error('EOS 节点同步未完成')
                    return
                # 用户是否有归集未确认订单
                if Order.is_collect(user.stellar_account, COIN_NAME):
                    print('用户有归集未确认订单')
                    continue
                # 用户绑定地址
                user_digiccy_address = user.address
                # 解密私钥
                user_digiccy_secret = rsa_params_decrypt(user.secret)
                # 用户绑定地址余额,小于最小归集数量跳过
                balance = round(eos_wallet.get_balance(user_digiccy_address), 7)





                if balance <= collect_min_amount:
                    continue
                print(type(balance), balance, user_digiccy_address, user_digiccy_secret)
                # 查询客户账号ram,cup,net余额,并判断是否充值
                # 充值的费用是按照2019.3.28号的ram,cup,net价格计算的,后续关注是否需要调整
                ram, cpu, net = eos_wallet.get_account_ram_cup_net(user_digiccy_address, user_digiccy_secret)
                if ram < 3000:
                    balance = balance - 0.1
                elif cpu < 2000 or net < 3000:
                    balance = balance - 0.03
                elif ram == 0 and cpu == 0 and net == 0:
                    continue
                # 创建归集订单
                order_collect = Order(
                    id=str(uuid.uuid1()),
                    user_id=user.id,
                    stellar_account=user.stellar_account,
                    coin_name=user.coin_name,
                    order_type=3,
                    chain_type=2,
                    order_from=user_digiccy_address,
                    order_to=eos_boss_address,
                    amount=balance,
                    fee=0,
                    order_hash='',
                    add_time=datetime.now(),
                )
                # 创建裸交易发出
                is_success, msg = eos_wallet.payment(privKey=user_digiccy_secret,
                                                     fromAddr=user_digiccy_address,
                                                     toAddre=eos_boss_address,
                                                     value=balance)

                if is_success:
                    order_collect.status = 2  # 发出成功待确认
                    order_collect.order_hash = msg
                    order_collect.done_time = datetime.now()
                else:
                    print("发出交易失败")
                    continue

                try:
                    db.session.add(order_collect)
                    db.session.commit()
                except Exception as e:
                    logging.error('chain_out_withdraw update order error:{}'.format(str(e)))
                    return

            start_num += limit_num
コード例 #3
0
def task_chain_out_collect():
    """链外资金归集"""

    with db.app.app_context():
        # 归集地址:项目方提供boss地址
        btc_boss_address = consul_clinet.get_digiccy_boss_address(COIN_NAME)
        # 最小归集数量
        collect_min_amount = consul_clinet.get_digiccy_collect_min(COIN_NAME)
        # 归集手续费
        fee = Decimal(consul_clinet.get_btc_collect_fee(COIN_NAME))
        start_num = 0
        limit_num = 100
        len_num = 0
        success_num = 0
        fail_num = 0
        while True:
            users = User.coin_bind_users(COIN_NAME, start_num, limit_num)
            len_num += len(users)
            if not users:
                logging.info('{}链外归集处理完毕,处理条数:{},归集成功条数:{},归集失败条数:{}'.format(
                    COIN_NAME, len_num, success_num, fail_num))
                print('{}链外归集处理完毕,处理条数:{},归集成功条数:{},归集失败条数:{}'.format(
                    COIN_NAME, len_num, success_num, fail_num))
                break
            for user in users:
                if not consul_clinet.get_task_switch():
                    logging.warning('链外充值定时任务被手动关闭!')
                    return
                # 本地节点是否链接,是否同步
                if not btc_wallet.is_connected():
                    logging.error('{}节点离线!'.format(COIN_NAME))
                    return
                if not btc_wallet.is_sync():
                    logging.error('BTC 节点同步未完成')
                    return

                # 用户是否有归集未确认订单
                if Order.is_collect(user.stellar_account, COIN_NAME):
                    print('用户有归集未确认订单')
                    continue

                # 用户绑定地址
                digiccy_address = user.address
                # 获取btc余额
                # btc_account = btc_wallet.get_accounts(digiccy_address)
                # amount = btc_wallet.get_balance_by_account(btc_account)
                amount = btc_wallet.get_balance(digiccy_address)
                collect_amount = round(amount - fee, 8)
                if amount is None:
                    continue
                # 归集数量小于最小归集数量,则跳过
                if collect_amount < collect_min_amount:
                    continue

                # 创建归集订单
                order_collect = Order(
                    id=str(uuid.uuid1()),
                    user_id=user.id,
                    stellar_account=user.stellar_account,
                    coin_name=user.coin_name,
                    order_type=3,
                    chain_type=2,
                    order_from=digiccy_address,
                    order_to=btc_boss_address,
                    amount=collect_amount,
                    fee=fee,
                    order_hash='',
                    add_time=datetime.now(),
                )
                # 创建裸交易发出
                is_success, tx_hash, msg = btc_wallet.raw_payment(
                    digiccy_address, btc_boss_address, collect_amount)
                if is_success is None:
                    continue
                print(is_success, tx_hash, msg)

                if is_success:
                    success_num += 1
                    order_collect.status = 2  # 发出成功待确认
                    order_collect.order_hash = tx_hash
                    order_collect.done_time = datetime.now()
                else:
                    fail_num += 1
                    order_collect.status = 0  # 发出成功失败

                try:
                    db.session.add(order_collect)
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'chain_out_withdraw update order error:{}'.format(
                            str(e)))
                    return

            start_num += limit_num
コード例 #4
0
def task_chain_out_collect():
    """链外资金归集"""

    with db.app.app_context():
        # 归集地址:项目方提供地址boos账户
        eth_boss_address = consul_clinet.get_digiccy_boss_address(COIN_NAME)

        # 最小归集数量
        collect_min_amount = consul_clinet.get_digiccy_collect_min(COIN_NAME)

        # 归集手续费
        gas_limit, gas_price = consul_clinet.get_digiccy_collect_fee(COIN_NAME)
        gas_limit_fee = Decimal((gas_limit * gas_price) / (10 ** 18))

        start_num = 0
        limit_num = 100
        len_num = 0
        success_num = 0
        fail_num = 0
        while True:
            users = User.coin_bind_users(COIN_NAME, start_num, limit_num)
            len_num += len(users)
            if not users:
                logging.info('{}链外归集处理完毕,处理条数:{},归集成功条数:{},归集失败条数:{}'.format(COIN_NAME, len_num, success_num, fail_num))
                print('{}链外归集处理完毕,处理条数:{},归集成功条数:{},归集失败条数:{}'.format(COIN_NAME, len_num, success_num, fail_num))
                break
            for user in users:
                if not consul_clinet.get_task_switch():
                    logging.warning('链外充值定时任务被手动关闭!')
                    return
                # 本地节点是否链接,是否同步
                if not eth_wallet.is_connected():
                    logging.error('{}节点离线!'.format(COIN_NAME))
                    return
                if eth_wallet.is_syncing():
                    logging.error('ETH 节点同步未完成')
                    return

                # 用户是否有归集未确认订单
                if Order.is_collect(user.stellar_account, COIN_NAME):
                    print('用户有归集未确认订单')
                    continue

                # 用户绑定地址
                user_digiccy_address = user.address
                user_digiccy_secret = rsa_params_decrypt(user.secret)

                # 用户绑定地址余额,小于最小归集数量跳过
                balance = eth_wallet.get_balance(user_digiccy_address)
                if balance <= 0:
                    # print('账户无余额')
                    continue
                retain_balance = Decimal('0.00001')  # 账户保留余额0.0001约1分人民币

                # 归集数量:余额-最大使用手续费
                collect_amount = balance - retain_balance - gas_limit_fee
                if collect_amount < collect_min_amount:
                    # print('余额不足',balance, collect_amount, user_digiccy_address, user_digiccy_secret)
                    continue

                # print('余额充足',balance, collect_amount, user_digiccy_address, user_digiccy_secret)

                # 创建归集订单
                order_collect = Order(
                    id=str(uuid.uuid1()),
                    user_id=user.id,
                    stellar_account=user.stellar_account,
                    coin_name=user.coin_name,
                    order_type=3,
                    chain_type=2,
                    order_from=user_digiccy_address,
                    order_to=eth_boss_address,
                    amount=collect_amount,
                    fee=gas_limit_fee,
                    order_hash='',
                    add_time=datetime.now(),
                )
                # 创建裸交易发出
                is_success, tx_hash, msg = eth_wallet.raw_transaction(user_digiccy_secret, eth_boss_address,
                                                                     collect_amount, gas_price, gas_limit)

                print(is_success, tx_hash, msg)

                if is_success:
                    success_num += 1
                    order_collect.status = 2  # 发出成功待确认
                    order_collect.order_hash = tx_hash
                    order_collect.done_time = datetime.now()
                else:
                    fail_num += 1
                    order_collect.status = 0  # 发出成功失败

                try:
                    db.session.add(order_collect)
                    db.session.commit()
                except Exception as e:
                    logging.error('chain_out_withdraw update order error:{}'.format(str(e)))
                    return

            start_num += limit_num