Commit 91480b21 authored by confusion's avatar confusion

修改node

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