Commit 7d3ec615 authored by 陈涛's avatar 陈涛

修改beacon接口返回变更引起的bug

parent fc0031f9
...@@ -27,9 +27,11 @@ async def subscribe( ...@@ -27,9 +27,11 @@ async def subscribe(
fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect), fund_collect: AgnosticCollection = Depends(dependencies.get_fund_collect),
beacon_service: BeaconChaService = Depends(BeaconChaService) beacon_service: BeaconChaService = Depends(BeaconChaService)
): ):
node_detail_list = await beacon_service.get_validator(index_or_pubkey=create_node.pub_key) node_detail = await beacon_service.get_validator(index_or_pubkey=create_node.pub_key)
assert node_detail_list, "节点不存在,绑定失败" assert node_detail, "节点不存在,绑定失败"
db_data = BaseNode(**create_node.dict(), index=node_detail_list[0].validator_index) if not isinstance(node_detail, Validator):
node_detail = node_detail[0]
db_data = BaseNode(**create_node.dict(), index=node_detail.validator_index)
# 限制staking基金才可绑定节点 # 限制staking基金才可绑定节点
query = {'id': create_node.fund_id, 'user_id': user.id, 'fund_type': FundType.staking} query = {'id': create_node.fund_id, 'user_id': user.id, 'fund_type': FundType.staking}
res = await fund_collect.update_one( res = await fund_collect.update_one(
...@@ -75,9 +77,11 @@ async def get_node_info( ...@@ -75,9 +77,11 @@ async def get_node_info(
"nodes": {"$elemMatch": {"pub_key": pub_key}} "nodes": {"$elemMatch": {"pub_key": pub_key}}
}) })
assert fund, NotFundError() assert fund, NotFundError()
validator_detail_list = await beacon_service.get_validator(pub_key) validator_detail = await beacon_service.get_validator(pub_key)
assert validator_detail_list, NotFundError() if not isinstance(validator_detail, Validator):
response = Response[Validator](data=validator_detail_list[0]) validator_detail = validator_detail[0]
assert validator_detail, NotFundError()
response = Response[Validator](data=validator_detail)
return response return response
......
...@@ -61,24 +61,43 @@ class BeaconChaService: ...@@ -61,24 +61,43 @@ class BeaconChaService:
assert response["status"] == "OK", RequestHttpException() assert response["status"] == "OK", RequestHttpException()
return response return response
async def get_validator(self, index_or_pubkey: Union[int, str]) -> List[Validator]: async def get_validator(self, index_or_pubkey: Union[int, str]) -> Union[Validator, List[Validator]]:
"""获取质押信息""" """获取质押信息"""
url = f"{self.base_url}/api/v1/validator/{index_or_pubkey}" url = f"{self.base_url}/api/v1/validator/{index_or_pubkey}"
response = await self.service_request(url) response = await self.service_request(url)
return [Validator( if isinstance(response["data"], dict):
activation_eligibility_epoch=item["activationeligibilityepoch"], result = Validator(
activation_epoch=item["activationepoch"], activation_eligibility_epoch=response["data"]["activationeligibilityepoch"],
validator_index=item["validatorindex"], activation_epoch=response["data"]["activationepoch"],
pubkey=item["pubkey"], validator_index=response["data"]["validatorindex"],
balance=item["balance"] / self.eth_decimal, pubkey=response["data"]["pubkey"],
effective_balance=item["effectivebalance"] / self.eth_decimal, balance=response["data"]["balance"] / self.eth_decimal,
exit_epoch=item["exitepoch"], effective_balance=response["data"]["effectivebalance"] / self.eth_decimal,
last_attestation_slot=item["lastattestationslot"], exit_epoch=response["data"]["exitepoch"],
slashed=item["slashed"], last_attestation_slot=response["data"]["lastattestationslot"],
status=item["status"], slashed=response["data"]["slashed"],
withdraw_able_epoch=item["withdrawableepoch"], status=response["data"]["status"],
withdrawal_credentials=item["withdrawalcredentials"], withdraw_able_epoch=response["data"]["withdrawableepoch"],
) for item in response["data"]] withdrawal_credentials=response["data"]["withdrawalcredentials"],
)
elif isinstance(response["data"], list):
result = [Validator(
activation_eligibility_epoch=item["activationeligibilityepoch"],
activation_epoch=item["activationepoch"],
validator_index=item["validatorindex"],
pubkey=item["pubkey"],
balance=item["balance"] / self.eth_decimal,
effective_balance=item["effectivebalance"] / self.eth_decimal,
exit_epoch=item["exitepoch"],
last_attestation_slot=item["lastattestationslot"],
slashed=item["slashed"],
status=item["status"],
withdraw_able_epoch=item["withdrawableepoch"],
withdrawal_credentials=item["withdrawalcredentials"],
) for item in response["data"]]
else:
raise RequestHttpException()
return result
async def get_validator_deposit(self, index_or_pubkey: Union[int, str]): async def get_validator_deposit(self, index_or_pubkey: Union[int, str]):
"""获取质押信息""" """获取质押信息"""
......
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