@@ -51,18 +51,16 @@ def init(plugin, options, **kwargs):
51
51
feerate_url = "{}/v1/fees/recommended" .format (plugin .api_endpoint )
52
52
feerate_req = fetch (feerate_url )
53
53
assert feerate_req .status_code == 200
54
- plugin .is_esplora = False
55
54
plugin .is_mempoolspace = True
56
55
except AssertionError as e0 :
57
56
try :
58
57
# Blockstream API
59
58
feerate_url = "{}/fee-estimates" .format (plugin .api_endpoint )
60
59
feerate_req = fetch (feerate_url )
61
60
assert feerate_req .status_code == 200
62
- plugin .is_esplora = True
63
61
plugin .is_mempoolspace = False
64
62
except AssertionError as e1 :
65
- raise Exception ("Sauron API cannot be reached" ) from e
63
+ raise Exception ("Sauron API cannot be reached" ) from e1
66
64
67
65
68
66
if options ["sauron-tor-proxy" ]:
@@ -185,22 +183,27 @@ def getutxout(plugin, address, txid, vout, **kwargs):
185
183
# Determine the API endpoint type based on the URL structure
186
184
if plugin .is_mempoolspace :
187
185
# 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 )
189
191
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
197
198
)
198
-
199
+ )
200
+ if plugin .is_mempoolspace :
201
+ # Building response from MutinyNet API
199
202
# Parse the UTXO data
200
- utxos = utxo_req .json ()
203
+ utxos = gettx_req .json ()
201
204
# Find the UTXO with the given txid and vout
202
205
for utxo in utxos :
203
- if utxo ['txid' ] == txid and utxo [ 'vout' ] == vout :
206
+ if utxo ['txid' ] == txid :
204
207
return {
205
208
"amount" : utxo ["value" ],
206
209
"script" : None # MutinyNet API does not provide script information
@@ -211,19 +214,8 @@ def getutxout(plugin, address, txid, vout, **kwargs):
211
214
"amount" : None ,
212
215
"script" : None
213
216
}
214
-
215
217
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
227
219
status_req = fetch (status_url )
228
220
if not status_req .status_code == 200 :
229
221
raise SauronError (
@@ -252,15 +244,12 @@ def estimatefees(plugin, **kwargs):
252
244
if plugin .is_mempoolspace :
253
245
# MutinyNet API
254
246
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
-
258
247
else :
259
248
# Blockstream API
260
249
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 )
263
250
251
+ plugin .log ("estimatefees: plugin.api_endpoint = %s" % plugin .api_endpoint )
252
+ plugin .log ("estimatefees: feerate_url = %s" % feerate_url )
264
253
feerate_req = fetch (feerate_url )
265
254
assert feerate_req .status_code == 200
266
255
feerates = feerate_req .json ()
0 commit comments