Ejemplo n.º 1
0
def task_chain_in_confirm():
    """链内转账504,或timeout错误确认"""
    with db.app.app_context():
        orders = Order.chain_in_unconfirm(COIN_NAME, 100)
        for order in orders:
            # 定时任务开关
            if not consul_clinet.get_task_switch():
                logging.warning('链外充值定时任务被手动关闭!')
                return

            # 查询链内哈希
            stellar_hash = order.order_hash
            stellar_node = stellar_service.stellar_node(is_full=True)
            ret = stellar_service.query_hash(stellar_hash, stellar_node=stellar_node)
            # 请求失败
            if not ret:
                continue

            relate_order = None
            if ret.get('hash') is None:
                order.status = 0  # hash 不存在,链内转账失败
                # 当前订单为充值订单
                if order.order_type == 1:
                    relate_order = Order.query.filter_by(id=order.relate_id).first()
                    relate_order.relate_order_status = 0  # 待重新生成链内转账订单
            else:
                order.status = 1  # hash 存在,链内转账成功
                # 当前订单为提现订单
                if order.order_type == 2:
                    relate_order = Order.query.filter_by(id=order.relate_id).first()
                    relate_order.status = -1  # 更新链外提现订单状态为-1(待转账)
                elif order.order_type == 1:
                    order.done_time = datetime.now()  # 链内充值订单完成时间

            # 无需更改关联订单状态
            if relate_order is None:
                try:
                    db.session.add(order)
                    db.session.commit()
                except Exception as e:
                    logging.error('task_chain_in_confirm update db error:{}'.format(str(e)))
                    db.session.rollback()
                    return
            # 更改关联订单状态
            else:
                try:
                    db.session.add_all([order, relate_order])
                    db.session.commit()
                except Exception as e:
                    logging.error('task_chain_in_confirm update db error:{}'.format(str(e)))
                    db.session.rollback()
                    return

            is_relate = '否' if not relate_order else '是,关联订单id:{}'.format(relate_order.id)
            print('确认hash订单id:{},是否更改关联订单:{}'.format(order.id,is_relate))
            logging.info('确认hash订单id:{},是否更改关联订单:{}'.format(order.id,is_relate))
Ejemplo n.º 2
0
def task_chain_in_confirm():
    """链内转帐确认"""
    with db.app.app_context():
        orders = Order.chain_in_unconfirm(COIN_NAME, 100)
        for order in orders:
            # 定时任务开关
            if not consul_clinet.get_task_switch():
                logging.warning('{}链内转帐确认定时任务被手动关闭!'.format(COIN_NAME))
                return
            order_hash = order.order_hash
            stellar_node = stellar_service.stellar_node(is_full=True)
            ret = stellar_service.query_hash(order_hash,
                                             stellar_node=stellar_node)
            if ret is None:
                return
            relate_order = None
            if ret.get("hash") is None:
                order.status = 3
                # 如果为充值订单
                if order.order_type == 1:
                    relate_order = Order.query.filter_by(
                        id=order.relate_id).first()
                    relate_order.relate_order_status = 0  # 进入task_chain_in_recharge 重新生成订单
            else:
                order.status = 3
                if order.order_type == 1:
                    order.done_time = datetime.now()
                else:
                    relate_order = Order.query.filter_by(
                        id=order.relate_id).first()
                    # relate_order.status = -1  # 链外待转帐,relate_order进入task_chain_out_withdraw

            if relate_order is None:
                try:
                    db.session.add(order)
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'task_chain_in_confirm update db error:{}'.format(
                            str(e)))
                    db.session.rollback()
                    return
            else:
                try:
                    db.session.add_all([order, relate_order])
                    db.session.commit()
                except Exception as e:
                    logging.error(
                        'task_chain_in_confirm update db error:{}'.format(
                            str(e)))
                    db.session.rollback()
                    return
Ejemplo n.º 3
0
    def get(self):
        parser_ = CoverRequestParser()
        parser_.add_argument("stellar_account", type=str, required=True)
        parser_.add_argument("asset", type=str, required=False)
        parser_.add_argument("payment_type", type=int, required=False)
        parser_.add_argument("trades_type", type=int, required=False)
        parser_.add_argument("create_time", type=str, required=False)
        params = parser_.parse_args()

        account = params.get('stellar_account')
        asset = params.get('asset')
        payment_type = params.get('payment_type')
        trades_type = params.get('trades_type')
        create_time = params.get('create_time')

        try:
            account_xdr_object(account)
        except Exception as e:
            return create_response(CodeMsg.CM(1031, '账户地址错误'))

        try:
            coin_types = get_coin_types()
        except Exception as e:
            logging.error('find coin_types error:{}'.format(e))
            return create_response(CodeMsg.CM(1030, '查询失败'))
        if asset is not None and asset not in coin_types:
            return create_response(CodeMsg.CM(1031, '资产名错误'))

        if payment_type is not None and int(payment_type) not in (1, 2, 3):
            return create_response(CodeMsg.CM(1031, '转帐类型错误'))
        if trades_type is not None and int(trades_type) not in (1, 2, 3):
            return create_response(CodeMsg.CM(1031, '挂单类型错误'))

        if create_time is not None:
            try:
                time.strptime(create_time, "%Y-%m-%d %H:%M:%S")
            except Exception as e:
                return create_response(CodeMsg.CM(1031, '时间参数错误'))

        native_code = 'VTOKEN'
        stellar_http_node = stellar_service.stellar_node(
        )  # 'http://101.132.188.48:8000'
        try:
            asset_flow = StellarAssetFlow(account,
                                          stellar_http_node,
                                          native_code,
                                          asset_code=asset,
                                          create_time=create_time)
        except Exception as e:
            logging.error('查询转帐、挂单流水错误:{}'.format(e))
            return create_response(CodeMsg.CM(1030, '查询错误'))
        if payment_type is not None:
            payment_type = int(payment_type)
            if payment_type == 3:
                asset_flow.payment_records()
            else:
                asset_flow.payment_records(payment_type)
        if trades_type is not None:
            trades_type = int(trades_type)
            if trades_type == 3:
                asset_flow.trades_records()
            else:
                asset_flow.trades_records(trades_type)

        flow_list = asset_flow.records
        return create_response(CodeMsg.CM(200, '查询成功'), data=flow_list)