Skip to content

Instantly share code, notes, and snippets.

@cdecker

cdecker/probe.py Secret

Created September 14, 2019 09:40
Show Gist options
  • Save cdecker/046d58de933b7c8ed5d38f34748ff4dc to your computer and use it in GitHub Desktop.
Save cdecker/046d58de933b7c8ed5d38f34748ff4dc to your computer and use it in GitHub Desktop.
@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