@@ -19,6 +19,8 @@ class SauronError(Exception):
19
19
def fetch (url ):
20
20
"""Fetch the given {url}, maybe through a pre-defined proxy."""
21
21
# FIXME: Maybe try to be smart and renew circuit to broadcast different
22
+ # transactions ? Hint: lightningd will agressively send us the same
23
+ # transaction a certain amount of times.
22
24
session = requests .session ()
23
25
session .proxies = plugin .sauron_socks_proxies
24
26
retry_strategy = Retry (
@@ -36,10 +38,10 @@ def fetch(url):
36
38
37
39
@plugin .init ()
38
40
def init (plugin , options , ** kwargs ):
39
- plugin .sauron_api_endpoint = options .get ("sauron-api-endpoint" , None )
40
- plugin .log ("plugin.sauron_api_endpoint = %s" % plugin .sauron_api_endpoint )
41
+ plugin .api_endpoint = options .get ("sauron-api-endpoint" , None )
42
+ plugin .log ("plugin.api_endpoint = %s" % plugin .api_endpoint )
41
43
42
- if not plugin .sauron_api_endpoint :
44
+ if not plugin .api_endpoint :
43
45
raise SauronError ("You need to specify the sauron-api-endpoint option." )
44
46
sys .exit (1 )
45
47
@@ -57,8 +59,8 @@ def init(plugin, options, **kwargs):
57
59
58
60
@plugin .method ("getchaininfo" )
59
61
def getchaininfo (plugin , ** kwargs ):
60
- blockhash_url = "{}block-height/0" .format (plugin .sauron_api_endpoint )
61
- blockcount_url = "{}blocks/tip/height" .format (plugin .sauron_api_endpoint )
62
+ blockhash_url = "{}/ block-height/0" .format (plugin .api_endpoint )
63
+ blockcount_url = "{}/ blocks/tip/height" .format (plugin .api_endpoint )
62
64
63
65
chains = {
64
66
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" : "main" ,
@@ -87,6 +89,8 @@ def getchaininfo(plugin, **kwargs):
87
89
raise SauronError ("Unsupported network" )
88
90
plugin .sauron_network = chains [genesis_req .text ]
89
91
92
+ # We wouldn't be able to hit it if its bitcoind wasn't synced, so
93
+ # ibd = false and headercount = blockcount
90
94
return {
91
95
"chain" : plugin .sauron_network ,
92
96
"blockcount" : blockcount_req .text ,
@@ -97,7 +101,7 @@ def getchaininfo(plugin, **kwargs):
97
101
@plugin .method ("getrawblockbyheight" )
98
102
def getrawblock (plugin , height , ** kwargs ):
99
103
# Step 1: Get the block hash by height
100
- blockhash_url = "{}block-height/{}" .format (plugin .sauron_api_endpoint , height )
104
+ blockhash_url = "{}/ block-height/{}" .format (plugin .api_endpoint , height )
101
105
102
106
blockhash_req = fetch (blockhash_url )
103
107
if blockhash_req .status_code != 200 :
@@ -109,7 +113,7 @@ def getrawblock(plugin, height, **kwargs):
109
113
block_hash = blockhash_req .text .strip () # Ensure no extra spaces or newlines
110
114
111
115
# Step 2: Determine the block URL and fetch the block data
112
- block_url = "{}block/{}/raw" .format (plugin .sauron_api_endpoint , block_hash )
116
+ block_url = "{}/ block/{}/raw" .format (plugin .api_endpoint , block_hash )
113
117
114
118
while True :
115
119
block_req = fetch (block_url )
@@ -145,7 +149,7 @@ def getrawblock(plugin, height, **kwargs):
145
149
146
150
@plugin .method ("sendrawtransaction" )
147
151
def sendrawtx (plugin , tx , ** kwargs ):
148
- sendtx_url = "{}tx" .format (plugin .sauron_api_endpoint )
152
+ sendtx_url = "{}/ tx" .format (plugin .api_endpoint )
149
153
150
154
sendtx_req = requests .post (sendtx_url , data = tx )
151
155
if sendtx_req .status_code != 200 :
@@ -163,9 +167,9 @@ def sendrawtx(plugin, tx, **kwargs):
163
167
@plugin .method ("getutxout" )
164
168
def getutxout (plugin , address , txid , vout , ** kwargs ):
165
169
# Determine the API endpoint type based on the URL structure
166
- if "mutinynet" in plugin .sauron_api_endpoint :
170
+ if "mutinynet" in plugin .api_endpoint :
167
171
# MutinyNet API
168
- utxo_url = "{}address/{}/utxo" .format (plugin .sauron_api_endpoint , address )
172
+ utxo_url = "{}/ address/{}/utxo" .format (plugin .api_endpoint , address )
169
173
170
174
# Fetch the list of UTXOs for the given address
171
175
utxo_req = fetch (utxo_url )
@@ -194,8 +198,8 @@ def getutxout(plugin, address, txid, vout, **kwargs):
194
198
195
199
else :
196
200
# Blockstream API
197
- gettx_url = "{}/tx/{}" .format (plugin .sauron_api_endpoint , txid )
198
- status_url = "{}/tx/{}/outspend/{}" .format (plugin .sauron_api_endpoint , txid , vout )
201
+ gettx_url = "{}/tx/{}" .format (plugin .api_endpoint , txid )
202
+ status_url = "{}/tx/{}/outspend/{}" .format (plugin .api_endpoint , txid , vout )
199
203
200
204
gettx_req = fetch (gettx_url )
201
205
if not gettx_req .status_code == 200 :
@@ -229,16 +233,16 @@ def getutxout(plugin, address, txid, vout, **kwargs):
229
233
@plugin .method ("estimatefees" )
230
234
def estimatefees (plugin , ** kwargs ):
231
235
# Define the URL based on the selected API
232
- if "mutinynet" in plugin .sauron_api_endpoint :
236
+ if "mutinynet" in plugin .api_endpoint :
233
237
# MutinyNet API
234
- feerate_url = "{}v1/fees/recommended" .format (plugin .sauron_api_endpoint )
235
- plugin .log ("estimatefees: plugin.sauron_api_endpoint = %s" % plugin .sauron_api_endpoint )
238
+ feerate_url = "{}/ v1/fees/recommended" .format (plugin .api_endpoint )
239
+ plugin .log ("estimatefees: plugin.api_endpoint = %s" % plugin .api_endpoint )
236
240
plugin .log ("estimatefees: feerate_url = %s" % feerate_url )
237
241
238
242
else :
239
243
# Blockstream API
240
- feerate_url = "{}/fee-estimates" .format (plugin .sauron_api_endpoint )
241
- plugin .log ("estimatefees: plugin.sauron_api_endpoint = %s" % plugin .sauron_api_endpoint )
244
+ feerate_url = "{}/fee-estimates" .format (plugin .api_endpoint )
245
+ plugin .log ("estimatefees: plugin.api_endpoint = %s" % plugin .api_endpoint )
242
246
plugin .log ("estimatefees: feerate_url = %s" % feerate_url )
243
247
244
248
feerate_req = fetch (feerate_url )
@@ -255,6 +259,7 @@ def estimatefees(plugin, **kwargs):
255
259
slow = normal = urgent = very_urgent = int (feerate * multiply_factor )
256
260
else :
257
261
# Adjust fee rates based on the specific API
262
+ # It returns sat/vB, we want sat/kVB, so multiply everything by 10**3
258
263
slow = int (feerates ["144" ] * multiply_factor )
259
264
normal = int (feerates ["12" ] * multiply_factor )
260
265
urgent = int (feerates ["6" ] * multiply_factor )
@@ -288,6 +293,7 @@ def estimatefees(plugin, **kwargs):
288
293
plugin .add_option (
289
294
"sauron-api-endpoint" ,
290
295
"" ,
296
+ "The URL of the esplora instance to hit (including '/api')." ,
291
297
"The URL of the mutinynet instance to hit (including '/api')." ,
292
298
)
293
299
0 commit comments