Commit f8f73509 authored by 陈涛's avatar 陈涛

修改pubkey的bug

parent 1b885c1d
...@@ -31,23 +31,23 @@ async def subscribe( ...@@ -31,23 +31,23 @@ async def subscribe(
): ):
try: try:
int(bind_node.pub_key) int(bind_node.pub_key)
except Exception as e:
raise RequestInvalidParamsError() raise RequestInvalidParamsError()
node_detail = await beacon_service.get_validator(index_or_pubkey=bind_node.pub_key) except Exception as e:
db_data = BaseNode(**bind_node.dict(), index=node_detail.validator_index) node_detail = await beacon_service.get_validator(index_or_pubkey=bind_node.pub_key)
# 限制staking基金才可绑定节点 db_data = BaseNode(**bind_node.dict(), index=node_detail.validator_index)
# 限制staking基金才可绑定节点
query = {'id': bind_node.fund_id, 'user_id': user.id, 'fund_type': FundType.staking, query = {'id': bind_node.fund_id, 'user_id': user.id, 'fund_type': FundType.staking,
f"nodes.{bind_node.pub_key}": {'$exists': False}} f"nodes.{bind_node.pub_key}": {'$exists': False}}
update = {"$set": {f"nodes.{bind_node.pub_key}": db_data.dict()}} update = {"$set": {f"nodes.{bind_node.pub_key}": db_data.dict()}}
res = await fund_collect.update_one( res = await fund_collect.update_one(
query, query,
update update
) )
if res.raw_result['nModified'] == 0: if res.raw_result['nModified'] == 0:
raise ExistDataError(message='节点已存在') raise ExistDataError(message='节点已存在')
return BaseResponse(data='绑定成功') return BaseResponse(data='绑定成功')
@router.delete('/', response_model=BaseResponse, summary='解绑节点', description='解绑节点') @router.delete('/', response_model=BaseResponse, summary='解绑节点', description='解绑节点')
...@@ -78,14 +78,14 @@ async def get_node_info( ...@@ -78,14 +78,14 @@ async def get_node_info(
): ):
try: try:
int(pub_key) int(pub_key)
except Exception as e:
raise RequestInvalidParamsError() raise RequestInvalidParamsError()
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}} except Exception as e:
fund = await fund_collect.find_one(query) query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
assert fund, NotFundError('未绑定该节点') fund = await fund_collect.find_one(query)
validator_detail = await beacon_service.get_validator(pub_key) assert fund, NotFundError('未绑定该节点')
response = Response[Validator](data=validator_detail) validator_detail = await beacon_service.get_validator(pub_key)
return response response = Response[Validator](data=validator_detail)
return response
@router.get( @router.get(
...@@ -101,14 +101,14 @@ async def get_node_deposit( ...@@ -101,14 +101,14 @@ async def get_node_deposit(
): ):
try: try:
int(pub_key) int(pub_key)
except Exception as e:
raise RequestInvalidParamsError() raise RequestInvalidParamsError()
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}} except Exception as e:
fund = await fund_collect.find_one(query) query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
assert fund, NotFundError('未绑定该节点') fund = await fund_collect.find_one(query)
validator_deposit_list = await beacon_service.get_validator_deposit(pub_key) assert fund, NotFundError('未绑定该节点')
response = Response[List[ValidatorDeposit]](data=validator_deposit_list) validator_deposit_list = await beacon_service.get_validator_deposit(pub_key)
return response response = Response[List[ValidatorDeposit]](data=validator_deposit_list)
return response
@router.get( @router.get(
...@@ -125,18 +125,18 @@ async def get_node_blocks( ...@@ -125,18 +125,18 @@ async def get_node_blocks(
): ):
try: try:
int(pub_key) int(pub_key)
except Exception as e:
raise RequestInvalidParamsError() raise RequestInvalidParamsError()
start = (page.page - 1) * page.page_size except Exception as e:
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}} start = (page.page - 1) * page.page_size
fund = await fund_collect.find_one(query) query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
assert fund, NotFundError('未绑定该节点') fund = await fund_collect.find_one(query)
validator_blocks = await beacon_service.get_validator_blocks( assert fund, NotFundError('未绑定该节点')
index=fund["nodes"][pub_key]["index"], validator_blocks = await beacon_service.get_validator_blocks(
start=start, index=fund["nodes"][pub_key]["index"],
length=page.page_size start=start,
) length=page.page_size
return PageResponse[ValidatorBlock](data=validator_blocks.data, **page.dict(), total=validator_blocks.total) )
return PageResponse[ValidatorBlock](data=validator_blocks.data, **page.dict(), total=validator_blocks.total)
@router.get( @router.get(
...@@ -152,15 +152,15 @@ async def get_node_income( ...@@ -152,15 +152,15 @@ async def get_node_income(
): ):
try: try:
int(pub_key) int(pub_key)
except Exception as e:
raise RequestInvalidParamsError() raise RequestInvalidParamsError()
query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}} except Exception as e:
fund = await fund_collect.find_one(query) query = {'id': fund_id, 'user_id': user.id, 'fund_type': FundType.staking, f"nodes.{pub_key}": {"$exists": True}}
assert fund, NotFundError('未绑定该节点') fund = await fund_collect.find_one(query)
validator_income_list = await beacon_service.get_validator_income(index_or_pubkey=pub_key) assert fund, NotFundError('未绑定该节点')
assert validator_income_list, NotFundError() validator_income_list = await beacon_service.get_validator_income(index_or_pubkey=pub_key)
response = Response[ValidatorIncome](data=validator_income_list[0]) assert validator_income_list, NotFundError()
return response response = Response[ValidatorIncome](data=validator_income_list[0])
return response
@router.get("/epoch/{epoch}/", response_model=Response[Epoch], summary="查询epoch", description="") @router.get("/epoch/{epoch}/", response_model=Response[Epoch], summary="查询epoch", description="")
......
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