Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PyFund
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈涛
PyFund
Commits
7d3ec615
Commit
7d3ec615
authored
Mar 29, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改beacon接口返回变更引起的bug
parent
fc0031f9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
21 deletions
+44
-21
node.py
api/node.py
+10
-6
beacon.py
service/beacon.py
+34
-15
No files found.
api/node.py
View file @
7d3ec615
...
@@ -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
...
...
service/beacon.py
View file @
7d3ec615
...
@@ -61,11 +61,27 @@ class BeaconChaService:
...
@@ -61,11 +61,27 @@ 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
):
result
=
Validator
(
activation_eligibility_epoch
=
response
[
"data"
][
"activationeligibilityepoch"
],
activation_epoch
=
response
[
"data"
][
"activationepoch"
],
validator_index
=
response
[
"data"
][
"validatorindex"
],
pubkey
=
response
[
"data"
][
"pubkey"
],
balance
=
response
[
"data"
][
"balance"
]
/
self
.
eth_decimal
,
effective_balance
=
response
[
"data"
][
"effectivebalance"
]
/
self
.
eth_decimal
,
exit_epoch
=
response
[
"data"
][
"exitepoch"
],
last_attestation_slot
=
response
[
"data"
][
"lastattestationslot"
],
slashed
=
response
[
"data"
][
"slashed"
],
status
=
response
[
"data"
][
"status"
],
withdraw_able_epoch
=
response
[
"data"
][
"withdrawableepoch"
],
withdrawal_credentials
=
response
[
"data"
][
"withdrawalcredentials"
],
)
elif
isinstance
(
response
[
"data"
],
list
):
result
=
[
Validator
(
activation_eligibility_epoch
=
item
[
"activationeligibilityepoch"
],
activation_eligibility_epoch
=
item
[
"activationeligibilityepoch"
],
activation_epoch
=
item
[
"activationepoch"
],
activation_epoch
=
item
[
"activationepoch"
],
validator_index
=
item
[
"validatorindex"
],
validator_index
=
item
[
"validatorindex"
],
...
@@ -79,6 +95,9 @@ class BeaconChaService:
...
@@ -79,6 +95,9 @@ class BeaconChaService:
withdraw_able_epoch
=
item
[
"withdrawableepoch"
],
withdraw_able_epoch
=
item
[
"withdrawableepoch"
],
withdrawal_credentials
=
item
[
"withdrawalcredentials"
],
withdrawal_credentials
=
item
[
"withdrawalcredentials"
],
)
for
item
in
response
[
"data"
]]
)
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
]):
"""获取质押信息"""
"""获取质押信息"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment