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
f0eaf49b
Commit
f0eaf49b
authored
Jun 13, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加收益接口,收益历史接口
parent
a3d3346d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
5 deletions
+69
-5
node.py
api/node.py
+32
-2
requirements.txt
requirements.txt
+5
-1
beacon.py
schema/beacon.py
+6
-0
beacon.py
service/beacon.py
+26
-2
No files found.
api/node.py
View file @
f0eaf49b
from
typing
import
List
import
requests
from
motor.core
import
AgnosticCollection
import
dependencies
...
...
@@ -10,7 +10,7 @@ from fastapi import APIRouter, Depends, Query
from
model.fund
import
FundType
from
model.node
import
BaseNode
from
schema.beacon
import
Validator
,
ValidatorDeposit
,
ValidatorBlock
,
ValidatorIncome
,
Epoch
from
schema.beacon
import
Validator
,
ValidatorDeposit
,
ValidatorBlock
,
ValidatorIncome
,
Epoch
,
Rewards
from
schema.node
import
BindNode
from
service.beacon
import
BeaconChaService
from
tools.jwt_tools
import
User
...
...
@@ -163,3 +163,33 @@ async def get_epoch(
epoch
=
await
beacon_service
.
get_epoch
(
epoch
)
response
=
Response
[
Epoch
](
data
=
epoch
)
return
response
@
router
.
get
(
"/consensus/income/"
,
response_model
=
Response
[
list
],
summary
=
"查询cl收益"
,
description
=
""
)
async
def
income_history
(
index
:
str
,
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
)
):
result
=
beacon_service
.
get_income_history
(
index
)
response
=
Response
(
data
=
result
)
return
response
@
router
.
get
(
"/execute/income/"
,
response_model
=
Response
[
list
],
summary
=
"查询el收益"
,
description
=
""
)
async
def
income_history
(
index
:
str
,
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
)
):
result
=
beacon_service
.
get_execute_income_history
(
index
)
response
=
Response
(
data
=
result
)
return
response
@
router
.
get
(
"/rewards/"
,
response_model
=
Response
[
Rewards
],
summary
=
"收益"
,
description
=
""
)
async
def
get_rewards
(
index_or_pubkey
:
str
,
beacon_service
:
BeaconChaService
=
Depends
(
BeaconChaService
)
):
rewards
=
beacon_service
.
get_rewards
(
index_or_pubkey
)
response
=
Response
(
data
=
rewards
.
dict
())
return
response
requirements.txt
View file @
f0eaf49b
...
...
@@ -12,4 +12,8 @@ cryptography==39.0.2
pymongo
~=4.3.3
httpx
~=0.23.3
APScheduler
~=3.10.1
aiofiles
==23.1.0
\ No newline at end of file
aiofiles
==23.1.0
requests
~=2.29.0
numpy
~=1.24.3
Pillow
~=9.5.0
lxml
~=4.9.2
\ No newline at end of file
schema/beacon.py
View file @
f0eaf49b
...
...
@@ -67,3 +67,9 @@ class Epoch(BaseModel):
total_validator_balance
:
float
=
Field
(
None
,
title
=
"节点总计余额"
)
ts
:
int
=
Field
(
None
,
title
=
"时间"
)
finalized
:
bool
=
Field
(
None
,
title
=
"结果"
)
class
Rewards
(
BaseModel
):
cl
:
str
el
:
str
total
:
str
service/beacon.py
View file @
f0eaf49b
...
...
@@ -3,11 +3,13 @@ import re
import
time
from
typing
import
List
,
Union
import
requests
from
lxml
import
etree
from
pydantic
import
BaseModel
,
Field
from
exception.db
import
NotFundError
from
exception.http
import
RequestHttpException
from
schema.beacon
import
Validator
,
ValidatorDeposit
,
ValidatorBlock
,
ValidatorIncome
,
Epoch
from
schema.beacon
import
Validator
,
ValidatorDeposit
,
ValidatorBlock
,
ValidatorIncome
,
Epoch
,
Rewards
from
tools.http_helper
import
aio_request
from
tools.time_helper
import
time_str_to_timestamp
...
...
@@ -128,7 +130,7 @@ class BeaconChaService:
)
for
item
in
response
[
"data"
]]
async
def
get_validator_blocks
(
self
,
index
:
int
,
start
:
int
=
0
,
length
:
int
=
10
)
->
ValidatorBlocks
:
url
=
f
"
https://beaconcha.in
/validator/{index}/proposedblocks?draw=1&columns
%5
B0
%5
D
%5
Bdata
%5
D=0&columns
%5
B0
%5
D
%5
Bname
%5
D=&columns
%5
B0
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B0
%5
D
%5
Borderable
%5
D=true&columns
%5
B0
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B0
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B1
%5
D
%5
Bdata
%5
D=1&columns
%5
B1
%5
D
%5
Bname
%5
D=&columns
%5
B1
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B1
%5
D
%5
Borderable
%5
D=false&columns
%5
B1
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B1
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B2
%5
D
%5
Bdata
%5
D=2&columns
%5
B2
%5
D
%5
Bname
%5
D=&columns
%5
B2
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B2
%5
D
%5
Borderable
%5
D=true&columns
%5
B2
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B2
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B3
%5
D
%5
Bdata
%5
D=3&columns
%5
B3
%5
D
%5
Bname
%5
D=&columns
%5
B3
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B3
%5
D
%5
Borderable
%5
D=false&columns
%5
B3
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B3
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B4
%5
D
%5
Bdata
%5
D=4&columns
%5
B4
%5
D
%5
Bname
%5
D=&columns
%5
B4
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B4
%5
D
%5
Borderable
%5
D=false&columns
%5
B4
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B4
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B5
%5
D
%5
Bdata
%5
D=5&columns
%5
B5
%5
D
%5
Bname
%5
D=&columns
%5
B5
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B5
%5
D
%5
Borderable
%5
D=true&columns
%5
B5
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B5
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B6
%5
D
%5
Bdata
%5
D=6&columns
%5
B6
%5
D
%5
Bname
%5
D=&columns
%5
B6
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B6
%5
D
%5
Borderable
%5
D=true&columns
%5
B6
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B6
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B7
%5
D
%5
Bdata
%5
D=7&columns
%5
B7
%5
D
%5
Bname
%5
D=&columns
%5
B7
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B7
%5
D
%5
Borderable
%5
D=false&columns
%5
B7
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B7
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B8
%5
D
%5
Bdata
%5
D=8&columns
%5
B8
%5
D
%5
Bname
%5
D=&columns
%5
B8
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B8
%5
D
%5
Borderable
%5
D=true&columns
%5
B8
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B8
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B9
%5
D
%5
Bdata
%5
D=9&columns
%5
B9
%5
D
%5
Bname
%5
D=&columns
%5
B9
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B9
%5
D
%5
Borderable
%5
D=true&columns
%5
B9
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B9
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&order
%5
B0
%5
D
%5
Bcolumn
%5
D=0&order
%5
B0
%5
D
%5
Bdir
%5
D=desc&start={start}&length={length}&search
%5
Bvalue
%5
D=&search
%5
Bregex
%5
D=false&_={time.time() * 1000}"
url
=
f
"
{self.base_url}
/validator/{index}/proposedblocks?draw=1&columns
%5
B0
%5
D
%5
Bdata
%5
D=0&columns
%5
B0
%5
D
%5
Bname
%5
D=&columns
%5
B0
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B0
%5
D
%5
Borderable
%5
D=true&columns
%5
B0
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B0
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B1
%5
D
%5
Bdata
%5
D=1&columns
%5
B1
%5
D
%5
Bname
%5
D=&columns
%5
B1
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B1
%5
D
%5
Borderable
%5
D=false&columns
%5
B1
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B1
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B2
%5
D
%5
Bdata
%5
D=2&columns
%5
B2
%5
D
%5
Bname
%5
D=&columns
%5
B2
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B2
%5
D
%5
Borderable
%5
D=true&columns
%5
B2
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B2
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B3
%5
D
%5
Bdata
%5
D=3&columns
%5
B3
%5
D
%5
Bname
%5
D=&columns
%5
B3
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B3
%5
D
%5
Borderable
%5
D=false&columns
%5
B3
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B3
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B4
%5
D
%5
Bdata
%5
D=4&columns
%5
B4
%5
D
%5
Bname
%5
D=&columns
%5
B4
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B4
%5
D
%5
Borderable
%5
D=false&columns
%5
B4
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B4
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B5
%5
D
%5
Bdata
%5
D=5&columns
%5
B5
%5
D
%5
Bname
%5
D=&columns
%5
B5
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B5
%5
D
%5
Borderable
%5
D=true&columns
%5
B5
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B5
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B6
%5
D
%5
Bdata
%5
D=6&columns
%5
B6
%5
D
%5
Bname
%5
D=&columns
%5
B6
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B6
%5
D
%5
Borderable
%5
D=true&columns
%5
B6
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B6
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B7
%5
D
%5
Bdata
%5
D=7&columns
%5
B7
%5
D
%5
Bname
%5
D=&columns
%5
B7
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B7
%5
D
%5
Borderable
%5
D=false&columns
%5
B7
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B7
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B8
%5
D
%5
Bdata
%5
D=8&columns
%5
B8
%5
D
%5
Bname
%5
D=&columns
%5
B8
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B8
%5
D
%5
Borderable
%5
D=true&columns
%5
B8
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B8
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&columns
%5
B9
%5
D
%5
Bdata
%5
D=9&columns
%5
B9
%5
D
%5
Bname
%5
D=&columns
%5
B9
%5
D
%5
Bsearchable
%5
D=true&columns
%5
B9
%5
D
%5
Borderable
%5
D=true&columns
%5
B9
%5
D
%5
Bsearch
%5
D
%5
Bvalue
%5
D=&columns
%5
B9
%5
D
%5
Bsearch
%5
D
%5
Bregex
%5
D=false&order
%5
B0
%5
D
%5
Bcolumn
%5
D=0&order
%5
B0
%5
D
%5
Bdir
%5
D=desc&start={start}&length={length}&search
%5
Bvalue
%5
D=&search
%5
Bregex
%5
D=false&_={time.time() * 1000}"
response
=
await
aio_request
(
url
)
blocks
=
[
ValidatorBlock
(
epoch
=
re
.
findall
(
r'/epoch/(\d+)">'
,
item
[
0
])[
0
],
...
...
@@ -162,3 +164,25 @@ class BeaconChaService:
finalized
=
response
[
"data"
][
"finalized"
]
)
return
result
def
get_income_history
(
self
,
index_or_pubkey
:
str
):
response
=
requests
.
get
(
f
"{self.base_url}/validator/{index_or_pubkey}"
)
return
eval
(
re
.
findall
(
r'var incomeHistory = \[(.*?)\]'
,
response
.
text
)[
0
])
def
get_execute_income_history
(
self
,
index_or_pubkey
:
str
):
response
=
requests
.
get
(
f
"{self.base_url}/validator/{index_or_pubkey}"
)
return
eval
(
re
.
findall
(
r'var executionIncomeHistory = \[(.*?)\]'
,
response
.
text
)[
0
])
def
get_rewards
(
self
,
index_or_pubkey
:
Union
[
int
,
str
])
->
Rewards
:
response
=
requests
.
get
(
f
"{self.base_url}/validator/{index_or_pubkey}"
)
html
=
response
.
content
# 解析 HTML 页面
tree
=
etree
.
HTML
(
html
)
total_rewards_re
=
tree
.
xpath
(
'/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td/span'
)[
0
]
total_rewards_title
=
total_rewards_re
.
get
(
"title"
)
cl
=
re
.
findall
(
r'CL: <span>(\+[\d\.]+ ETH)</span>'
,
total_rewards_title
)[
0
]
el
=
re
.
findall
(
r'EL: <span>(\+[\d\.]+ ETH)</span>'
,
total_rewards_title
)[
0
]
total_re
=
tree
.
xpath
(
'/html/body/main/div[1]/div[2]/div[2]/div/table/tbody/tr[1]/td/span/b'
)[
0
]
total
=
total_re
.
text
result
=
Rewards
(
cl
=
cl
,
el
=
el
,
total
=
total
)
return
result
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