Commit c35c5a76 authored by 陈涛's avatar 陈涛

判断节点用正则

parent 01a8c82e
from typing import List
from motor.core import AgnosticCollection
from pydantic import Field
import dependencies
from exception.api import APIError
from exception.db import ExistDataError, NotFundError
from exception.http import RequestInvalidParamsError
from model import BaseResponse, Response, PageResponse, Page
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Query
from model.fund import FundType
from model.node import BaseNode
......@@ -29,7 +30,6 @@ async def subscribe(
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect),
beacon_service: BeaconChaService = Depends(BeaconChaService),
):
assert str_not_numbers(bind_node.pub_key), RequestInvalidParamsError()
node_detail = await beacon_service.get_validator(index_or_pubkey=bind_node.pub_key)
db_data = BaseNode(**bind_node.dict(), index=node_detail.validator_index)
# 限制staking基金才可绑定节点
......@@ -50,7 +50,8 @@ async def subscribe(
@router.delete('/', response_model=BaseResponse, summary='解绑节点', description='解绑节点')
async def unsubscribe(
fund_id: str,
pub_key: str,
# pub_key: str = Query(regex=r"\d*[a-zA-Z]+\d*"),
pub_key: str = Query(regex=r".*\D+"),
user: User = Depends(dependencies.get_current_user),
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect)
):
......@@ -68,12 +69,11 @@ async def unsubscribe(
@router.get("/info/{pub_key}/", response_model=Response[Validator], summary="查询节点详情", description="")
async def get_node_info(
fund_id: str,
pub_key: str,
pub_key: str = Query(regex=r".*\D+"),
user: User = Depends(dependencies.get_current_user),
beacon_service: BeaconChaService = Depends(BeaconChaService),
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect)
):
assert str_not_numbers(pub_key), RequestInvalidParamsError()
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
fund = await fund_collect.find_one(query)
assert fund, NotFundError('未绑定该节点')
......@@ -88,12 +88,11 @@ async def get_node_info(
summary="查询节点充值记录", description="")
async def get_node_deposit(
fund_id: str,
pub_key: str,
pub_key: str = Query(regex=r".*\D+"),
user: User = Depends(dependencies.get_current_user),
beacon_service: BeaconChaService = Depends(BeaconChaService),
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect)
):
assert str_not_numbers(pub_key), RequestInvalidParamsError()
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
fund = await fund_collect.find_one(query)
assert fund, NotFundError('未绑定该节点')
......@@ -108,13 +107,12 @@ async def get_node_deposit(
summary="查询节点blocks", description="")
async def get_node_blocks(
fund_id: str,
pub_key: str,
pub_key: str = Query(regex=r".*\D+"),
user: User = Depends(dependencies.get_current_user),
page: Page = Depends(Page),
beacon_service: BeaconChaService = Depends(BeaconChaService),
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect)
):
assert str_not_numbers(pub_key), RequestInvalidParamsError()
start = (page.page - 1) * page.page_size
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
fund = await fund_collect.find_one(query)
......@@ -133,12 +131,11 @@ async def get_node_blocks(
summary="查询节点收益", description="")
async def get_node_income(
fund_id: str,
pub_key: str,
pub_key: str = Query(regex=r".*\D+"),
user: User = Depends(dependencies.get_current_user),
beacon_service: BeaconChaService = Depends(BeaconChaService),
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect)
):
assert str_not_numbers(pub_key), RequestInvalidParamsError()
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
fund = await fund_collect.find_one(query)
assert fund, NotFundError('未绑定该节点')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment