Skip to content

Commit

Permalink
Add mutinynet
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-ruz committed Oct 19, 2024
1 parent 2436719 commit 0c2ce6d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions sauron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv/
8 changes: 8 additions & 0 deletions sauron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Here is a fully reptilian example running against [blockstream.info](https://blo
lightningd --mainnet --disable-plugin bcli --plugin $PWD/sauron.py --sauron-api-endpoint https://blockstream.info/api/
```


Here is an example running against [mutinynet.com](https://mutinynet.com/):

```
lightningd --signet --disable-plugin bcli --plugin $PWD/sauron.py --sauron-api-endpoint https://mutinynet.com/api/
```


You can use also proxy your requests through [Tor](https://www.torproject.org/) by
specifying a SOCKS proxy to use with the `--sauron-tor-proxy` startup option, in
the form `address:port`.
Expand Down
2 changes: 1 addition & 1 deletion sauron/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyln-client>=23.2
pyln-client>=23.2,<=24.5
requests[socks]>=2.23.0
32 changes: 27 additions & 5 deletions sauron/sauron.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,29 @@ def fetch(url):


@plugin.init()
def init(plugin, options, configuration, **kwargs):
plugin.api_endpoint = options["sauron-api-endpoint"]
def init(plugin, options, **kwargs):
plugin.api_endpoint = options.get("sauron-api-endpoint", None)
if not plugin.api_endpoint:
raise SauronError("You need to specify the sauron-api-endpoint option.")
sys.exit(1)

# Test for Esplora or mempoolspace
try:
# Esplora API
feerate_url = "{}/fee-estimates".format(plugin.api_endpoint)
feerate_req = fetch(feerate_url)
assert feerate_req.status_code == 200
plugin.is_mempoolspace = False
except AssertionError as e0:
try:
# MutinyNet API
feerate_url = "{}/v1/fees/recommended".format(plugin.api_endpoint)
feerate_req = fetch(feerate_url)
assert feerate_req.status_code == 200
plugin.is_mempoolspace = True
except AssertionError as e1:
raise Exception("Sauron API cannot be reached") from e1

if options["sauron-tor-proxy"]:
address, port = options["sauron-tor-proxy"].split(":")
socks5_proxy = "socks5h://{}:{}".format(address, port)
Expand Down Expand Up @@ -188,7 +205,12 @@ def getutxout(plugin, txid, vout, **kwargs):

@plugin.method("estimatefees")
def estimatefees(plugin, **kwargs):
feerate_url = "{}/fee-estimates".format(plugin.api_endpoint)
if plugin.is_mempoolspace:
# MutinyNet API
feerate_url = "{}/v1/fees/recommended".format(plugin.api_endpoint)
else:
# Blockstream API
feerate_url = "{}/fee-estimates".format(plugin.api_endpoint)

feerate_req = fetch(feerate_url)
assert feerate_req.status_code == 200
Expand All @@ -204,7 +226,7 @@ def estimatefees(plugin, **kwargs):
urgent = int(feerates["6"] * 10**3)
very_urgent = int(feerates["2"] * 10**3)

feerate_floor = int(feerates["1008"] * 10**3)
feerate_floor = int(feerates.get("1008", slow) * 10**3)
feerates = [
{"blocks": 2, "feerate": very_urgent},
{"blocks": 6, "feerate": urgent},
Expand All @@ -229,7 +251,7 @@ def estimatefees(plugin, **kwargs):
plugin.add_option(
"sauron-api-endpoint",
"",
"The URL of the esplora instance to hit (including '/api').",
"The URL of the esplora or mempool.space instance to hit (including '/api').",
)

plugin.add_option(
Expand Down

0 comments on commit 0c2ce6d

Please sign in to comment.