Skip to content

Commit f80de9a

Browse files
committed
remove some redundant code lines
1 parent daae291 commit f80de9a

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

sauron/sauron.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,16 @@ def init(plugin, options, **kwargs):
5151
feerate_url = "{}/v1/fees/recommended".format(plugin.api_endpoint)
5252
feerate_req = fetch(feerate_url)
5353
assert feerate_req.status_code == 200
54-
plugin.is_esplora = False
5554
plugin.is_mempoolspace = True
5655
except AssertionError as e0:
5756
try:
5857
# Blockstream API
5958
feerate_url = "{}/fee-estimates".format(plugin.api_endpoint)
6059
feerate_req = fetch(feerate_url)
6160
assert feerate_req.status_code == 200
62-
plugin.is_esplora = True
6361
plugin.is_mempoolspace = False
6462
except AssertionError as e1:
65-
raise Exception("Sauron API cannot be reached") from e
63+
raise Exception("Sauron API cannot be reached") from e1
6664

6765

6866
if options["sauron-tor-proxy"]:
@@ -185,22 +183,27 @@ def getutxout(plugin, address, txid, vout, **kwargs):
185183
# Determine the API endpoint type based on the URL structure
186184
if plugin.is_mempoolspace:
187185
# MutinyNet API
188-
utxo_url = "{}/address/{}/utxo".format(plugin.api_endpoint, address)
186+
gettx_url = "{}/address/{}/utxo".format(plugin.api_endpoint, address)
187+
else:
188+
# Blockstream API
189+
gettx_url = "{}/tx/{}".format(plugin.api_endpoint, txid)
190+
status_url = "{}/tx/{}/outspend/{}".format(plugin.api_endpoint, txid, vout)
189191

190-
# Fetch the list of UTXOs for the given address
191-
utxo_req = fetch(utxo_url)
192-
if not utxo_req.status_code == 200:
193-
raise SauronError(
194-
"Endpoint at {} returned {} ({}) when trying to get UTXOs.".format(
195-
utxo_url, utxo_req.status_code, utxo_req.text
196-
)
192+
# Fetch the list of UTXOs for the given address
193+
gettx_req = fetch(gettx_url)
194+
if not gettx_req.status_code == 200:
195+
raise SauronError(
196+
"Endpoint at {} returned {} ({}) when trying to get transaction.".format(
197+
gettx_url, gettx_req.status_code, gettx_req.text
197198
)
198-
199+
)
200+
if plugin.is_mempoolspace:
201+
# Building response from MutinyNet API
199202
# Parse the UTXO data
200-
utxos = utxo_req.json()
203+
utxos = gettx_req.json()
201204
# Find the UTXO with the given txid and vout
202205
for utxo in utxos:
203-
if utxo['txid'] == txid and utxo['vout'] == vout:
206+
if utxo['txid'] == txid:
204207
return {
205208
"amount": utxo["value"],
206209
"script": None # MutinyNet API does not provide script information
@@ -211,19 +214,8 @@ def getutxout(plugin, address, txid, vout, **kwargs):
211214
"amount": None,
212215
"script": None
213216
}
214-
215217
else:
216-
# Blockstream API
217-
gettx_url = "{}/tx/{}".format(plugin.api_endpoint, txid)
218-
status_url = "{}/tx/{}/outspend/{}".format(plugin.api_endpoint, txid, vout)
219-
220-
gettx_req = fetch(gettx_url)
221-
if not gettx_req.status_code == 200:
222-
raise SauronError(
223-
"Endpoint at {} returned {} ({}) when trying to get transaction.".format(
224-
gettx_url, gettx_req.status_code, gettx_req.text
225-
)
226-
)
218+
# Building response from Blockstream API
227219
status_req = fetch(status_url)
228220
if not status_req.status_code == 200:
229221
raise SauronError(
@@ -252,15 +244,12 @@ def estimatefees(plugin, **kwargs):
252244
if plugin.is_mempoolspace:
253245
# MutinyNet API
254246
feerate_url = "{}/v1/fees/recommended".format(plugin.api_endpoint)
255-
plugin.log("estimatefees: plugin.api_endpoint = %s" % plugin.api_endpoint)
256-
plugin.log("estimatefees: feerate_url = %s" % feerate_url)
257-
258247
else:
259248
# Blockstream API
260249
feerate_url = "{}/fee-estimates".format(plugin.api_endpoint)
261-
plugin.log("estimatefees: plugin.api_endpoint = %s" % plugin.api_endpoint)
262-
plugin.log("estimatefees: feerate_url = %s" % feerate_url)
263250

251+
plugin.log("estimatefees: plugin.api_endpoint = %s" % plugin.api_endpoint)
252+
plugin.log("estimatefees: feerate_url = %s" % feerate_url)
264253
feerate_req = fetch(feerate_url)
265254
assert feerate_req.status_code == 200
266255
feerates = feerate_req.json()

0 commit comments

Comments
 (0)