-
-
Save cdecker/046d58de933b7c8ed5d38f34748ff4dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@plugin.method("probe") | |
def probe(plugin, node_id, **kwargs): | |
"""Probe a network by sending a payment to it. | |
""" | |
probe = { | |
'destination': node_id, | |
'started_at': str(datetime.now()), | |
} | |
try: | |
probe['route'] = plugin.rpc.getroute( | |
probe['destination'], | |
msatoshi=10000, | |
riskfactor=1, | |
)['route'] | |
probe['payment_hash'] = ''.join(random.choice(string.hexdigits) for _ in range(64)) | |
except RpcError: | |
probe['failcode'] = -1 | |
return probe | |
plugin.rpc.sendpay(probe['route'], probe['payment_hash']) | |
try: | |
plugin.rpc.waitsendpay(probe['payment_hash']) | |
raise ValueError("The recipient guessed the preimage? Cryptography is broken!!!") | |
except RpcError as e: | |
probe['finished_at'] = str(datetime.now()) | |
probe['error'] = e.error['data'] | |
probe['failcode'] = e.error['data']['failcode'] | |
return probe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment