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
51af1633
Commit
51af1633
authored
Mar 24, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交查询pubkey相关接口
parent
daecbead
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
150 additions
and
0 deletions
+150
-0
beaconcha.py
service/beaconcha.py
+150
-0
No files found.
service/beaconcha.py
0 → 100644
View file @
51af1633
import
datetime
import
re
import
json
import
time
from
typing
import
List
,
Union
from
pydantic
import
BaseModel
,
Field
from
configs
import
settings
# from bs4 import BeautifulSoup as bs
from
tools.http_helper
import
aio_request
class
ValidatorBlock
(
BaseModel
):
epoch
:
int
=
Field
(
None
,
title
=
"epoch"
)
slot
:
int
=
Field
(
None
,
title
=
"slot"
)
status
:
str
=
Field
(
None
,
title
=
"status"
)
timestamp
:
int
=
Field
(
None
,
title
=
"timestamp"
)
root_hash
:
str
=
Field
(
None
,
title
=
"root_hash"
)
att
:
int
=
Field
(
None
,
title
=
"att"
)
dep
:
int
=
Field
(
None
,
title
=
"dep"
)
proposers
:
str
=
Field
(
None
,
title
=
"proposers"
)
ex
:
int
=
Field
(
None
,
title
=
"ex"
)
class
ValidatorBlocks
(
BaseModel
):
total
:
int
=
Field
(
None
,
title
=
"total"
)
data
:
List
[
ValidatorBlock
]
=
Field
(
None
,
title
=
"data"
)
class
BeaconChaService
:
base_url
=
settings
.
beaconcha_url
api_key
=
"STVubDVzdkxxRGMvZ2E4cTc0TlZP"
start_date
=
datetime
.
datetime
(
year
=
2020
,
month
=
12
,
day
=
1
)
deposit_abi
=
{
"inputs"
:
[
{
"internalType"
:
"bytes"
,
"name"
:
"pubkey"
,
"type"
:
"bytes"
},
{
"internalType"
:
"bytes"
,
"name"
:
"withdrawal_credentials"
,
"type"
:
"bytes"
},
{
"internalType"
:
"bytes"
,
"name"
:
"signature"
,
"type"
:
"bytes"
},
{
"internalType"
:
"bytes32"
,
"name"
:
"deposit_data_root"
,
"type"
:
"bytes32"
}
],
"name"
:
"deposit"
,
"outputs"
:
[],
"stateMutability"
:
"payable"
,
"type"
:
"function"
}
headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36'
,
'Content-Type'
:
'application/json'
,
'Accept'
:
'application/json'
,
}
async
def
get_validator
(
self
,
indexOrPubkey
:
Union
[
int
,
str
]):
"""获取质押信息"""
url
=
f
"{self.base_url}/api/v1/validator/{indexOrPubkey}"
response
=
await
aio_request
(
url
=
url
,
method
=
"GET"
,
headers
=
self
.
headers
)
return
response
async
def
get_validator_deposit
(
self
,
indexOrPubkey
:
Union
[
int
,
str
]):
"""获取质押信息"""
url
=
f
"{self.base_url}/api/v1/validator/{indexOrPubkey}/deposits"
response
=
await
aio_request
(
url
=
url
,
method
=
"GET"
,
headers
=
self
.
headers
)
return
response
async
def
get_validator_income
(
self
,
indexOrPubkey
:
Union
[
int
,
str
]):
"""获取质押收益"""
url
=
f
"{self.base_url}/api/v1/validator/{indexOrPubkey}/performance"
response
=
await
aio_request
(
url
=
url
,
method
=
"GET"
,
headers
=
self
.
headers
)
return
response
async
def
get_validator_blocks
(
self
,
index
:
int
,
start
:
int
=
0
,
length
:
int
=
10
):
t
=
time
.
time
()
*
1000
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&_={t}"
response
=
await
aio_request
(
url
=
url
,
method
=
"GET"
,
headers
=
self
.
headers
)
data
=
response
.
result
[
"data"
]
blocks
=
[]
for
item
in
data
:
epoch
=
re
.
findall
(
r'/epoch/(\d+)">'
,
item
[
0
])[
0
]
slot
=
re
.
findall
(
r'/slot/(\d+)">'
,
item
[
1
])[
0
]
status
=
re
.
findall
(
r'>(\w+)</'
,
item
[
2
])[
0
]
timestamp
=
re
.
findall
(
r'data-timestamp=\"(\d+)\">'
,
item
[
3
])[
0
]
root_hash
=
re
.
findall
(
r'data-clipboard-text=(\w+)>'
,
item
[
4
])[
0
]
att
=
item
[
5
]
dep
=
item
[
6
]
proposers
=
item
[
7
]
ex
=
item
[
8
]
blocks
.
append
(
ValidatorBlock
(
epoch
=
epoch
,
slot
=
slot
,
status
=
status
,
timestamp
=
timestamp
,
root_hash
=
root_hash
,
att
=
att
,
dep
=
dep
,
proposers
=
proposers
,
ex
=
ex
))
result
=
ValidatorBlocks
(
total
=
response
.
result
[
"recordsTotal"
],
data
=
blocks
)
return
result
async
def
get_daily_stats
(
self
,
index
:
int
):
url
=
f
"{self.base_url}/api/v1/validator/stats/{index}"
response
=
await
aio_request
(
url
=
url
,
method
=
"GET"
,
headers
=
self
.
headers
)
return
response
async
def
get_eth_deposits
(
self
,
indexOrPubkey
:
Union
[
int
,
str
]):
url
=
f
"{self.base_url}/api/v1/validator/{indexOrPubkey}/deposits"
response
=
await
aio_request
(
url
=
url
,
method
=
"GET"
,
headers
=
self
.
headers
)
return
response
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