sauron: fail early if we can't get block hash in getrawblock

It's a bit of duplication but is nonsensical to make a block request if
we couldn't get the block hash.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
Antoine Poinsot
2021-09-04 09:51:45 +02:00
committed by Christian Decker
parent d013450f14
commit dc3f691ea1

View File

@@ -101,11 +101,16 @@ def getchaininfo(plugin, **kwargs):
@plugin.method("getrawblockbyheight") @plugin.method("getrawblockbyheight")
def getrawblock(plugin, height, **kwargs): def getrawblock(plugin, height, **kwargs):
blockhash_url = "{}/block-height/{}".format(plugin.api_endpoint, height) blockhash_url = "{}/block-height/{}".format(plugin.api_endpoint, height)
blockhash_req = fetch(blockhash_url) blockhash_req = fetch(blockhash_url)
block_req = fetch("{}/block/{}/raw".format(plugin.api_endpoint, if blockhash_req.status_code != 200:
blockhash_req.text)) return {
if blockhash_req.status_code != 200 or block_req.status_code != 200: "blockhash": None,
"block": None,
}
block_url = "{}/block/{}/raw".format(plugin.api_endpoint, blockhash_req.text)
block_req = fetch(block_url)
if block_req.status_code != 200:
return { return {
"blockhash": None, "blockhash": None,
"block": None, "block": None,