mirror of
https://github.com/logos-blockchain/logos-blockchain-block-explorer-template.git
synced 2026-03-28 22:43:33 +00:00
use POST api for fetching blocks
This commit is contained in:
parent
7b8a2fd1ce
commit
cb4a40b574
@ -77,8 +77,13 @@ class HttpNodeApi(NodeApi):
|
||||
return InfoSerializer.model_validate(response.json())
|
||||
|
||||
async def get_block_by_hash(self, block_hash: str) -> Optional[BlockSerializer]:
|
||||
url = urljoin(self.base_url, f"{self.ENDPOINT_BLOCK_BY_HASH}/{block_hash}")
|
||||
response = requests.get(url, auth=self.authentication, timeout=60)
|
||||
url = urljoin(self.base_url, self.ENDPOINT_BLOCK_BY_HASH)
|
||||
response = requests.post(
|
||||
url,
|
||||
auth=self.authentication,
|
||||
timeout=60,
|
||||
json=block_hash,
|
||||
)
|
||||
if response.status_code == 404:
|
||||
return None
|
||||
response.raise_for_status()
|
||||
@ -88,7 +93,7 @@ class HttpNodeApi(NodeApi):
|
||||
return None
|
||||
block = BlockSerializer.model_validate(json_data)
|
||||
# The storage endpoint doesn't include the block hash in the response,
|
||||
# so we set it from the URL parameter
|
||||
# so we set it from the request body
|
||||
if not block.header.hash:
|
||||
block.header.hash = bytes.fromhex(block_hash)
|
||||
return block
|
||||
|
||||
7
third_party/requests.py
vendored
7
third_party/requests.py
vendored
@ -9,3 +9,10 @@ def get(url, params=None, auth: Option[Authentication] = None, **kwargs):
|
||||
if auth.is_some:
|
||||
headers["Authorization"] = auth.unwrap().for_requests()
|
||||
return requests.get(url, params, headers=headers, **kwargs)
|
||||
|
||||
|
||||
def post(url, data=None, json=None, auth: Option[Authentication] = None, **kwargs):
|
||||
headers = kwargs.get("headers", {})
|
||||
if auth.is_some:
|
||||
headers["Authorization"] = auth.unwrap().for_requests()
|
||||
return requests.post(url, data=data, json=json, headers=headers, **kwargs)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user