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
513baca8
Commit
513baca8
authored
Apr 03, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
判断节点用正则
parent
f8f73509
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
66 deletions
+58
-66
node.py
api/node.py
+58
-66
No files found.
api/node.py
View file @
513baca8
import
re
from
typing
import
List
from
typing
import
List
from
motor.core
import
AgnosticCollection
from
motor.core
import
AgnosticCollection
import
dependencies
import
dependencies
from
exception.api
import
APIError
from
exception.api
import
APIError
from
exception.db
import
ExistDataError
,
NotFundError
from
exception.db
import
ExistDataError
,
NotFundError
...
@@ -19,6 +18,14 @@ from tools.jwt_tools import User
...
@@ -19,6 +18,14 @@ from tools.jwt_tools import User
router
=
APIRouter
()
router
=
APIRouter
()
def
str_not_numbers
(
string_with_numbers
:
str
)
->
bool
:
flag
=
True
regex_pattern
=
r"^\d+$"
if
re
.
match
(
regex_pattern
,
string_with_numbers
):
flag
=
False
return
flag
@
router
.
post
(
'/'
,
@
router
.
post
(
'/'
,
response_model
=
BaseResponse
,
response_model
=
BaseResponse
,
summary
=
'绑定节点'
,
summary
=
'绑定节点'
,
...
@@ -29,10 +36,7 @@ async def subscribe(
...
@@ -29,10 +36,7 @@ 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
),
):
):
try
:
assert
str_not_numbers
(
bind_node
.
pub_key
),
RequestInvalidParamsError
()
int
(
bind_node
.
pub_key
)
raise
RequestInvalidParamsError
()
except
Exception
as
e
:
node_detail
=
await
beacon_service
.
get_validator
(
index_or_pubkey
=
bind_node
.
pub_key
)
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
)
db_data
=
BaseNode
(
**
bind_node
.
dict
(),
index
=
node_detail
.
validator_index
)
# 限制staking基金才可绑定节点
# 限制staking基金才可绑定节点
...
@@ -76,10 +80,7 @@ async def get_node_info(
...
@@ -76,10 +80,7 @@ async def get_node_info(
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
):
try
:
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
int
(
pub_key
)
raise
RequestInvalidParamsError
()
except
Exception
as
e
:
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
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
)
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
...
@@ -99,10 +100,7 @@ async def get_node_deposit(
...
@@ -99,10 +100,7 @@ async def get_node_deposit(
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
):
try
:
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
int
(
pub_key
)
raise
RequestInvalidParamsError
()
except
Exception
as
e
:
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
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
)
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
...
@@ -123,10 +121,7 @@ async def get_node_blocks(
...
@@ -123,10 +121,7 @@ async def get_node_blocks(
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
):
try
:
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
int
(
pub_key
)
raise
RequestInvalidParamsError
()
except
Exception
as
e
:
start
=
(
page
.
page
-
1
)
*
page
.
page_size
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
}}
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
)
fund
=
await
fund_collect
.
find_one
(
query
)
...
@@ -150,10 +145,7 @@ async def get_node_income(
...
@@ -150,10 +145,7 @@ async def get_node_income(
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
),
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
fund_collect
:
AgnosticCollection
=
Depends
(
dependencies
.
get_fund_collect
)
):
):
try
:
assert
str_not_numbers
(
pub_key
),
RequestInvalidParamsError
()
int
(
pub_key
)
raise
RequestInvalidParamsError
()
except
Exception
as
e
:
query
=
{
'id'
:
fund_id
,
'user_id'
:
user
.
id
,
'fund_type'
:
FundType
.
staking
,
f
"nodes.{pub_key}"
:
{
"$exists"
:
True
}}
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
)
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
(
'未绑定该节点'
)
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