def post(self): parser_ = CoverRequestParser() parser_.add_argument("encryption_parameters", type=str, required=True) params = parser_.parse_args() encryption_parameters = params['encryption_parameters'] # 整体参数解密 try: params = json.loads(rsa_params_decrypt(encryption_parameters)) except: return create_response(CodeMsg.CM(1022, '参数无效')) # 参数提取,验证完整性 encrypt_seed = params.get('encrypt_seed') if not encrypt_seed or encrypt_seed == '': return create_response(CodeMsg.CM(1022, '参数不完整')) # stellar account result = digiccy_base.bind_compulsory(encrypt_seed) if isinstance(result, CodeMsg.CM): return create_response(result) stellar_address = result # digiccy account bind_secret, bind_address = eos_wallet.create_account() bind_secret = rsaEncryptToken(str(bind_secret)) # 加密 # instert db is_success = digiccy_base.bind_insert(stellar_address, bind_address, bind_secret) if not is_success: return create_response(CodeMsg.BIND_ERROR) return create_response(CodeMsg.SUCCESS)
def post(self): # parser_ = CoverRequestParser() # parser_.add_argument("fee", type=str, required=True) # parser_.add_argument("amount", type=str, required=True) # parser_.add_argument("encrypt_seed", type=str, required=True) # parser_.add_argument("digiccy_address", type=str, required=True) # params = parser_.parse_args() # fee = params['fee'] # amount = params['amount'] # encrypt_seed = params['encrypt_seed'] # digiccy_address = params['digiccy_address'] parser_ = CoverRequestParser() parser_.add_argument("encryption_parameters", type=str, required=True) params = parser_.parse_args() encryption_parameters = params['encryption_parameters'] # 整体参数解密 try: params = json.loads(rsa_params_decrypt(encryption_parameters)) except: return create_response(CodeMsg.CM(1022, '参数无效')) # 参数提取 fee = params.get('fee') amount = params.get('amount') encrypt_seed = params.get('encrypt_seed') digiccy_address = params.get('digiccy_address') google_code = params.get('google_verification_code') # 参数完整性 if not all([fee, amount, encrypt_seed, digiccy_address]): return create_response(CodeMsg.CM(1024, '参数不完整')) # 谷歌验证码 auth = request.headers.get('Authorization') is_success, msg = verify_googleauth(auth, google_code) if not is_success: return create_response(CodeMsg.CM(1023, '验证谷歌验证码失败'), msg=msg) # 校验eth钱包节点是否链接 if not eth_wallet.is_connected(): return create_response(CodeMsg.CM(1019, '节点离线')) # 本地节点是否同步 if eth_wallet.is_syncing(): return create_response(CodeMsg.CM(1020, 'eth节点未同步,请勿执行提现操作')) # 提币地址校验 if not eth_wallet.is_valid_address(digiccy_address): return create_response(CodeMsg.CM(1021, '提币地址无效')) # stellar账户校验,转账 ret = digiccy_base.withdraw_compulsory(encrypt_seed, amount, fee, digiccy_address) if ret.code == CodeMsg.SUCCESS.code: return create_response(CodeMsg.CM(200, '提现成功,最多三个工作日到账,请耐心等待')) else: return create_response(ret)
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)
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)
def post(self): parser_ = CoverRequestParser() parser_.add_argument("encrypt_seed", type=str, required=True) params = parser_.parse_args() encrypt_seed = params['encrypt_seed'] # stellar account result = digiccy_base.bind_compulsory(encrypt_seed) if isinstance(result, CodeMsg.CM): return create_response(result) stellar_address = result # digiccy account bind_address, bind_secret = btc_wallet.create_account(stellar_address) bind_secret = rsaEncryptToken(str(bind_secret)) # 加密 # instert db is_success = digiccy_base.bind_insert(stellar_address, bind_address, bind_secret) if not is_success: return create_response(CodeMsg.BIND_ERROR) return create_response(CodeMsg.SUCCESS)
def get(self): parser_ = CoverRequestParser() parser_.add_argument("coin_name", type=str, required=True) params = parser_.parse_args() coin_name = params.get("coin_name") coin_name = coin_name.upper() 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 not in coin_types: return create_response(CodeMsg.CM(1031, '币种名错误')) coin_name = coin_name.upper() try: amount_limit = get_coin_limit() except Exception as e: logging.error('find amount limit error:{}'.format(e)) return create_response(CodeMsg.CM(1030, '查询限额失败')) coin_limit = amount_limit.get(coin_name) if coin_limit is None: return create_response(CodeMsg.CM(1030, '币种名称错误')) return create_response(CodeMsg.CM(200, '查询限额成功'), data=coin_limit)
def get(self): parser_ = CoverRequestParser() parser_.add_argument("chain_type", type=int, required=True) parser_.add_argument("coin_name", type=str, required=True) params = parser_.parse_args() chain_type = params['chain_type'] coin_name = params.get('coin_name') base_balance = None 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 not in coin_types: return create_response(CodeMsg.CM(1031, '币种名错误')) if chain_type not in (1, 2): return create_response(CodeMsg.CM(1031, '链类型错误')) if chain_type == 2: base_address = consul_clinet.get_digiccy_base_account( coin_name, is_seed=False) wallet_str = "{}_wallet".format(coin_name.lower()) wallet = getattr(app, wallet_str) try: base_balance = wallet.get_balance(base_address) print("-----------------", base_balance) except Exception as e: return create_response(CodeMsg.CM(1030, '链外余额查询错误')) else: stellar_address = consul_clinet.get_stellar_base_account( coin_name, is_seed=False) stellar_node = app.stellar_service.stellar_node() url = stellar_node + '/accounts/{}'.format(stellar_address) try: response = requests.get(url).json() balances = response.get('balances') for balance_info in balances: if balance_info.get("asset_code") == coin_name: base_balance = balance_info.get("balance") break except Exception as e: return create_response(CodeMsg.CM(1030, '链内余额查询错误')) if base_balance is None: return create_response(CodeMsg.CM(1030, '余额查询错误')) base_balance = str(base_balance) return create_response(CodeMsg.CM(200, '余额查询成功'), data=base_balance)
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)
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)
def post(self): parser_ = CoverRequestParser() parser_.add_argument("encryption_parameters", type=str, required=True) parser_.add_argument("coin_name", type=str, required=True) params = parser_.parse_args() encryption_parameters = params['encryption_parameters'] coin_name = params.get('coin_name') # 整体参数解密 try: params = json.loads(rsa_params_decrypt(encryption_parameters)) except: return create_response(CodeMsg.CM(1022, '参数无效')) fee = params.get('fee') amount = params.get('amount') encrypt_seed = params.get('encrypt_seed') digiccy_address = params.get('digiccy_address') google_code = params.get('google_verification_code') # 参数完整性 if not all([fee, amount, encrypt_seed, digiccy_address, coin_name]): return create_response(CodeMsg.CM(1024, '参数不完整')) 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, '币种名错误')) # 谷歌验证码 # auth = request.headers.get('Authorization') # is_success, msg = verify_googleauth(auth, google_code) # if not is_success: # return create_response(CodeMsg.CM(1023, '验证谷歌验证码失败'), msg=msg) wallet_str = "{}_wallet".format(coin_name.lower()) wallet = getattr(app, wallet_str) # 校验eth钱包节点是否链接 if not wallet.is_connected(): return create_response(CodeMsg.CM(1019, '节点离线')) # 本地节点是否同步 if wallet.is_syncing(): return create_response(CodeMsg.CM(1020, 'eth节点未同步,请勿执行提现操作')) # 提币地址校验 if not wallet.is_valid_address(digiccy_address): return create_response(CodeMsg.CM(1021, '提币地址无效')) digiccy_base = DigiccyBase(coin_name) ret = digiccy_base.audit_compulsory(encrypt_seed, amount, fee) if isinstance(ret, CodeMsg.CM): return create_response(ret) stellar_address = ret order_auditor_id = str(uuid.uuid1()) order_auditor = OrderAuditor(id=order_auditor_id, stellar_account=stellar_address, coin_name=coin_name, amount=amount, data=encryption_parameters, status=1) db.session.add(order_auditor) try: db.session.commit() except Exception as e: logging.error('Db insert order_auditor order error:{}'.format( str(e))) return CodeMsg.CM(1012, '生成审核表出错,请稍后再试!') return create_response(CodeMsg.CM(200, '正在审核'))
def post(self): parser_ = CoverRequestParser() parser_.add_argument("fee", type=str, required=True) parser_.add_argument("amount", type=str, required=True) parser_.add_argument("encrypt_seed", type=str, required=True) parser_.add_argument("digiccy_address", type=str, required=True) params = parser_.parse_args() fee = params['fee'] amount = params['amount'] encrypt_seed = params['encrypt_seed'] digiccy_address = params['digiccy_address'] # 校验btc节点是否链接 if not btc_wallet.is_connected(): return create_response(CodeMsg.CM(1019, 'BTC节点离线')) # 本地节点是否同步 if not btc_wallet.is_sync(): return create_response(CodeMsg.CM(1020, 'BTC节点未同步,请勿执行提现操作')) # 提币地址校验 if not btc_wallet.is_valid_address(digiccy_address): return create_response(CodeMsg.CM(1021, '提币地址无效')) # stellar账户校验,转账 ret = digiccy_base.withdraw_compulsory(encrypt_seed, amount, fee, digiccy_address) if ret.code == CodeMsg.SUCCESS.code: return create_response(CodeMsg.CM(200, '提现成功,最多三个工作日到账,请耐心等待')) else: return create_response(ret)