Exemplo n.º 1
0
    def gather_to_gather(self, coin_id, from_address, amount, to_address, verification_code):
        """
        归集转归集
        :param coin_id: 币种
        :param from_address: 待归集地址
        :param amount: 归集数量
        :param to_address: 收款地址
        :param verification_code: 验证码
        :return:
        """
        conf = get_config()
        env = conf["env"]
        if env == "pd":
            vcode_service = VcodeService()
            result = vcode_service.check_sms_email_vcode('common', verification_code)
        with MysqlTools().session_scope() as session:
            record_id = generate_order_no()
            foreign_gather_record = ForeignGatherRecordModel(
                record_id=record_id,
                public_address=to_address,
                purpose_amount=amount,
                gather_status=_FOUR_S
            )
            session.add(foreign_gather_record)
            gather_record_id = foreign_gather_record.record_id
            order_no = generate_order_no()
            withdraw = ForeignWithdrawOrderRecordModel(
                order_no=order_no,
                relate_flow_no=gather_record_id,
                coin_id=coin_id,
                from_address=from_address,
                withdraw_address=to_address,
                withdraw_amount=amount,
                withdraw_type=_THREE_S,
                withdraw_status=_ZERO_S,
                audit_status=_ONE_S,
                source_status=_ZERO_S,
                transfer_at=get_utc_now()
            )
            session.add(withdraw)
            session.commit()
            withdraw_order_no = withdraw.order_no
            withdraw = session.query(ForeignWithdrawOrderRecordModel).filter(
                ForeignWithdrawOrderRecordModel.order_no == order_no).first()
            wfs = WalletForeignService()
            send_result = None
            if coin_id == _ZERO_S:  # 比特币
                send_result = wfs.btc_send_tx(withdraw)
            elif coin_id == _SIXTY_S:  # 以太坊
                send_result = wfs.eth_send_tx(withdraw)

            if send_result is True:
                gather_record_model = session.query(ForeignGatherRecordModel).filter(ForeignGatherRecordModel.record_id == gather_record_id).first()
                gather_record_model.gather_status = _ONE_S
                withdraw_reocrd_model = session.query(ForeignWithdrawOrderRecordModel).filter(ForeignWithdrawOrderRecordModel.order_no == withdraw_order_no).first()
                withdraw_reocrd_model.withdraw_status = _ONE_S
                session.commit()
            return
Exemplo n.º 2
0
    def operation_gather(self, user_name, sub_public_address, conditions, coin_id, to_address, verification_code):
        """
        归集操作
        :param user_name: 用户名
        :param sub_public_address: 钱包地址
        :param conditions: 归集条件(大于等于xx个单位)
        :param coin_id: 币种(必填)
        :param to_address: 归集账户
        :param verification_code: 验证码
        :return:
        """
        conf = get_config()
        env = conf["env"]
        if env == "pd":
            vcode_service = VcodeService()
            result = vcode_service.check_sms_email_vcode('common', verification_code)
        f_filters = {}
        u_filters = {}
        if user_name:
            u_filters["user_name"] = user_name
        if sub_public_address:
            f_filters["sub_public_address"] = sub_public_address
        if not conditions:
            conditions = 0
        wfs = WalletForeignService()

        with MysqlTools().session_scope() as session:
            model = None
            if coin_id == _ZERO_S:
                model = WalletBtcModel
            elif coin_id == _SIXTY_S:
                model = WalletEthModel
            # token_conf = session.query(TokenConfModel).filter(TokenConfModel.coin_id == coin_id).first()
            # gather_minimum_amount = token_conf.gather_minimum_amount
            gather_minimum_amount = wfs.eth_get_gas()

            wallet_list = session.query(model, UserAccountModel).filter(
                model.amount >= conditions, model.account_id != "").filter_by(**f_filters).outerjoin(
                UserAccountModel,
                model.account_id == UserAccountModel.account_id).filter_by(**u_filters)
            total_amount = 0
            available_wallet_list = []
            for w in wallet_list:
                amount = 0
                if coin_id == _ZERO_S:
                    amount = w.WalletBtcModel.amount
                elif coin_id == _SIXTY_S:
                    amount = w.WalletEthModel.amount
                if gather_minimum_amount < amount:
                    available_wallet_list.append(w)
                    total_amount = total_amount + amount

            record_id = generate_order_no()
            foreign_gather_record = ForeignGatherRecordModel(
                record_id=record_id,
                coin_id=coin_id,
                public_address=to_address,
                conditions=conditions,
                purpose_amount=total_amount
            )
            session.add(foreign_gather_record)
            foreign_withdraw_order_record_list = []
            wallet_list = available_wallet_list
            if coin_id == _ZERO_S:
                for wallet in wallet_list:
                    if wallet.WalletBtcModel.amount > 0:
                        foreign_withdraw_order_record = ForeignWithdrawOrderRecordModel(
                            order_no=generate_order_no(),
                            relate_flow_no=foreign_gather_record.record_id,
                            account_id=wallet.WalletBtcModel.account_id,
                            coin_id=coin_id,
                            from_address=wallet.WalletBtcModel.sub_public_address,
                            withdraw_address=to_address,
                            withdraw_amount=wallet.WalletBtcModel.amount,
                            withdraw_type=_TWO,
                            withdraw_status=_ZERO,
                            audit_status=_ONE,
                            source_status=_ONE
                        )
                        foreign_withdraw_order_record_list.append(foreign_withdraw_order_record)
            elif coin_id == _SIXTY_S:
                for wallet in wallet_list:
                    if wallet.WalletEthModel.amount > 0:
                        foreign_withdraw_order_record = ForeignWithdrawOrderRecordModel(
                            order_no=generate_order_no(),
                            relate_flow_no=foreign_gather_record.record_id,
                            account_id=wallet.WalletEthModel.account_id,
                            coin_id=coin_id,
                            from_address=wallet.WalletEthModel.sub_public_address,
                            withdraw_address=to_address,
                            withdraw_amount=wallet.WalletEthModel.amount,
                            withdraw_type=_TWO,
                            withdraw_status=_ZERO,
                            audit_status=_ONE,
                            source_status=_ONE
                        )
                        foreign_withdraw_order_record_list.append(foreign_withdraw_order_record)
            session.add_all(foreign_withdraw_order_record_list)
            session.commit()

            if coin_id == _ZERO_S:  # 比特币
                for withdraw in foreign_withdraw_order_record_list:
                    wfs.btc_send_tx(withdraw)
            elif coin_id == _SIXTY_S:  # 以太坊
                for withdraw in foreign_withdraw_order_record_list:
                    wfs.eth_send_tx(withdraw)
            return