Пример #1
0
def checkStellarAccount(account):
    """检查stellar账户是否有效"""
    try:
        account_xdr_object(account)
        return True
    except:
        return False
Пример #2
0
    def get(self):
        parser_ = CoverRequestParser()
        parser_.add_argument("stellar_account", type=str, required=True)
        parser_.add_argument("coin_name", type=str, required=False)
        parser_.add_argument("order_type", type=int, required=False)
        parser_.add_argument("chain_type", type=int, required=False)
        params = parser_.parse_args()

        user_address = params.get('stellar_account')
        coin_name = params.get('coin_name')
        order_type = params.get('order_type')
        chain_type = params.get('chain_type')
        try:
            account_xdr_object(user_address)
        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 coin_name is not None and coin_name not in coin_types:
            return create_response(CodeMsg.CM(1031, '币种名错误'))
        if order_type is not None and int(order_type) not in (1, 2, 3):
            return create_response(CodeMsg.CM(1031, '订单类型错误'))
        if chain_type is not None and int(chain_type) not in (1, 2):
            return create_response(CodeMsg.CM(1031, '链类型错误'))

        params_dict = dict(
            stellar_account=user_address,
            coin_name=coin_name,
            order_type=order_type,
            chain_type=chain_type,
        )
        filter = {}
        for param in params_dict:
            if params_dict[param] is not None:
                filter[param] = params_dict[param]
        # print(filter)
        ret_list = []
        try:
            query_dict = Order.query.filter_by(**filter).all()
            for query in query_dict:
                ret_dict = {}
                ret_dict["user_id"] = query.user_id
                ret_dict["order_from"] = query.order_from
                ret_dict["order_to"] = query.order_to
                ret_dict["amount"] = str(query.amount)
                ret_dict["fee"] = str(query.fee)
                ret_dict["status"] = str(query.status)
                ret_dict["add_time"] = str(query.add_time)
                ret_dict["coin_name"] = query.coin_name

                ret_list.append(ret_dict)
        except Exception as e:
            logging.error('Db query order error:{}'.format(e))
            return create_response(CodeMsg.CM(1030, '查询错误'))

        return create_response(CodeMsg.CM(200, '查询成功'), data=ret_list)
Пример #3
0
def check_stellar_account(stellar_account):
    """检查stellar公钥是否合法,合法返回True 不合法返回False"""
    try:
        # stellar 内部提供的方法 知道有什么用就行了
        account_xdr_object(stellar_account)
    except:
        return False
    return True
Пример #4
0
    def get(self):
        parser_ = CoverRequestParser()
        parser_.add_argument("user_address", type=str, required=True)
        params = parser_.parse_args()
        user_address = params.get("user_address")

        try:
            account_xdr_object(user_address)
        except Exception as e:
            return create_response(CodeMsg.CM(1003, '账户地址错误'))
        try:
            user = User.query.filter_by(stellar_account=user_address, coin_name=COIN_NAME).first()
        except Exception as e:
            logging.error('Db query user error:{}'.format(e))
            return create_response(CodeMsg.CM(1003, '查询错误'))
        if user is None:
            return create_response(CodeMsg.CM(1003, '地址不存在或没绑定对应币种'))
        address = user.address
        return create_response(CodeMsg.CM(200, '充币地址查询成功'), data=address)
Пример #5
0
    def get(self):
        parser_ = CoverRequestParser()
        parser_.add_argument("user_address", type=str, required=True)
        parser_.add_argument("currency_letter", type=str, required=False)
        params = parser_.parse_args()
        user_address = params.get("user_address")
        currency_letter = params.get("currency_letter")
        try:
            account_xdr_object(user_address)
        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, '查询失败'))
        coin_list = []
        if currency_letter is not None:
            currency_letter = currency_letter.upper()
            for coin_type in coin_types:
                if currency_letter in coin_type:
                    coin_list.append(coin_type)
        else:
            coin_list = list(coin_types.keys())

        ret_data = []
        if len(coin_list) == 0:
            return create_response(CodeMsg.CM(200, '查询成功'), data=ret_data)
        else:
            for coin_name in coin_list:
                try:
                    user = User.query.filter_by(stellar_account=user_address,
                                                coin_name=coin_name).first()
                except Exception as e:
                    logging.error('Db query user error:{}'.format(e))
                    return create_response(CodeMsg.CM(1030, '查询错误'))
                ret_data.append({
                    "asset_code": coin_name,
                    "is_bind": 0 if user is None else 1
                })
            return create_response(CodeMsg.CM(200, '查询成功'), data=ret_data)
Пример #6
0
 def test_account_xdr_object(self):
     assert isinstance(utils.account_xdr_object(self.account),
                       Xdr.types.PublicKey)
Пример #7
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)
Пример #8
0
 def test_account_xdr_object(self):
     assert isinstance(utils.account_xdr_object(self.account), Xdr.types.PublicKey)
Пример #9
0
 def test_account_xdr_object(self):
     self.assertIsInstance(Xdr.types.PublicKey, utils.account_xdr_object(self.account))