Commit 91480b21 authored by confusion's avatar confusion

修改node

parent 201d1562
...@@ -27,9 +27,9 @@ async def subscribe( ...@@ -27,9 +27,9 @@ 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 = await beacon_service.get_validator(indexOrPubkey=create_node.pub_key) node_detail_list = await beacon_service.get_validator(index_or_pubkey=create_node.pub_key)
assert node_detail, "节点不存在,绑定失败" assert node_detail_list, "节点不存在,绑定失败"
db_data = BaseNode(**create_node.dict(), index=node_detail.validatorindex) db_data = BaseNode(**create_node.dict(), index=node_detail_list[0].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,8 +75,9 @@ async def get_node_info( ...@@ -75,8 +75,9 @@ 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 = await beacon_service.get_validator(pub_key) validator_detail_list = await beacon_service.get_validator(pub_key)
response = Response[Validator](data=validator_detail) assert validator_detail_list, NotFundError()
response = Response[Validator](data=validator_detail_list[0])
return response return response
...@@ -97,8 +98,8 @@ async def get_node_deposit( ...@@ -97,8 +98,8 @@ async def get_node_deposit(
"nodes": {"$elemMatch": {"pub_key": pub_key}} "nodes": {"$elemMatch": {"pub_key": pub_key}}
}) })
assert fund, NotFundError() assert fund, NotFundError()
validator_deposit = await beacon_service.get_validator_deposit(pub_key) validator_deposit_list = await beacon_service.get_validator_deposit(pub_key)
response = Response[List[ValidatorDeposit]](data=validator_deposit) response = Response[List[ValidatorDeposit]](data=validator_deposit_list)
return response return response
...@@ -106,7 +107,7 @@ async def get_node_deposit( ...@@ -106,7 +107,7 @@ async def get_node_deposit(
"/validator/blocks/{index}/", "/validator/blocks/{index}/",
response_model=PageResponse[ValidatorBlock], response_model=PageResponse[ValidatorBlock],
summary="查询节点blocks", description="") summary="查询节点blocks", description="")
async def node_get_validator_deposit( async def get_node_blocks(
fund_id: str, fund_id: str,
pub_key: str, pub_key: str,
user: User = Depends(dependencies.get_current_user), user: User = Depends(dependencies.get_current_user),
...@@ -127,19 +128,14 @@ async def node_get_validator_deposit( ...@@ -127,19 +128,14 @@ async def node_get_validator_deposit(
start=start, start=start,
length=page.page_size length=page.page_size
) )
response = PageResponse[ValidatorBlock]( return PageResponse[ValidatorBlock](data=validator_blocks.data, **page.dict(), total=validator_blocks.total)
data=validator_blocks.data,
**page.dict(),
total=validator_blocks.total
)
return response
@router.get( @router.get(
"/validator/income/{pub_key}/", "/validator/income/{pub_key}/",
response_model=Response[ValidatorIncome], response_model=Response[ValidatorIncome],
summary="查询节点收益", description="") summary="查询节点收益", description="")
async def node_get_validator_deposit( async def get_node_income(
fund_id: str, fund_id: str,
pub_key: str, pub_key: str,
user: User = Depends(dependencies.get_current_user), user: User = Depends(dependencies.get_current_user),
...@@ -152,7 +148,7 @@ async def node_get_validator_deposit( ...@@ -152,7 +148,7 @@ async def node_get_validator_deposit(
"nodes": {"$elemMatch": {"pub_key": pub_key}} "nodes": {"$elemMatch": {"pub_key": pub_key}}
}) })
assert fund, NotFundError() assert fund, NotFundError()
validator_income = await beacon_service.get_validator_income(indexOrPubkey=pub_key) validator_income_list = await beacon_service.get_validator_income(index_or_pubkey=pub_key)
assert validator_income, "没有查到收益" assert validator_income_list, NotFundError()
response = Response[ValidatorIncome](data=validator_income[0]) response = Response[ValidatorIncome](data=validator_income_list[0])
return response return response
...@@ -3,18 +3,18 @@ from pydantic import BaseModel, Field ...@@ -3,18 +3,18 @@ from pydantic import BaseModel, Field
class Validator(BaseModel): class Validator(BaseModel):
"""质押基本信息""" """质押基本信息"""
activationeligibilityepoch: int = Field(None, title="激活合格编号") activation_eligibility_epoch: int = Field(None, title="激活合格编号")
activationepoch: int = Field(None, title="激活编号") activation_epoch: int = Field(None, title="激活编号")
validatorindex: int = Field(None, title="节点编号") validator_index: int = Field(None, title="节点编号")
pubkey: str = Field(None, title="pubkey") pubkey: str = Field(None, title="pubkey")
balance: int = Field(None, title="余额") balance: int = Field(None, title="余额")
effectivebalance: int = Field(None, title="实际余额") effective_balance: int = Field(None, title="实际余额")
exitepoch: int = Field(None, title="") exit_epoch: int = Field(None, title="")
lastattestationslot: int = Field(None, title="") last_attestation_slot: int = Field(None, title="")
slashed: bool = Field(None, title="") slashed: bool = Field(None, title="")
status: str = Field(None, title="") status: str = Field(None, title="")
withdrawableepoch: int = Field(None, title="") withdraw_able_epoch: int = Field(None, title="")
withdrawalcredentials: str = Field(None, title="") withdrawal_credentials: str = Field(None, title="")
class ValidatorDeposit(BaseModel): class ValidatorDeposit(BaseModel):
...@@ -54,4 +54,4 @@ class ValidatorIncome(BaseModel): ...@@ -54,4 +54,4 @@ class ValidatorIncome(BaseModel):
performance31d: float = Field(None, title="31日收益") performance31d: float = Field(None, title="31日收益")
performance365d: float = Field(None, title="年收益") performance365d: float = Field(None, title="年收益")
rank7d: int = Field(None, title="7日排名") rank7d: int = Field(None, title="7日排名")
validatorindex: int = Field(None, title="节点编号") validator_index: int = Field(None, title="节点编号")
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
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