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
c35c5a76
Commit
c35c5a76
authored
Apr 03, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
判断节点用正则
parent
01a8c82e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
node.py
api/node.py
+8
-11
No files found.
api/node.py
View file @
c35c5a76
from
typing
import
List
from
motor.core
import
AgnosticCollection
from
pydantic
import
Field
import
dependencies
from
exception.api
import
APIError
from
exception.db
import
ExistDataError
,
NotFundError
from
exception.http
import
RequestInvalidParamsError
from
model
import
BaseResponse
,
Response
,
PageResponse
,
Page
from
fastapi
import
APIRouter
,
Depends
from
fastapi
import
APIRouter
,
Depends
,
Query
from
model.fund
import
FundType
from
model.node
import
BaseNode
...
...
@@ -29,7 +30,6 @@ async def subscribe(
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
):
assert
str_not_numbers
(
bind_node
.
pub_key
),
RequestInvalidParamsError
()
node_detail
=
await
beacon_service
.
get_validator
(
index_or_pubkey
=
bind_node
.
pub_key
)
db_data
=
BaseNode
(
**
bind_node
.
dict
(),
index
=
node_detail
.
validator_index
)
# 限制staking基金才可绑定节点
...
...
@@ -50,7 +50,8 @@ async def subscribe(
@
router
.
delete
(
'/'
,
response_model
=
BaseResponse
,
summary
=
'解绑节点'
,
description
=
'解绑节点'
)
async
def
unsubscribe
(
fund_id
:
str
,
pub_key
:
str
,
# pub_key: str = Query(regex=r"\d*[a-zA-Z]+\d*"),
pub_key
:
str
=
Query
(
regex
=
r".*\D+"
),
user
:
User
=
Depends
(
dependencies
.
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
...
...
@@ -68,12 +69,11 @@ async def unsubscribe(
@
router
.
get
(
"/info/{pub_key}/"
,
response_model
=
Response
[
Validator
],
summary
=
"查询节点详情"
,
description
=
""
)
async
def
get_node_info
(
fund_id
:
str
,
pub_key
:
str
,
pub_key
:
str
=
Query
(
regex
=
r".*\D+"
)
,
user
:
User
=
Depends
(
dependencies
.
get_current_user
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
...
...
@@ -88,12 +88,11 @@ async def get_node_info(
summary
=
"查询节点充值记录"
,
description
=
""
)
async
def
get_node_deposit
(
fund_id
:
str
,
pub_key
:
str
,
pub_key
:
str
=
Query
(
regex
=
r".*\D+"
)
,
user
:
User
=
Depends
(
dependencies
.
get_current_user
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
...
...
@@ -108,13 +107,12 @@ async def get_node_deposit(
summary
=
"查询节点blocks"
,
description
=
""
)
async
def
get_node_blocks
(
fund_id
:
str
,
pub_key
:
str
,
pub_key
:
str
=
Query
(
regex
=
r".*\D+"
)
,
user
:
User
=
Depends
(
dependencies
.
get_current_user
),
page
:
Page
=
Depends
(
Page
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
start
=
(
page
.
page
-
1
)
*
page
.
page_size
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
fund
=
await
fund_collect
.
find_one
(
query
)
...
...
@@ -133,12 +131,11 @@ async def get_node_blocks(
summary
=
"查询节点收益"
,
description
=
""
)
async
def
get_node_income
(
fund_id
:
str
,
pub_key
:
str
,
pub_key
:
str
=
Query
(
regex
=
r".*\D+"
)
,
user
:
User
=
Depends
(
dependencies
.
get_current_user
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
...
...
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